PostgreSQL Source Code: src/backend/nodes/nodeFuncs.c Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

16

25

27static int leftmostLoc(int loc1, int loc2);

31 void *context);

34 void *context);

35

36

37

38

39

40

43{

45

46 if (!expr)

48

50 {

51 case T_Var:

52 type = ((const Var *) expr)->vartype;

53 break;

54 case T_Const:

55 type = ((const Const *) expr)->consttype;

56 break;

57 case T_Param:

58 type = ((const Param *) expr)->paramtype;

59 break;

60 case T_Aggref:

61 type = ((const Aggref *) expr)->aggtype;

62 break;

63 case T_GroupingFunc:

64 type = INT4OID;

65 break;

66 case T_WindowFunc:

68 break;

69 case T_MergeSupportFunc:

71 break;

72 case T_SubscriptingRef:

74 break;

75 case T_FuncExpr:

76 type = ((const FuncExpr *) expr)->funcresulttype;

77 break;

78 case T_NamedArgExpr:

80 break;

81 case T_OpExpr:

82 type = ((const OpExpr *) expr)->opresulttype;

83 break;

84 case T_DistinctExpr:

86 break;

87 case T_NullIfExpr:

89 break;

90 case T_ScalarArrayOpExpr:

91 type = BOOLOID;

92 break;

93 case T_BoolExpr:

94 type = BOOLOID;

95 break;

96 case T_SubLink:

97 {

99

102 {

103

106

108 elog(ERROR, "cannot get type for untransformed sublink");

110 Assert(!tent->resjunk);

113 {

117 (errcode(ERRCODE_UNDEFINED_OBJECT),

118 errmsg("could not find array type for data type %s",

120 }

121 }

123 {

124

125 type = RECORDOID;

126 }

127 else

128 {

129

130 type = BOOLOID;

131 }

132 }

133 break;

134 case T_SubPlan:

135 {

137

140 {

141

144 {

148 (errcode(ERRCODE_UNDEFINED_OBJECT),

149 errmsg("could not find array type for data type %s",

151 }

152 }

154 {

155

156 type = RECORDOID;

157 }

158 else

159 {

160

161 type = BOOLOID;

162 }

163 }

164 break;

165 case T_AlternativeSubPlan:

166 {

168

169

171 }

172 break;

173 case T_FieldSelect:

175 break;

176 case T_FieldStore:

178 break;

179 case T_RelabelType:

181 break;

182 case T_CoerceViaIO:

184 break;

185 case T_ArrayCoerceExpr:

187 break;

188 case T_ConvertRowtypeExpr:

190 break;

191 case T_CollateExpr:

193 break;

194 case T_CaseExpr:

196 break;

197 case T_CaseTestExpr:

199 break;

200 case T_ArrayExpr:

202 break;

203 case T_RowExpr:

204 type = ((const RowExpr *) expr)->row_typeid;

205 break;

206 case T_RowCompareExpr:

207 type = BOOLOID;

208 break;

209 case T_CoalesceExpr:

211 break;

212 case T_MinMaxExpr:

214 break;

215 case T_SQLValueFunction:

217 break;

218 case T_XmlExpr:

220 type = BOOLOID;

222 type = TEXTOID;

223 else

224 type = XMLOID;

225 break;

226 case T_JsonValueExpr:

227 {

229

231 }

232 break;

233 case T_JsonConstructorExpr:

235 break;

236 case T_JsonIsPredicate:

237 type = BOOLOID;

238 break;

239 case T_JsonExpr:

240 {

242

244 break;

245 }

246 case T_JsonBehavior:

247 {

249

251 break;

252 }

253 case T_NullTest:

254 type = BOOLOID;

255 break;

256 case T_BooleanTest:

257 type = BOOLOID;

258 break;

259 case T_CoerceToDomain:

261 break;

262 case T_CoerceToDomainValue:

264 break;

265 case T_SetToDefault:

267 break;

268 case T_CurrentOfExpr:

269 type = BOOLOID;

270 break;

271 case T_NextValueExpr:

273 break;

274 case T_InferenceElem:

275 {

277

279 }

280 break;

281 case T_ReturningExpr:

283 break;

284 case T_PlaceHolderVar:

286 break;

287 default:

288 elog(ERROR, "unrecognized node type: %d", (int) nodeTag(expr));

290 break;

291 }

293}

294

295

296

297

298

299

302{

303 if (!expr)

304 return -1;

305

307 {

308 case T_Var:

309 return ((const Var *) expr)->vartypmod;

310 case T_Const:

311 return ((const Const *) expr)->consttypmod;

312 case T_Param:

313 return ((const Param *) expr)->paramtypmod;

314 case T_SubscriptingRef:

316 case T_FuncExpr:

317 {

318 int32 coercedTypmod;

319

320

322 return coercedTypmod;

323 }

324 break;

325 case T_NamedArgExpr:

327 case T_NullIfExpr:

328 {

329

330

331

332

334

336 }

337 break;

338 case T_SubLink:

339 {

341

344 {

345

348

350 elog(ERROR, "cannot get type for untransformed sublink");

352 Assert(!tent->resjunk);

354

355 }

356

357 }

358 break;

359 case T_SubPlan:

360 {

362

365 {

366

367

369 }

370

371 }

372 break;

373 case T_AlternativeSubPlan:

374 {

376

377

379 }

380 break;

381 case T_FieldSelect:

382 return ((const FieldSelect *) expr)->resulttypmod;

383 case T_RelabelType:

384 return ((const RelabelType *) expr)->resulttypmod;

385 case T_ArrayCoerceExpr:

387 case T_CollateExpr:

389 case T_CaseExpr:

390 {

391

392

393

394

396 Oid casetype = cexpr->casetype;

399

401 return -1;

403 return -1;

405 if (typmod < 0)

406 return -1;

407 foreach(arg, cexpr->args)

408 {

410

412 return -1;

414 return -1;

415 }

416 return typmod;

417 }

418 break;

419 case T_CaseTestExpr:

420 return ((const CaseTestExpr *) expr)->typeMod;

421 case T_ArrayExpr:

422 {

423

424

425

426

428 Oid commontype;

431

432 if (arrayexpr->elements == NIL)

433 return -1;

435 if (typmod < 0)

436 return -1;

437 if (arrayexpr->multidims)

438 commontype = arrayexpr->array_typeid;

439 else

440 commontype = arrayexpr->element_typeid;

441 foreach(elem, arrayexpr->elements)

442 {

444

446 return -1;

448 return -1;

449 }

450 return typmod;

451 }

452 break;

453 case T_CoalesceExpr:

454 {

455

456

457

458

460 Oid coalescetype = cexpr->coalescetype;

463

465 return -1;

467 if (typmod < 0)

468 return -1;

470 {

472

474 return -1;

476 return -1;

477 }

478 return typmod;

479 }

480 break;

481 case T_MinMaxExpr:

482 {

483

484

485

486

488 Oid minmaxtype = mexpr->minmaxtype;

491

493 return -1;

495 if (typmod < 0)

496 return -1;

498 {

500

502 return -1;

504 return -1;

505 }

506 return typmod;

507 }

508 break;

509 case T_SQLValueFunction:

511 case T_JsonValueExpr:

513 case T_JsonConstructorExpr:

515 case T_JsonExpr:

516 {

518

520 }

521 break;

522 case T_JsonBehavior:

523 {

525

527 }

528 break;

529 case T_CoerceToDomain:

530 return ((const CoerceToDomain *) expr)->resulttypmod;

531 case T_CoerceToDomainValue:

533 case T_SetToDefault:

534 return ((const SetToDefault *) expr)->typeMod;

535 case T_ReturningExpr:

537 case T_PlaceHolderVar:

539 default:

540 break;

541 }

542 return -1;

543}

544

545

546

547

548

549

550

551

552

553

554

555

556bool

558{

559 if (coercedTypmod != NULL)

560 *coercedTypmod = -1;

561

562

563

564

565

567 {

569 int nargs;

570 Const *second_arg;

571

572

573

574

577 return false;

578

579

580

581

582

583

585 if (nargs < 2 || nargs > 3)

586 return false;

587

589 if (IsA(second_arg, Const) ||

590 second_arg->consttype != INT4OID ||

591 second_arg->constisnull)

592 return false;

593

594

595

596

597 if (coercedTypmod != NULL)

598 *coercedTypmod = DatumGetInt32(second_arg->constvalue);

599

600 return true;

601 }

602

604 {

606

607

608 if (acoerce->resulttypmod < 0)

609 return false;

610

611

612

613

614 if (coercedTypmod != NULL)

615 *coercedTypmod = acoerce->resulttypmod;

616

617 return true;

618 }

619

620 return false;

621}

622

623

624

625

626

627

628

629

630

631

632

633

634

637 CoercionForm rformat, int rlocation, bool overwrite_ok)

638{

639

640

641

642

643

646

648 {

649

651

652 if (!overwrite_ok)

655 con->consttypmod = rtypmod;

656 con->constcollid = rcollid;

657

658 return (Node *) con;

659 }

663 {

664

665 return arg;

666 }

667 else

668 {

669

671

674 newrelabel->resulttypmod = rtypmod;

675 newrelabel->resultcollid = rcollid;

676 newrelabel->relabelformat = rformat;

677 newrelabel->location = rlocation;

678 return (Node *) newrelabel;

679 }

680}

681

682

683

684

685

686

687

690{

693}

694

695

696

697

698

699

700

701

702

703

706{

707 if (node == NULL)

708 return NULL;

710 {

712

715 }

717 {

719

722 }

724 {

726

729 }

731 {

733

736 }

738 {

740

743 }

745 {

747

750 }

751 return node;

752}

753

754

755

756

757

758

759

760

761

762bool

764{

766}

767

768static bool

770{

771 if (node == NULL)

772 return false;

774 {

776

777 if (expr->funcretset)

778 return true;

779

780 }

782 {

784

785 if (expr->opretset)

786 return true;

787

788 }

789

790

791

792

793

794

795

796

798 return false;

800 return false;

802 return false;

803

805 context);

806}

807

808

809

810

811

812

813

814

815

816

817

818

819

822{

823 Oid coll;

824

825 if (!expr)

827

829 {

830 case T_Var:

831 coll = ((const Var *) expr)->varcollid;

832 break;

833 case T_Const:

834 coll = ((const Const *) expr)->constcollid;

835 break;

836 case T_Param:

837 coll = ((const Param *) expr)->paramcollid;

838 break;

839 case T_Aggref:

840 coll = ((const Aggref *) expr)->aggcollid;

841 break;

842 case T_GroupingFunc:

844 break;

845 case T_WindowFunc:

846 coll = ((const WindowFunc *) expr)->wincollid;

847 break;

848 case T_MergeSupportFunc:

850 break;

851 case T_SubscriptingRef:

853 break;

854 case T_FuncExpr:

855 coll = ((const FuncExpr *) expr)->funccollid;

856 break;

857 case T_NamedArgExpr:

859 break;

860 case T_OpExpr:

861 coll = ((const OpExpr *) expr)->opcollid;

862 break;

863 case T_DistinctExpr:

864 coll = ((const DistinctExpr *) expr)->opcollid;

865 break;

866 case T_NullIfExpr:

867 coll = ((const NullIfExpr *) expr)->opcollid;

868 break;

869 case T_ScalarArrayOpExpr:

870

871 coll = InvalidOid;

872 break;

873 case T_BoolExpr:

874

875 coll = InvalidOid;

876 break;

877 case T_SubLink:

878 {

880

883 {

884

887

889 elog(ERROR, "cannot get collation for untransformed sublink");

891 Assert(!tent->resjunk);

893

894 }

895 else

896 {

897

898 coll = InvalidOid;

899 }

900 }

901 break;

902 case T_SubPlan:

903 {

905

908 {

909

911

912 }

913 else

914 {

915

916 coll = InvalidOid;

917 }

918 }

919 break;

920 case T_AlternativeSubPlan:

921 {

923

924

926 }

927 break;

928 case T_FieldSelect:

929 coll = ((const FieldSelect *) expr)->resultcollid;

930 break;

931 case T_FieldStore:

932

933 coll = InvalidOid;

934 break;

935 case T_RelabelType:

936 coll = ((const RelabelType *) expr)->resultcollid;

937 break;

938 case T_CoerceViaIO:

939 coll = ((const CoerceViaIO *) expr)->resultcollid;

940 break;

941 case T_ArrayCoerceExpr:

943 break;

944 case T_ConvertRowtypeExpr:

945

946 coll = InvalidOid;

947 break;

948 case T_CollateExpr:

949 coll = ((const CollateExpr *) expr)->collOid;

950 break;

951 case T_CaseExpr:

952 coll = ((const CaseExpr *) expr)->casecollid;

953 break;

954 case T_CaseTestExpr:

955 coll = ((const CaseTestExpr *) expr)->collation;

956 break;

957 case T_ArrayExpr:

958 coll = ((const ArrayExpr *) expr)->array_collid;

959 break;

960 case T_RowExpr:

961

962 coll = InvalidOid;

963 break;

964 case T_RowCompareExpr:

965

966 coll = InvalidOid;

967 break;

968 case T_CoalesceExpr:

969 coll = ((const CoalesceExpr *) expr)->coalescecollid;

970 break;

971 case T_MinMaxExpr:

972 coll = ((const MinMaxExpr *) expr)->minmaxcollid;

973 break;

974 case T_SQLValueFunction:

975

977 coll = C_COLLATION_OID;

978 else

980 break;

981 case T_XmlExpr:

982

983

984

985

986

987

989 coll = DEFAULT_COLLATION_OID;

990 else

992 break;

993 case T_JsonValueExpr:

995 break;

996 case T_JsonConstructorExpr:

997 {

999

1002 else

1004 }

1005 break;

1006 case T_JsonIsPredicate:

1007

1008 coll = InvalidOid;

1009 break;

1010 case T_JsonExpr:

1011 {

1013

1015 }

1016 break;

1017 case T_JsonBehavior:

1018 {

1020

1021 if (behavior->expr)

1023 else

1025 }

1026 break;

1027 case T_NullTest:

1028

1029 coll = InvalidOid;

1030 break;

1031 case T_BooleanTest:

1032

1033 coll = InvalidOid;

1034 break;

1035 case T_CoerceToDomain:

1036 coll = ((const CoerceToDomain *) expr)->resultcollid;

1037 break;

1038 case T_CoerceToDomainValue:

1040 break;

1041 case T_SetToDefault:

1042 coll = ((const SetToDefault *) expr)->collation;

1043 break;

1044 case T_CurrentOfExpr:

1045

1046 coll = InvalidOid;

1047 break;

1048 case T_NextValueExpr:

1049

1050 coll = InvalidOid;

1051 break;

1052 case T_InferenceElem:

1054 break;

1055 case T_ReturningExpr:

1057 break;

1058 case T_PlaceHolderVar:

1060 break;

1061 default:

1062 elog(ERROR, "unrecognized node type: %d", (int) nodeTag(expr));

1063 coll = InvalidOid;

1064 break;

1065 }

1066 return coll;

1067}

1068

1069

1070

1071

1072

1073

1074

1077{

1078 Oid coll;

1079

1080 if (!expr)

1082

1084 {

1085 case T_Aggref:

1086 coll = ((const Aggref *) expr)->inputcollid;

1087 break;

1088 case T_WindowFunc:

1089 coll = ((const WindowFunc *) expr)->inputcollid;

1090 break;

1091 case T_FuncExpr:

1092 coll = ((const FuncExpr *) expr)->inputcollid;

1093 break;

1094 case T_OpExpr:

1095 coll = ((const OpExpr *) expr)->inputcollid;

1096 break;

1097 case T_DistinctExpr:

1098 coll = ((const DistinctExpr *) expr)->inputcollid;

1099 break;

1100 case T_NullIfExpr:

1101 coll = ((const NullIfExpr *) expr)->inputcollid;

1102 break;

1103 case T_ScalarArrayOpExpr:

1105 break;

1106 case T_MinMaxExpr:

1107 coll = ((const MinMaxExpr *) expr)->inputcollid;

1108 break;

1109 default:

1111 break;

1112 }

1113 return coll;

1114}

1115

1116

1117

1118

1119

1120

1121

1122

1123void

1125{

1127 {

1128 case T_Var:

1129 ((Var *) expr)->varcollid = collation;

1130 break;

1131 case T_Const:

1132 ((Const *) expr)->constcollid = collation;

1133 break;

1134 case T_Param:

1135 ((Param *) expr)->paramcollid = collation;

1136 break;

1137 case T_Aggref:

1138 ((Aggref *) expr)->aggcollid = collation;

1139 break;

1140 case T_GroupingFunc:

1142 break;

1143 case T_WindowFunc:

1144 ((WindowFunc *) expr)->wincollid = collation;

1145 break;

1146 case T_MergeSupportFunc:

1148 break;

1149 case T_SubscriptingRef:

1151 break;

1152 case T_FuncExpr:

1153 ((FuncExpr *) expr)->funccollid = collation;

1154 break;

1155 case T_NamedArgExpr:

1157 break;

1158 case T_OpExpr:

1159 ((OpExpr *) expr)->opcollid = collation;

1160 break;

1161 case T_DistinctExpr:

1162 ((DistinctExpr *) expr)->opcollid = collation;

1163 break;

1164 case T_NullIfExpr:

1165 ((NullIfExpr *) expr)->opcollid = collation;

1166 break;

1167 case T_ScalarArrayOpExpr:

1168

1169 Assert(OidIsValid(collation));

1170 break;

1171 case T_BoolExpr:

1172

1173 Assert(OidIsValid(collation));

1174 break;

1175 case T_SubLink:

1176#ifdef USE_ASSERT_CHECKING

1177 {

1179

1182 {

1183

1186

1188 elog(ERROR, "cannot set collation for untransformed sublink");

1190 Assert(!tent->resjunk);

1192 }

1193 else

1194 {

1195

1197 }

1198 }

1199#endif

1200 break;

1201 case T_FieldSelect:

1202 ((FieldSelect *) expr)->resultcollid = collation;

1203 break;

1204 case T_FieldStore:

1205

1206 Assert(OidIsValid(collation));

1207 break;

1208 case T_RelabelType:

1209 ((RelabelType *) expr)->resultcollid = collation;

1210 break;

1211 case T_CoerceViaIO:

1212 ((CoerceViaIO *) expr)->resultcollid = collation;

1213 break;

1214 case T_ArrayCoerceExpr:

1216 break;

1217 case T_ConvertRowtypeExpr:

1218

1219 Assert(OidIsValid(collation));

1220 break;

1221 case T_CaseExpr:

1222 ((CaseExpr *) expr)->casecollid = collation;

1223 break;

1224 case T_ArrayExpr:

1225 ((ArrayExpr *) expr)->array_collid = collation;

1226 break;

1227 case T_RowExpr:

1228

1229 Assert(OidIsValid(collation));

1230 break;

1231 case T_RowCompareExpr:

1232

1233 Assert(OidIsValid(collation));

1234 break;

1235 case T_CoalesceExpr:

1236 ((CoalesceExpr *) expr)->coalescecollid = collation;

1237 break;

1238 case T_MinMaxExpr:

1239 ((MinMaxExpr *) expr)->minmaxcollid = collation;

1240 break;

1241 case T_SQLValueFunction:

1243 (collation == C_COLLATION_OID) :

1245 break;

1246 case T_XmlExpr:

1248 (collation == DEFAULT_COLLATION_OID) :

1250 break;

1251 case T_JsonValueExpr:

1253 collation);

1254 break;

1255 case T_JsonConstructorExpr:

1256 {

1258

1261 else

1263

1264 }

1265 break;

1266 case T_JsonIsPredicate:

1267 Assert(OidIsValid(collation));

1268 break;

1269 case T_JsonExpr:

1270 {

1272

1274 }

1275 break;

1276 case T_JsonBehavior:

1277 {

1279

1280 if (behavior->expr)

1282 }

1283 break;

1284 case T_NullTest:

1285

1286 Assert(OidIsValid(collation));

1287 break;

1288 case T_BooleanTest:

1289

1290 Assert(OidIsValid(collation));

1291 break;

1292 case T_CoerceToDomain:

1293 ((CoerceToDomain *) expr)->resultcollid = collation;

1294 break;

1295 case T_CoerceToDomainValue:

1297 break;

1298 case T_SetToDefault:

1299 ((SetToDefault *) expr)->collation = collation;

1300 break;

1301 case T_CurrentOfExpr:

1302

1303 Assert(OidIsValid(collation));

1304 break;

1305 case T_NextValueExpr:

1306

1307 Assert(OidIsValid(collation));

1308 break;

1309 default:

1310 elog(ERROR, "unrecognized node type: %d", (int) nodeTag(expr));

1311 break;

1312 }

1313}

1314

1315

1316

1317

1318

1319

1320

1321

1322

1323void

1325{

1327 {

1328 case T_Aggref:

1329 ((Aggref *) expr)->inputcollid = inputcollation;

1330 break;

1331 case T_WindowFunc:

1332 ((WindowFunc *) expr)->inputcollid = inputcollation;

1333 break;

1334 case T_FuncExpr:

1335 ((FuncExpr *) expr)->inputcollid = inputcollation;

1336 break;

1337 case T_OpExpr:

1338 ((OpExpr *) expr)->inputcollid = inputcollation;

1339 break;

1340 case T_DistinctExpr:

1341 ((DistinctExpr *) expr)->inputcollid = inputcollation;

1342 break;

1343 case T_NullIfExpr:

1344 ((NullIfExpr *) expr)->inputcollid = inputcollation;

1345 break;

1346 case T_ScalarArrayOpExpr:

1348 break;

1349 case T_MinMaxExpr:

1350 ((MinMaxExpr *) expr)->inputcollid = inputcollation;

1351 break;

1352 default:

1353 break;

1354 }

1355}

1356

1357

1358

1359

1360

1361

1362

1363

1364

1365

1366

1367

1368

1369

1370

1371

1372

1373

1374

1375

1376

1377

1378

1379

1380

1381

1382

1383

1384

1385

1386

1387int

1389{

1390 int loc;

1391

1392 if (expr == NULL)

1393 return -1;

1395 {

1396 case T_RangeVar:

1397 loc = ((const RangeVar *) expr)->location;

1398 break;

1399 case T_TableFunc:

1400 loc = ((const TableFunc *) expr)->location;

1401 break;

1402 case T_Var:

1403 loc = ((const Var *) expr)->location;

1404 break;

1405 case T_Const:

1406 loc = ((const Const *) expr)->location;

1407 break;

1408 case T_Param:

1409 loc = ((const Param *) expr)->location;

1410 break;

1411 case T_Aggref:

1412

1413 loc = ((const Aggref *) expr)->location;

1414 break;

1415 case T_GroupingFunc:

1416 loc = ((const GroupingFunc *) expr)->location;

1417 break;

1418 case T_WindowFunc:

1419

1420 loc = ((const WindowFunc *) expr)->location;

1421 break;

1422 case T_MergeSupportFunc:

1424 break;

1425 case T_SubscriptingRef:

1426

1428 break;

1429 case T_FuncExpr:

1430 {

1432

1433

1436 }

1437 break;

1438 case T_NamedArgExpr:

1439 {

1441

1442

1445 }

1446 break;

1447 case T_OpExpr:

1448 case T_DistinctExpr:

1449 case T_NullIfExpr:

1450 {

1451 const OpExpr *opexpr = (const OpExpr *) expr;

1452

1453

1456 }

1457 break;

1458 case T_ScalarArrayOpExpr:

1459 {

1461

1462

1465 }

1466 break;

1467 case T_BoolExpr:

1468 {

1470

1471

1472

1473

1474

1475

1478 }

1479 break;

1480 case T_SubLink:

1481 {

1483

1484

1487 }

1488 break;

1489 case T_FieldSelect:

1490

1492 break;

1493 case T_FieldStore:

1494

1496 break;

1497 case T_RelabelType:

1498 {

1500

1501

1504 }

1505 break;

1506 case T_CoerceViaIO:

1507 {

1509

1510

1513 }

1514 break;

1515 case T_ArrayCoerceExpr:

1516 {

1518

1519

1522 }

1523 break;

1524 case T_ConvertRowtypeExpr:

1525 {

1527

1528

1531 }

1532 break;

1533 case T_CollateExpr:

1534

1536 break;

1537 case T_CaseExpr:

1538

1539 loc = ((const CaseExpr *) expr)->location;

1540 break;

1541 case T_CaseWhen:

1542

1543 loc = ((const CaseWhen *) expr)->location;

1544 break;

1545 case T_ArrayExpr:

1546

1547 loc = ((const ArrayExpr *) expr)->location;

1548 break;

1549 case T_RowExpr:

1550

1551 loc = ((const RowExpr *) expr)->location;

1552 break;

1553 case T_RowCompareExpr:

1554

1556 break;

1557 case T_CoalesceExpr:

1558

1559 loc = ((const CoalesceExpr *) expr)->location;

1560 break;

1561 case T_MinMaxExpr:

1562

1563 loc = ((const MinMaxExpr *) expr)->location;

1564 break;

1565 case T_SQLValueFunction:

1566

1568 break;

1569 case T_XmlExpr:

1570 {

1572

1573

1576 }

1577 break;

1578 case T_JsonFormat:

1579 loc = ((const JsonFormat *) expr)->location;

1580 break;

1581 case T_JsonValueExpr:

1583 break;

1584 case T_JsonConstructorExpr:

1586 break;

1587 case T_JsonIsPredicate:

1589 break;

1590 case T_JsonExpr:

1591 {

1593

1594

1597 }

1598 break;

1599 case T_JsonBehavior:

1601 break;

1602 case T_NullTest:

1603 {

1605

1606

1609 }

1610 break;

1611 case T_BooleanTest:

1612 {

1614

1615

1618 }

1619 break;

1620 case T_CoerceToDomain:

1621 {

1623

1624

1627 }

1628 break;

1629 case T_CoerceToDomainValue:

1631 break;

1632 case T_SetToDefault:

1633 loc = ((const SetToDefault *) expr)->location;

1634 break;

1635 case T_ReturningExpr:

1637 break;

1638 case T_TargetEntry:

1639

1641 break;

1642 case T_IntoClause:

1643

1645 break;

1646 case T_List:

1647 {

1648

1650

1651 loc = -1;

1652 foreach(lc, (const List *) expr)

1653 {

1655 if (loc >= 0)

1656 break;

1657 }

1658 }

1659 break;

1660 case T_A_Expr:

1661 {

1662 const A_Expr *aexpr = (const A_Expr *) expr;

1663

1664

1665

1668 }

1669 break;

1670 case T_ColumnRef:

1671 loc = ((const ColumnRef *) expr)->location;

1672 break;

1673 case T_ParamRef:

1674 loc = ((const ParamRef *) expr)->location;

1675 break;

1676 case T_A_Const:

1677 loc = ((const A_Const *) expr)->location;

1678 break;

1679 case T_FuncCall:

1680 {

1682

1683

1684

1687 }

1688 break;

1689 case T_A_ArrayExpr:

1690

1691 loc = ((const A_ArrayExpr *) expr)->location;

1692 break;

1693 case T_ResTarget:

1694

1695 loc = ((const ResTarget *) expr)->location;

1696 break;

1697 case T_MultiAssignRef:

1699 break;

1700 case T_TypeCast:

1701 {

1703

1704

1705

1706

1707

1711 }

1712 break;

1713 case T_CollateClause:

1714

1716 break;

1717 case T_SortBy:

1718

1720 break;

1721 case T_WindowDef:

1722 loc = ((const WindowDef *) expr)->location;

1723 break;

1724 case T_RangeTableSample:

1726 break;

1727 case T_TypeName:

1728 loc = ((const TypeName *) expr)->location;

1729 break;

1730 case T_ColumnDef:

1731 loc = ((const ColumnDef *) expr)->location;

1732 break;

1733 case T_Constraint:

1734 loc = ((const Constraint *) expr)->location;

1735 break;

1736 case T_FunctionParameter:

1738 break;

1739 case T_XmlSerialize:

1740

1741 loc = ((const XmlSerialize *) expr)->location;

1742 break;

1743 case T_GroupingSet:

1744 loc = ((const GroupingSet *) expr)->location;

1745 break;

1746 case T_WithClause:

1747 loc = ((const WithClause *) expr)->location;

1748 break;

1749 case T_InferClause:

1750 loc = ((const InferClause *) expr)->location;

1751 break;

1752 case T_OnConflictClause:

1754 break;

1755 case T_CTESearchClause:

1757 break;

1758 case T_CTECycleClause:

1760 break;

1761 case T_CommonTableExpr:

1763 break;

1764 case T_JsonKeyValue:

1765

1767 break;

1768 case T_JsonObjectConstructor:

1770 break;

1771 case T_JsonArrayConstructor:

1773 break;

1774 case T_JsonArrayQueryConstructor:

1776 break;

1777 case T_JsonAggConstructor:

1779 break;

1780 case T_JsonObjectAgg:

1782 break;

1783 case T_JsonArrayAgg:

1785 break;

1786 case T_PlaceHolderVar:

1787

1789 break;

1790 case T_InferenceElem:

1791

1793 break;

1794 case T_PartitionElem:

1796 break;

1797 case T_PartitionSpec:

1799 break;

1800 case T_PartitionBoundSpec:

1802 break;

1803 case T_PartitionRangeDatum:

1805 break;

1806 default:

1807

1808 loc = -1;

1809 break;

1810 }

1811 return loc;

1812}

1813

1814

1815

1816

1817

1818

1819static int

1821{

1822 if (loc1 < 0)

1823 return loc2;

1824 else if (loc2 < 0)

1825 return loc1;

1826 else

1827 return Min(loc1, loc2);

1828}

1829

1830

1831

1832

1833

1834

1835

1836

1837

1838

1839

1840void

1842{

1843

1845}

1846

1847static bool

1849{

1850 if (node == NULL)

1851 return false;

1861}

1862

1863

1864

1865

1866

1867

1868

1869

1870

1871void

1873{

1876}

1877

1878

1879

1880

1881

1882void

1884{

1887}

1888

1889

1890

1891

1892

1893

1894

1895

1896

1897

1898

1899

1900

1901

1902

1903

1904

1905

1906

1907

1908

1909bool

1911 void *context)

1912{

1914 {

1915 case T_Aggref:

1916 {

1918

1919 if (checker(expr->aggfnoid, context))

1920 return true;

1921 }

1922 break;

1923 case T_WindowFunc:

1924 {

1926

1927 if (checker(expr->winfnoid, context))

1928 return true;

1929 }

1930 break;

1931 case T_FuncExpr:

1932 {

1934

1935 if (checker(expr->funcid, context))

1936 return true;

1937 }

1938 break;

1939 case T_OpExpr:

1940 case T_DistinctExpr:

1941 case T_NullIfExpr:

1942 {

1944

1945

1947 if (checker(expr->opfuncid, context))

1948 return true;

1949 }

1950 break;

1951 case T_ScalarArrayOpExpr:

1952 {

1954

1956 if (checker(expr->opfuncid, context))

1957 return true;

1958 }

1959 break;

1960 case T_CoerceViaIO:

1961 {

1963 Oid iofunc;

1964 Oid typioparam;

1965 bool typisvarlena;

1966

1967

1969 &iofunc, &typioparam);

1970 if (checker(iofunc, context))

1971 return true;

1972

1974 &iofunc, &typisvarlena);

1975 if (checker(iofunc, context))

1976 return true;

1977 }

1978 break;

1979 case T_RowCompareExpr:

1980 {

1983

1984 foreach(opid, rcexpr->opnos)

1985 {

1987

1988 if (checker(opfuncid, context))

1989 return true;

1990 }

1991 }

1992 break;

1993 default:

1994 break;

1995 }

1996 return false;

1997}

1998

1999

2000

2001

2002

2003

2004

2005

2006

2007

2008

2009

2010

2011

2012

2013

2014

2015

2016

2017

2018

2019

2020

2021

2022

2023

2024

2025

2026

2027

2028

2029

2030

2031

2032

2033

2034

2035

2036

2037

2038

2039

2040

2041

2042

2043

2044

2045

2046

2047

2048

2049

2050

2051

2052

2053

2054

2055

2056

2057

2058

2059

2060

2061

2062

2063

2064

2065

2066

2067

2068

2069

2070

2071

2072

2073

2074

2075

2076

2077

2078

2079

2080

2081

2082

2083

2084

2085

2086

2087

2088

2089

2090

2091

2092bool

2095 void *context)

2096{

2098

2099

2100

2101

2102

2103

2104

2105

2106

2107#define WALK(n) walker((Node *) (n), context)

2108

2109#define LIST_WALK(l) expression_tree_walker_impl((Node *) (l), walker, context)

2110

2111 if (node == NULL)

2112 return false;

2113

2114

2116

2118 {

2119 case T_Var:

2120 case T_Const:

2121 case T_Param:

2122 case T_CaseTestExpr:

2123 case T_SQLValueFunction:

2124 case T_CoerceToDomainValue:

2125 case T_SetToDefault:

2126 case T_CurrentOfExpr:

2127 case T_NextValueExpr:

2128 case T_RangeTblRef:

2129 case T_SortGroupClause:

2130 case T_CTESearchClause:

2131 case T_MergeSupportFunc:

2132

2133 break;

2134 case T_WithCheckOption:

2136 case T_Aggref:

2137 {

2139

2140

2142 return true;

2144 return true;

2146 return true;

2148 return true;

2150 return true;

2151 }

2152 break;

2153 case T_GroupingFunc:

2154 {

2156

2158 return true;

2159 }

2160 break;

2161 case T_WindowFunc:

2162 {

2164

2165

2167 return true;

2169 return true;

2170 if (WALK(expr->runCondition))

2171 return true;

2172 }

2173 break;

2174 case T_WindowFuncRunCondition:

2175 {

2177

2179 return true;

2180 }

2181 break;

2182 case T_SubscriptingRef:

2183 {

2185

2186

2188 return true;

2190 return true;

2191

2193 return true;

2194

2196 return true;

2197 }

2198 break;

2199 case T_FuncExpr:

2200 {

2202

2204 return true;

2205 }

2206 break;

2207 case T_NamedArgExpr:

2209 case T_OpExpr:

2210 case T_DistinctExpr:

2211 case T_NullIfExpr:

2212 {

2214

2216 return true;

2217 }

2218 break;

2219 case T_ScalarArrayOpExpr:

2220 {

2222

2224 return true;

2225 }

2226 break;

2227 case T_BoolExpr:

2228 {

2230

2232 return true;

2233 }

2234 break;

2235 case T_SubLink:

2236 {

2238

2240 return true;

2241

2242

2243

2244

2245

2247 }

2248 break;

2249 case T_SubPlan:

2250 {

2252

2253

2255 return true;

2256

2258 return true;

2259 }

2260 break;

2261 case T_AlternativeSubPlan:

2263 case T_FieldSelect:

2265 case T_FieldStore:

2266 {

2268

2270 return true;

2272 return true;

2273 }

2274 break;

2275 case T_RelabelType:

2277 case T_CoerceViaIO:

2279 case T_ArrayCoerceExpr:

2280 {

2282

2284 return true;

2286 return true;

2287 }

2288 break;

2289 case T_ConvertRowtypeExpr:

2291 case T_CollateExpr:

2293 case T_CaseExpr:

2294 {

2296

2297 if (WALK(caseexpr->arg))

2298 return true;

2299

2300 foreach(temp, caseexpr->args)

2301 {

2303

2305 return true;

2307 return true;

2308 }

2310 return true;

2311 }

2312 break;

2313 case T_ArrayExpr:

2315 case T_RowExpr:

2316

2318 case T_RowCompareExpr:

2319 {

2321

2323 return true;

2325 return true;

2326 }

2327 break;

2328 case T_CoalesceExpr:

2330 case T_MinMaxExpr:

2332 case T_XmlExpr:

2333 {

2335

2337 return true;

2338

2340 return true;

2341 }

2342 break;

2343 case T_JsonValueExpr:

2344 {

2346

2348 return true;

2350 return true;

2351 }

2352 break;

2353 case T_JsonConstructorExpr:

2354 {

2356

2358 return true;

2360 return true;

2362 return true;

2363 }

2364 break;

2365 case T_JsonIsPredicate:

2367 case T_JsonExpr:

2368 {

2370

2372 return true;

2374 return true;

2376 return true;

2377

2379 return true;

2381 return true;

2382 }

2383 break;

2384 case T_JsonBehavior:

2385 {

2387

2389 return true;

2390 }

2391 break;

2392 case T_NullTest:

2394 case T_BooleanTest:

2396 case T_CoerceToDomain:

2398 case T_TargetEntry:

2400 case T_Query:

2401

2402 break;

2403 case T_WindowClause:

2404 {

2406

2408 return true;

2410 return true;

2412 return true;

2414 return true;

2415 }

2416 break;

2417 case T_CTECycleClause:

2418 {

2420

2422 return true;

2424 return true;

2425 }

2426 break;

2427 case T_CommonTableExpr:

2428 {

2430

2431

2432

2433

2434

2436 return true;

2437

2438 if (WALK(cte->search_clause))

2439 return true;

2440 if (WALK(cte->cycle_clause))

2441 return true;

2442 }

2443 break;

2444 case T_JsonKeyValue:

2445 {

2447

2449 return true;

2451 return true;

2452 }

2453 break;

2454 case T_JsonObjectConstructor:

2455 {

2457

2459 return true;

2460 }

2461 break;

2462 case T_JsonArrayConstructor:

2463 {

2465

2467 return true;

2468 }

2469 break;

2470 case T_JsonArrayQueryConstructor:

2471 {

2473

2475 return true;

2476 }

2477 break;

2478 case T_JsonAggConstructor:

2479 {

2481

2483 return true;

2485 return true;

2487 return true;

2488 }

2489 break;

2490 case T_JsonObjectAgg:

2491 {

2493

2495 return true;

2497 return true;

2498 }

2499 break;

2500 case T_JsonArrayAgg:

2501 {

2503

2505 return true;

2507 return true;

2508 }

2509 break;

2510

2511 case T_PartitionBoundSpec:

2512 {

2514

2516 return true;

2518 return true;

2520 return true;

2521 }

2522 break;

2523 case T_PartitionRangeDatum:

2524 {

2526

2528 return true;

2529 }

2530 break;

2531 case T_List:

2532 foreach(temp, (List *) node)

2533 {

2535 return true;

2536 }

2537 break;

2538 case T_FromExpr:

2539 {

2541

2543 return true;

2545 return true;

2546 }

2547 break;

2548 case T_OnConflictExpr:

2549 {

2551

2553 return true;

2555 return true;

2557 return true;

2559 return true;

2561 return true;

2562 }

2563 break;

2564 case T_MergeAction:

2565 {

2567

2569 return true;

2571 return true;

2572 }

2573 break;

2574 case T_PartitionPruneStepOp:

2575 {

2577

2579 return true;

2580 }

2581 break;

2582 case T_PartitionPruneStepCombine:

2583

2584 break;

2585 case T_JoinExpr:

2586 {

2588

2590 return true;

2592 return true;

2594 return true;

2595

2596

2597

2598

2599 }

2600 break;

2601 case T_SetOperationStmt:

2602 {

2604

2606 return true;

2608 return true;

2609

2610

2611 }

2612 break;

2613 case T_IndexClause:

2614 {

2616

2618 return true;

2620 return true;

2621 }

2622 break;

2623 case T_PlaceHolderVar:

2625 case T_InferenceElem:

2627 case T_ReturningExpr:

2629 case T_AppendRelInfo:

2630 {

2632

2634 return true;

2635 }

2636 break;

2637 case T_PlaceHolderInfo:

2639 case T_RangeTblFunction:

2641 case T_TableSampleClause:

2642 {

2644

2646 return true;

2648 return true;

2649 }

2650 break;

2651 case T_TableFunc:

2652 {

2654

2655 if (WALK(tf->ns_uris))

2656 return true;

2658 return true;

2660 return true;

2662 return true;

2663 if (WALK(tf->coldefexprs))

2664 return true;

2665 if (WALK(tf->colvalexprs))

2666 return true;

2667 if (WALK(tf->passingvalexprs))

2668 return true;

2669 }

2670 break;

2671 default:

2672 elog(ERROR, "unrecognized node type: %d",

2674 break;

2675 }

2676 return false;

2677

2678

2679#undef LIST_WALK

2680}

2681

2682

2683

2684

2685

2686

2687

2688

2689

2690

2691

2692

2693

2694

2695

2696

2697bool

2700 void *context,

2701 int flags)

2702{

2704

2705

2706

2707

2708

2709

2710

2711

2713 return true;

2714 if (WALK(query->withCheckOptions))

2715 return true;

2717 return true;

2719 return true;

2721 return true;

2723 return true;

2725 return true;

2727 return true;

2729 return true;

2731 return true;

2733 return true;

2734

2735

2736

2737

2738

2739

2741 {

2743 return true;

2745 return true;

2747 return true;

2749 return true;

2750 }

2751 else

2752 {

2753

2754

2755

2756

2758

2760 {

2762

2764 return true;

2766 return true;

2767 }

2768 }

2769

2770

2771

2772

2773

2774

2775

2776

2777

2778

2779

2780

2781

2783 {

2785 return true;

2786 }

2788 {

2790 return true;

2791 }

2792 return false;

2793}

2794

2795

2796

2797

2798

2799

2800bool

2803 void *context,

2804 int flags)

2805{

2807

2808 foreach(rt, rtable)

2809 {

2811

2813 return true;

2814 }

2815 return false;

2816}

2817

2818

2819

2820

2821bool

2824 void *context,

2825 int flags)

2826{

2827

2828

2829

2830

2831

2833 if (WALK(rte))

2834 return true;

2835

2837 {

2840 return true;

2841 break;

2845 return true;

2846 break;

2849 if (WALK(rte->joinaliasvars))

2850 return true;

2851 break;

2854 return true;

2855 break;

2858 return true;

2859 break;

2862 return true;

2863 break;

2867

2868 break;

2871 if (WALK(rte->groupexprs))

2872 return true;

2873 break;

2874 }

2875

2876 if (WALK(rte->securityQuals))

2877 return true;

2878

2880 if (WALK(rte))

2881 return true;

2882

2883 return false;

2884}

2885

2886

2887

2888

2889

2890

2891

2892

2893

2894

2895

2896

2897

2898

2899

2900

2901

2902

2903

2904

2905

2906

2907

2908

2909

2910

2911

2912

2913

2914

2915

2916

2917

2918

2919

2920

2921

2922

2923

2924

2925

2926

2927

2928

2929

2930

2931

2932

2933

2934

2935

2936

2937

2938

2939

2940

2941

2942

2943

2944

2945

2946

2947

2948

2952 void *context)

2953{

2954

2955

2956

2957

2958

2959#define FLATCOPY(newnode, node, nodetype) \

2960 ( (newnode) = (nodetype *) palloc(sizeof(nodetype)), \

2961 memcpy((newnode), (node), sizeof(nodetype)) )

2962

2963#define MUTATE(newfield, oldfield, fieldtype) \

2964 ( (newfield) = (fieldtype) mutator((Node *) (oldfield), context) )

2965

2966 if (node == NULL)

2967 return NULL;

2968

2969

2971

2973 {

2974

2975

2976

2977

2978

2979 case T_Var:

2980 {

2981 Var *var = (Var *) node;

2982 Var *newnode;

2983

2985

2986 return (Node *) newnode;

2987 }

2988 break;

2989 case T_Const:

2990 {

2993

2995

2996 return (Node *) newnode;

2997 }

2998 break;

2999 case T_Param:

3000 case T_CaseTestExpr:

3001 case T_SQLValueFunction:

3002 case T_JsonFormat:

3003 case T_CoerceToDomainValue:

3004 case T_SetToDefault:

3005 case T_CurrentOfExpr:

3006 case T_NextValueExpr:

3007 case T_RangeTblRef:

3008 case T_SortGroupClause:

3009 case T_CTESearchClause:

3010 case T_MergeSupportFunc:

3012 case T_WithCheckOption:

3013 {

3016

3019 return (Node *) newnode;

3020 }

3021 case T_Aggref:

3022 {

3025

3027

3028 newnode->aggargtypes = list_copy(aggref->aggargtypes);

3034 return (Node *) newnode;

3035 }

3036 break;

3037 case T_GroupingFunc:

3038 {

3041

3043 MUTATE(newnode->args, grouping->args, List *);

3044

3045

3046

3047

3048

3049

3050

3051

3052

3053

3054 newnode->refs = list_copy(grouping->refs);

3055 newnode->cols = list_copy(grouping->cols);

3056

3057 return (Node *) newnode;

3058 }

3059 break;

3060 case T_WindowFunc:

3061 {

3064

3068 return (Node *) newnode;

3069 }

3070 break;

3071 case T_WindowFuncRunCondition:

3072 {

3075

3078 return (Node *) newnode;

3079 }

3080 break;

3081 case T_SubscriptingRef:

3082 {

3085

3095

3096 return (Node *) newnode;

3097 }

3098 break;

3099 case T_FuncExpr:

3100 {

3103

3106 return (Node *) newnode;

3107 }

3108 break;

3109 case T_NamedArgExpr:

3110 {

3113

3116 return (Node *) newnode;

3117 }

3118 break;

3119 case T_OpExpr:

3120 {

3123

3126 return (Node *) newnode;

3127 }

3128 break;

3129 case T_DistinctExpr:

3130 {

3133

3136 return (Node *) newnode;

3137 }

3138 break;

3139 case T_NullIfExpr:

3140 {

3143

3146 return (Node *) newnode;

3147 }

3148 break;

3149 case T_ScalarArrayOpExpr:

3150 {

3153

3156 return (Node *) newnode;

3157 }

3158 break;

3159 case T_BoolExpr:

3160 {

3163

3166 return (Node *) newnode;

3167 }

3168 break;

3169 case T_SubLink:

3170 {

3173

3176

3177

3178

3179

3180

3182 return (Node *) newnode;

3183 }

3184 break;

3185 case T_SubPlan:

3186 {

3189

3191

3193

3195

3196 return (Node *) newnode;

3197 }

3198 break;

3199 case T_AlternativeSubPlan:

3200 {

3203

3206 return (Node *) newnode;

3207 }

3208 break;

3209 case T_FieldSelect:

3210 {

3213

3216 return (Node *) newnode;

3217 }

3218 break;

3219 case T_FieldStore:

3220 {

3223

3227 newnode->fieldnums = list_copy(fstore->fieldnums);

3228 return (Node *) newnode;

3229 }

3230 break;

3231 case T_RelabelType:

3232 {

3235

3238 return (Node *) newnode;

3239 }

3240 break;

3241 case T_CoerceViaIO:

3242 {

3245

3248 return (Node *) newnode;

3249 }

3250 break;

3251 case T_ArrayCoerceExpr:

3252 {

3255

3259 return (Node *) newnode;

3260 }

3261 break;

3262 case T_ConvertRowtypeExpr:

3263 {

3266

3269 return (Node *) newnode;

3270 }

3271 break;

3272 case T_CollateExpr:

3273 {

3276

3279 return (Node *) newnode;

3280 }

3281 break;

3282 case T_CaseExpr:

3283 {

3286

3291 return (Node *) newnode;

3292 }

3293 break;

3294 case T_CaseWhen:

3295 {

3298

3302 return (Node *) newnode;

3303 }

3304 break;

3305 case T_ArrayExpr:

3306 {

3309

3311 MUTATE(newnode->elements, arrayexpr->elements, List *);

3312 return (Node *) newnode;

3313 }

3314 break;

3315 case T_RowExpr:

3316 {

3319

3322

3323 return (Node *) newnode;

3324 }

3325 break;

3326 case T_RowCompareExpr:

3327 {

3330

3334 return (Node *) newnode;

3335 }

3336 break;

3337 case T_CoalesceExpr:

3338 {

3341

3344 return (Node *) newnode;

3345 }

3346 break;

3347 case T_MinMaxExpr:

3348 {

3351

3354 return (Node *) newnode;

3355 }

3356 break;

3357 case T_XmlExpr:

3358 {

3361

3364

3366 return (Node *) newnode;

3367 }

3368 break;

3369 case T_JsonReturning:

3370 {

3373

3376

3377 return (Node *) newnode;

3378 }

3379 case T_JsonValueExpr:

3380 {

3383

3388

3389 return (Node *) newnode;

3390 }

3391 case T_JsonConstructorExpr:

3392 {

3395

3401

3402 return (Node *) newnode;

3403 }

3404 case T_JsonIsPredicate:

3405 {

3408

3412

3413 return (Node *) newnode;

3414 }

3415 case T_JsonExpr:

3416 {

3419

3424

3427 return (Node *) newnode;

3428 }

3429 break;

3430 case T_JsonBehavior:

3431 {

3434

3437 return (Node *) newnode;

3438 }

3439 break;

3440 case T_NullTest:

3441 {

3444

3447 return (Node *) newnode;

3448 }

3449 break;

3450 case T_BooleanTest:

3451 {

3454

3457 return (Node *) newnode;

3458 }

3459 break;

3460 case T_CoerceToDomain:

3461 {

3464

3467 return (Node *) newnode;

3468 }

3469 break;

3470 case T_ReturningExpr:

3471 {

3474

3477 return (Node *) newnode;

3478 }

3479 break;

3480 case T_TargetEntry:

3481 {

3484

3487 return (Node *) newnode;

3488 }

3489 break;

3490 case T_Query:

3491

3492 return node;

3493 case T_WindowClause:

3494 {

3497

3503 return (Node *) newnode;

3504 }

3505 break;

3506 case T_CTECycleClause:

3507 {

3510

3514 return (Node *) newnode;

3515 }

3516 break;

3517 case T_CommonTableExpr:

3518 {

3521

3523

3524

3525

3526

3527

3529

3532

3533 return (Node *) newnode;

3534 }

3535 break;

3536 case T_PartitionBoundSpec:

3537 {

3540

3545 return (Node *) newnode;

3546 }

3547 break;

3548 case T_PartitionRangeDatum:

3549 {

3552

3555 return (Node *) newnode;

3556 }

3557 break;

3558 case T_List:

3559 {

3560

3561

3562

3563

3564

3565 List *resultlist;

3567

3568 resultlist = NIL;

3569 foreach(temp, (List *) node)

3570 {

3571 resultlist = lappend(resultlist,

3573 context));

3574 }

3575 return (Node *) resultlist;

3576 }

3577 break;

3578 case T_FromExpr:

3579 {

3582

3586 return (Node *) newnode;

3587 }

3588 break;

3589 case T_OnConflictExpr:

3590 {

3593

3600

3601 return (Node *) newnode;

3602 }

3603 break;

3604 case T_MergeAction:

3605 {

3608

3612

3613 return (Node *) newnode;

3614 }

3615 break;

3616 case T_PartitionPruneStepOp:

3617 {

3620

3623

3624 return (Node *) newnode;

3625 }

3626 break;

3627 case T_PartitionPruneStepCombine:

3628

3630 case T_JoinExpr:

3631 {

3634

3639

3640 return (Node *) newnode;

3641 }

3642 break;

3643 case T_SetOperationStmt:

3644 {

3647

3651

3652 return (Node *) newnode;

3653 }

3654 break;

3655 case T_IndexClause:

3656 {

3659

3663 return (Node *) newnode;

3664 }

3665 break;

3666 case T_PlaceHolderVar:

3667 {

3670

3672 MUTATE(newnode->phexpr, phv->phexpr, Expr *);

3673

3674 return (Node *) newnode;

3675 }

3676 break;

3677 case T_InferenceElem:

3678 {

3681

3684 return (Node *) newnode;

3685 }

3686 break;

3687 case T_AppendRelInfo:

3688 {

3691

3694

3695 return (Node *) newnode;

3696 }

3697 break;

3698 case T_PlaceHolderInfo:

3699 {

3702

3705

3706 return (Node *) newnode;

3707 }

3708 break;

3709 case T_RangeTblFunction:

3710 {

3713

3716

3717 return (Node *) newnode;

3718 }

3719 break;

3720 case T_TableSampleClause:

3721 {

3724

3728 return (Node *) newnode;

3729 }

3730 break;

3731 case T_TableFunc:

3732 {

3735

3737 MUTATE(newnode->ns_uris, tf->ns_uris, List *);

3741 MUTATE(newnode->coldefexprs, tf->coldefexprs, List *);

3742 MUTATE(newnode->colvalexprs, tf->colvalexprs, List *);

3743 MUTATE(newnode->passingvalexprs, tf->passingvalexprs, List *);

3744 return (Node *) newnode;

3745 }

3746 break;

3747 default:

3748 elog(ERROR, "unrecognized node type: %d",

3750 break;

3751 }

3752

3753 return NULL;

3754}

3755

3756

3757

3758

3759

3760

3761

3762

3763

3764

3765

3766

3767

3768

3769

3770

3771

3772

3773

3774

3775

3779 void *context,

3780 int flags)

3781{

3783

3785 {

3786 Query *newquery;

3787

3789 query = newquery;

3790 }

3791

3793 MUTATE(query->withCheckOptions, query->withCheckOptions, List *);

3803

3804

3805

3806

3807

3808

3809

3811 {

3816 }

3817 else

3818 {

3819

3820

3821

3822

3823 List *resultlist;

3825

3826 resultlist = NIL;

3828 {

3831

3835

3836 resultlist = lappend(resultlist, (Node *) newnode);

3837 }

3839 }

3840

3841

3842

3843

3844

3845

3846

3847

3848

3849

3850

3851

3852

3855 else

3858 mutator, context, flags);

3859 return query;

3860}

3861

3862

3863

3864

3865

3866

3870 void *context,

3871 int flags)

3872{

3875

3876 foreach(rt, rtable)

3877 {

3880

3883 {

3887

3888 break;

3892 else

3893 {

3894

3896 }

3897 break;

3900 MUTATE(newrte->joinaliasvars, rte->joinaliasvars, List *);

3901 else

3902 {

3903

3904 newrte->joinaliasvars = copyObject(rte->joinaliasvars);

3905 }

3906 break;

3909 break;

3912 break;

3915 break;

3919

3920 break;

3923 MUTATE(newrte->groupexprs, rte->groupexprs, List *);

3924 else

3925 {

3926

3927 newrte->groupexprs = copyObject(rte->groupexprs);

3928 }

3929 break;

3930 }

3931 MUTATE(newrte->securityQuals, rte->securityQuals, List *);

3932 newrt = lappend(newrt, newrte);

3933 }

3934 return newrt;

3935}

3936

3937

3938

3939

3940

3941

3942

3943

3944

3945bool

3948 void *context,

3949 int flags)

3950{

3951 if (node && IsA(node, Query))

3953 walker,

3954 context,

3955 flags);

3956 else

3957 return WALK(node);

3958}

3959

3960

3961

3962

3963

3964

3965

3966

3967

3971 void *context,

3972 int flags)

3973{

3974 if (node && IsA(node, Query))

3976 mutator,

3977 context,

3978 flags);

3979 else

3980 return mutator(node, context);

3981}

3982

3983

3984

3985

3986

3987

3988

3989

3990

3991

3992

3993

3994

3995

3996

3997

3998

3999bool

4002 void *context)

4003{

4005

4006

4007

4008

4009

4010 if (node == NULL)

4011 return false;

4012

4013

4015

4017 {

4018 case T_JsonFormat:

4019 case T_SetToDefault:

4020 case T_CurrentOfExpr:

4021 case T_SQLValueFunction:

4022 case T_Integer:

4023 case T_Float:

4024 case T_Boolean:

4025 case T_String:

4026 case T_BitString:

4027 case T_ParamRef:

4028 case T_A_Const:

4029 case T_A_Star:

4030 case T_MergeSupportFunc:

4031 case T_ReturningOption:

4032

4033 break;

4034 case T_Alias:

4035

4036 break;

4037 case T_RangeVar:

4039 case T_GroupingFunc:

4041 case T_SubLink:

4042 {

4044

4046 return true;

4047

4049 return true;

4050 }

4051 break;

4052 case T_CaseExpr:

4053 {

4055

4056 if (WALK(caseexpr->arg))

4057 return true;

4058

4059 foreach(temp, caseexpr->args)

4060 {

4062

4064 return true;

4066 return true;

4067 }

4069 return true;

4070 }

4071 break;

4072 case T_RowExpr:

4073

4075 case T_CoalesceExpr:

4077 case T_MinMaxExpr:

4079 case T_XmlExpr:

4080 {

4082

4084 return true;

4085

4087 return true;

4088 }

4089 break;

4090 case T_JsonReturning:

4092 case T_JsonValueExpr:

4093 {

4095

4097 return true;

4099 return true;

4101 return true;

4102 }

4103 break;

4104 case T_JsonParseExpr:

4105 {

4107

4109 return true;

4111 return true;

4112 }

4113 break;

4114 case T_JsonScalarExpr:

4115 {

4117

4119 return true;

4121 return true;

4122 }

4123 break;

4124 case T_JsonSerializeExpr:

4125 {

4127

4129 return true;

4131 return true;

4132 }

4133 break;

4134 case T_JsonConstructorExpr:

4135 {

4137

4139 return true;

4141 return true;

4143 return true;

4145 return true;

4146 }

4147 break;

4148 case T_JsonIsPredicate:

4150 case T_JsonArgument:

4152 case T_JsonFuncExpr:

4153 {

4155

4157 return true;

4159 return true;

4161 return true;

4163 return true;

4165 return true;

4167 return true;

4168 }

4169 break;

4170 case T_JsonBehavior:

4171 {

4173

4175 return true;

4176 }

4177 break;

4178 case T_JsonTable:

4179 {

4181

4183 return true;

4185 return true;

4187 return true;

4189 return true;

4191 return true;

4192 }

4193 break;

4194 case T_JsonTableColumn:

4195 {

4197

4199 return true;

4201 return true;

4203 return true;

4205 return true;

4206 }

4207 break;

4208 case T_JsonTablePathSpec:

4210 case T_NullTest:

4212 case T_BooleanTest:

4214 case T_JoinExpr:

4215 {

4217

4219 return true;

4221 return true;

4223 return true;

4224 if (WALK(join->alias))

4225 return true;

4226

4227 }

4228 break;

4229 case T_IntoClause:

4230 {

4232

4234 return true;

4235

4236

4237 if (WALK(into->viewQuery))

4238 return true;

4239 }

4240 break;

4241 case T_List:

4242 foreach(temp, (List *) node)

4243 {

4245 return true;

4246 }

4247 break;

4248 case T_InsertStmt:

4249 {

4251

4253 return true;

4255 return true;

4257 return true;

4258 if (WALK(stmt->onConflictClause))

4259 return true;

4260 if (WALK(stmt->returningClause))

4261 return true;

4263 return true;

4264 }

4265 break;

4266 case T_DeleteStmt:

4267 {

4269

4271 return true;

4272 if (WALK(stmt->usingClause))

4273 return true;

4274 if (WALK(stmt->whereClause))

4275 return true;

4276 if (WALK(stmt->returningClause))

4277 return true;

4279 return true;

4280 }

4281 break;

4282 case T_UpdateStmt:

4283 {

4285

4287 return true;

4289 return true;

4290 if (WALK(stmt->whereClause))

4291 return true;

4293 return true;

4294 if (WALK(stmt->returningClause))

4295 return true;

4297 return true;

4298 }

4299 break;

4300 case T_MergeStmt:

4301 {

4303

4305 return true;

4306 if (WALK(stmt->sourceRelation))

4307 return true;

4308 if (WALK(stmt->joinCondition))

4309 return true;

4310 if (WALK(stmt->mergeWhenClauses))

4311 return true;

4312 if (WALK(stmt->returningClause))

4313 return true;

4315 return true;

4316 }

4317 break;

4318 case T_MergeWhenClause:

4319 {

4321

4323 return true;

4325 return true;

4327 return true;

4328 }

4329 break;

4330 case T_ReturningClause:

4331 {

4333

4335 return true;

4337 return true;

4338 }

4339 break;

4340 case T_SelectStmt:

4341 {

4343

4344 if (WALK(stmt->distinctClause))

4345 return true;

4347 return true;

4349 return true;

4351 return true;

4352 if (WALK(stmt->whereClause))

4353 return true;

4354 if (WALK(stmt->groupClause))

4355 return true;

4356 if (WALK(stmt->havingClause))

4357 return true;

4358 if (WALK(stmt->windowClause))

4359 return true;

4360 if (WALK(stmt->valuesLists))

4361 return true;

4363 return true;

4364 if (WALK(stmt->limitOffset))

4365 return true;

4367 return true;

4368 if (WALK(stmt->lockingClause))

4369 return true;

4371 return true;

4373 return true;

4375 return true;

4376 }

4377 break;

4378 case T_PLAssignStmt:

4379 {

4381

4382 if (WALK(stmt->indirection))

4383 return true;

4385 return true;

4386 }

4387 break;

4388 case T_A_Expr:

4389 {

4391

4393 return true;

4395 return true;

4396

4397 }

4398 break;

4399 case T_BoolExpr:

4400 {

4402

4404 return true;

4405 }

4406 break;

4407 case T_ColumnRef:

4408

4409 break;

4410 case T_FuncCall:

4411 {

4413

4415 return true;

4417 return true;

4419 return true;

4421 return true;

4422

4423 }

4424 break;

4425 case T_NamedArgExpr:

4427 case T_A_Indices:

4428 {

4430

4432 return true;

4434 return true;

4435 }

4436 break;

4437 case T_A_Indirection:

4438 {

4440

4442 return true;

4444 return true;

4445 }

4446 break;

4447 case T_A_ArrayExpr:

4449 case T_ResTarget:

4450 {

4452

4454 return true;

4456 return true;

4457 }

4458 break;

4459 case T_MultiAssignRef:

4461 case T_TypeCast:

4462 {

4464

4466 return true;

4468 return true;

4469 }

4470 break;

4471 case T_CollateClause:

4473 case T_SortBy:

4474 return WALK(((SortBy *) node)->node);

4475 case T_WindowDef:

4476 {

4478

4480 return true;

4482 return true;

4484 return true;

4486 return true;

4487 }

4488 break;

4489 case T_RangeSubselect:

4490 {

4492

4494 return true;

4496 return true;

4497 }

4498 break;

4499 case T_RangeFunction:

4500 {

4502

4504 return true;

4506 return true;

4508 return true;

4509 }

4510 break;

4511 case T_RangeTableSample:

4512 {

4514

4516 return true;

4517

4519 return true;

4521 return true;

4522 }

4523 break;

4524 case T_RangeTableFunc:

4525 {

4527

4529 return true;

4531 return true;

4533 return true;

4535 return true;

4537 return true;

4538 }

4539 break;

4540 case T_RangeTableFuncCol:

4541 {

4543

4545 return true;

4547 return true;

4548 }

4549 break;

4550 case T_TypeName:

4551 {

4553

4555 return true;

4557 return true;

4558

4559 }

4560 break;

4561 case T_ColumnDef:

4562 {

4564

4566 return true;

4568 return true;

4570 return true;

4571

4572 }

4573 break;

4574 case T_IndexElem:

4575 {

4577

4579 return true;

4580

4581 }

4582 break;

4583 case T_GroupingSet:

4585 case T_LockingClause:

4587 case T_XmlSerialize:

4588 {

4590

4592 return true;

4594 return true;

4595 }

4596 break;

4597 case T_WithClause:

4599 case T_InferClause:

4600 {

4602

4604 return true;

4605 if (WALK(stmt->whereClause))

4606 return true;

4607 }

4608 break;

4609 case T_OnConflictClause:

4610 {

4612

4614 return true;

4616 return true;

4617 if (WALK(stmt->whereClause))

4618 return true;

4619 }

4620 break;

4621 case T_CommonTableExpr:

4622

4624 case T_JsonOutput:

4625 {

4627

4629 return true;

4631 return true;

4632 }

4633 break;

4634 case T_JsonKeyValue:

4635 {

4637

4639 return true;

4641 return true;

4642 }

4643 break;

4644 case T_JsonObjectConstructor:

4645 {

4647

4649 return true;

4651 return true;

4652 }

4653 break;

4654 case T_JsonArrayConstructor:

4655 {

4657

4659 return true;

4661 return true;

4662 }

4663 break;

4664 case T_JsonAggConstructor:

4665 {

4667

4669 return true;

4671 return true;

4673 return true;

4675 return true;

4676 }

4677 break;

4678 case T_JsonObjectAgg:

4679 {

4681

4683 return true;

4685 return true;

4686 }

4687 break;

4688 case T_JsonArrayAgg:

4689 {

4691

4693 return true;

4695 return true;

4696 }

4697 break;

4698 case T_JsonArrayQueryConstructor:

4699 {

4701

4703 return true;

4705 return true;

4706 }

4707 break;

4708 default:

4709 elog(ERROR, "unrecognized node type: %d",

4711 break;

4712 }

4713 return false;

4714}

4715

4716

4717

4718

4719

4720

4721

4722bool

4725 void *context)

4726{

4729

4730

4731#define PSWALK(n) walker(n, context)

4732

4733

4735

4736

4738 return true;

4739

4740

4742 {

4744 return true;

4745 }

4746

4747

4749 {

4751 return true;

4752 }

4753

4754

4756 {

4757 case T_Append:

4760 walker, context))

4761 return true;

4762 break;

4763 case T_MergeAppend:

4766 walker, context))

4767 return true;

4768 break;

4769 case T_BitmapAnd:

4772 walker, context))

4773 return true;

4774 break;

4775 case T_BitmapOr:

4778 walker, context))

4779 return true;

4780 break;

4781 case T_SubqueryScan:

4783 return true;

4784 break;

4785 case T_CustomScan:

4787 {

4789 return true;

4790 }

4791 break;

4792 default:

4793 break;

4794 }

4795

4796

4798 return true;

4799

4800 return false;

4801}

4802

4803

4804

4805

4806static bool

4809 void *context)

4810{

4812

4813 foreach(lc, plans)

4814 {

4816

4818 return true;

4819 }

4820

4821 return false;

4822}

4823

4824

4825

4826

4827

4828static bool

4831 void *context)

4832{

4833 int j;

4834

4835 for (j = 0; j < nplans; j++)

4836 {

4837 if (PSWALK(planstates[j]))

4838 return true;

4839 }

4840

4841 return false;

4842}

#define OidIsValid(objectId)

int errcode(int sqlerrcode)

int errmsg(const char *fmt,...)

#define ereport(elevel,...)

#define outerPlanState(node)

#define innerPlanState(node)

char * format_type_be(Oid type_oid)

Assert(PointerIsAligned(start, uint64))

if(TABLE==NULL||TABLE_index==NULL)

List * lappend(List *list, void *datum)

List * list_copy(const List *oldlist)

void getTypeOutputInfo(Oid type, Oid *typOutput, bool *typIsVarlena)

RegProcedure get_opcode(Oid opno)

void getTypeInputInfo(Oid type, Oid *typInput, Oid *typIOParam)

Oid get_promoted_array_type(Oid typid)

bool query_tree_walker_impl(Query *query, tree_walker_callback walker, void *context, int flags)

#define FLATCOPY(newnode, node, nodetype)

bool raw_expression_tree_walker_impl(Node *node, tree_walker_callback walker, void *context)

Oid exprType(const Node *expr)

bool range_table_entry_walker_impl(RangeTblEntry *rte, tree_walker_callback walker, void *context, int flags)

bool exprIsLengthCoercion(const Node *expr, int32 *coercedTypmod)

void exprSetCollation(Node *expr, Oid collation)

Oid exprInputCollation(const Node *expr)

int32 exprTypmod(const Node *expr)

static bool planstate_walk_subplans(List *plans, planstate_tree_walker_callback walker, void *context)

bool check_functions_in_node(Node *node, check_function_callback checker, void *context)

Oid exprCollation(const Node *expr)

static bool fix_opfuncids_walker(Node *node, void *context)

void exprSetInputCollation(Node *expr, Oid inputcollation)

bool query_or_expression_tree_walker_impl(Node *node, tree_walker_callback walker, void *context, int flags)

bool expression_tree_walker_impl(Node *node, tree_walker_callback walker, void *context)

bool range_table_walker_impl(List *rtable, tree_walker_callback walker, void *context, int flags)

Node * query_or_expression_tree_mutator_impl(Node *node, tree_mutator_callback mutator, void *context, int flags)

Query * query_tree_mutator_impl(Query *query, tree_mutator_callback mutator, void *context, int flags)

#define MUTATE(newfield, oldfield, fieldtype)

Node * applyRelabelType(Node *arg, Oid rtype, int32 rtypmod, Oid rcollid, CoercionForm rformat, int rlocation, bool overwrite_ok)

static int leftmostLoc(int loc1, int loc2)

Node * strip_implicit_coercions(Node *node)

int exprLocation(const Node *expr)

List * range_table_mutator_impl(List *rtable, tree_mutator_callback mutator, void *context, int flags)

bool expression_returns_set(Node *clause)

bool planstate_tree_walker_impl(PlanState *planstate, planstate_tree_walker_callback walker, void *context)

void fix_opfuncids(Node *node)

Node * expression_tree_mutator_impl(Node *node, tree_mutator_callback mutator, void *context)

Node * relabel_to_typmod(Node *expr, int32 typmod)

static bool expression_returns_set_walker(Node *node, void *context)

void set_sa_opfuncid(ScalarArrayOpExpr *opexpr)

static bool planstate_walk_members(PlanState **planstates, int nplans, planstate_tree_walker_callback walker, void *context)

void set_opfuncid(OpExpr *opexpr)

Node *(* tree_mutator_callback)(Node *node, void *context)

#define QTW_DONT_COPY_QUERY

#define QTW_IGNORE_CTE_SUBQUERIES

#define QTW_IGNORE_RT_SUBQUERIES

#define range_table_walker(rt, w, c, f)

bool(* planstate_tree_walker_callback)(struct PlanState *planstate, void *context)

#define query_tree_walker(q, w, c, f)

#define range_table_entry_walker(r, w, c, f)

#define QTW_EXAMINE_RTES_AFTER

#define QTW_EXAMINE_SORTGROUP

bool(* tree_walker_callback)(Node *node, void *context)

#define QTW_IGNORE_GROUPEXPRS

#define expression_tree_walker(n, w, c)

#define query_tree_mutator(q, m, c, f)

bool(* check_function_callback)(Oid func_id, void *context)

#define QTW_EXAMINE_RTES_BEFORE

#define range_table_mutator(rt, m, c, f)

#define QTW_IGNORE_RANGE_TABLE

#define QTW_IGNORE_JOINALIASES

#define IsA(nodeptr, _type_)

#define lfirst_node(type, lc)

static int list_length(const List *l)

#define linitial_node(type, l)

#define for_each_from(cell, lst, N)

static rewind_source * source

static int32 DatumGetInt32(Datum X)

static int fc(const char *x)

void check_stack_depth(void)

Node * cycle_mark_default

CollateClause * collClause

struct RestrictInfo * rinfo

JsonAggConstructor * constructor

JsonReturning * returning

JsonReturning * returning

JsonValueExpr * context_item

JsonAggConstructor * constructor

JsonReturning * returning

JsonTablePathSpec * pathspec

JsonValueExpr * context_item

Node * mergeJoinCondition

OnConflictExpr * onConflict

struct TableSampleClause * tablesample

struct PlanState * planstate