| 1 | /*------------------------------------------------------------------------- |
| 2 | * |
| 3 | * nodes.h |
| 4 | * Definitions for tagged nodes. |
| 5 | * |
| 6 | * |
| 7 | * Portions Copyright (c) 1996-2017, PostgreSQL Global Development PGGroup |
| 8 | * Portions Copyright (c) 1994, Regents of the University of California |
| 9 | * |
| 10 | * src/include/nodes/nodes.h |
| 11 | * |
| 12 | *------------------------------------------------------------------------- |
| 13 | */ |
| 14 | #pragma once |
| 15 | |
| 16 | #include "pg_definitions.hpp" |
| 17 | |
| 18 | /* |
| 19 | * The first field of every node is NodeTag. Each node created (with makeNode) |
| 20 | * will have one of the following tags as the value of its first field. |
| 21 | * |
| 22 | * Note that inserting or deleting node types changes the numbers of other |
| 23 | * node types later in the list. This is no problem during development, since |
| 24 | * the node numbers are never stored on disk. But don't do it in a released |
| 25 | * branch, because that would represent an ABI break for extensions. |
| 26 | */ |
| 27 | typedef enum PGNodeTag |
| 28 | { |
| 29 | T_PGInvalid = 0, |
| 30 | |
| 31 | /* |
| 32 | * TAGS FOR EXECUTOR NODES (execnodes.h) |
| 33 | */ |
| 34 | T_PGIndexInfo, |
| 35 | T_PGExprContext, |
| 36 | T_PGProjectionInfo, |
| 37 | T_PGJunkFilter, |
| 38 | T_PGResultRelInfo, |
| 39 | T_PGEState, |
| 40 | T_PGTupleTableSlot, |
| 41 | |
| 42 | /* |
| 43 | * TAGS FOR PLAN NODES (plannodes.h) |
| 44 | */ |
| 45 | T_PGPlan, |
| 46 | T_PGResult, |
| 47 | T_PGProjectSet, |
| 48 | T_PGModifyTable, |
| 49 | T_PGAppend, |
| 50 | T_PGMergeAppend, |
| 51 | T_PGRecursiveUnion, |
| 52 | T_PGBitmapAnd, |
| 53 | T_PGBitmapOr, |
| 54 | T_PGScan, |
| 55 | T_PGSeqScan, |
| 56 | T_PGSampleScan, |
| 57 | T_PGIndexScan, |
| 58 | T_PGIndexOnlyScan, |
| 59 | T_PGBitmapIndexScan, |
| 60 | T_PGBitmapHeapScan, |
| 61 | T_PGTidScan, |
| 62 | T_PGSubqueryScan, |
| 63 | T_PGFunctionScan, |
| 64 | T_PGValuesScan, |
| 65 | T_PGTableFuncScan, |
| 66 | T_PGCteScan, |
| 67 | T_PGNamedTuplestoreScan, |
| 68 | T_PGWorkTableScan, |
| 69 | T_PGForeignScan, |
| 70 | T_PGCustomScan, |
| 71 | T_PGJoin, |
| 72 | T_PGNestLoop, |
| 73 | T_PGMergeJoin, |
| 74 | T_PGHashJoin, |
| 75 | T_PGMaterial, |
| 76 | T_PGSort, |
| 77 | T_PGGroup, |
| 78 | T_PGAgg, |
| 79 | T_PGWindowAgg, |
| 80 | T_PGUnique, |
| 81 | T_PGGather, |
| 82 | T_PGGatherMerge, |
| 83 | T_PGHash, |
| 84 | T_PGSetOp, |
| 85 | T_PGLockRows, |
| 86 | T_PGLimit, |
| 87 | /* these aren't subclasses of PGPlan: */ |
| 88 | T_PGNestLoopParam, |
| 89 | T_PGPlanRowMark, |
| 90 | T_PGPlanInvalItem, |
| 91 | |
| 92 | /* |
| 93 | * TAGS FOR PLAN STATE NODES (execnodes.h) |
| 94 | * |
| 95 | * These should correspond one-to-one with PGPlan node types. |
| 96 | */ |
| 97 | T_PGPlanState, |
| 98 | T_PGResultState, |
| 99 | T_PGProjectSetState, |
| 100 | T_PGModifyTableState, |
| 101 | T_PGAppendState, |
| 102 | T_PGMergeAppendState, |
| 103 | T_PGRecursiveUnionState, |
| 104 | T_PGBitmapAndState, |
| 105 | T_PGBitmapOrState, |
| 106 | T_PGScanState, |
| 107 | T_PGSeqScanState, |
| 108 | T_PGSampleScanState, |
| 109 | T_PGIndexScanState, |
| 110 | T_PGIndexOnlyScanState, |
| 111 | T_PGBitmapIndexScanState, |
| 112 | T_PGBitmapHeapScanState, |
| 113 | T_PGTidScanState, |
| 114 | T_PGSubqueryScanState, |
| 115 | T_PGFunctionScanState, |
| 116 | T_PGTableFuncScanState, |
| 117 | T_PGValuesScanState, |
| 118 | T_PGCteScanState, |
| 119 | T_PGNamedTuplestoreScanState, |
| 120 | T_PGWorkTableScanState, |
| 121 | T_PGForeignScanState, |
| 122 | T_PGCustomScanState, |
| 123 | T_PGJoinState, |
| 124 | T_PGNestLoopState, |
| 125 | T_PGMergeJoinState, |
| 126 | T_PGHashJoinState, |
| 127 | T_PGMaterialState, |
| 128 | T_PGSortState, |
| 129 | T_PGGroupState, |
| 130 | T_PGAggState, |
| 131 | T_PGWindowAggState, |
| 132 | T_PGUniqueState, |
| 133 | T_PGGatherState, |
| 134 | T_PGGatherMergeState, |
| 135 | T_PGHashState, |
| 136 | T_PGSetOpState, |
| 137 | T_PGLockRowsState, |
| 138 | T_PGLimitState, |
| 139 | |
| 140 | /* |
| 141 | * TAGS FOR PRIMITIVE NODES (primnodes.h) |
| 142 | */ |
| 143 | T_PGAlias, |
| 144 | T_PGRangeVar, |
| 145 | T_PGTableFunc, |
| 146 | T_PGExpr, |
| 147 | T_PGVar, |
| 148 | T_PGConst, |
| 149 | T_PGParam, |
| 150 | T_PGAggref, |
| 151 | T_PGGroupingFunc, |
| 152 | T_PGWindowFunc, |
| 153 | T_PGArrayRef, |
| 154 | T_PGFuncExpr, |
| 155 | T_PGNamedArgExpr, |
| 156 | T_PGOpExpr, |
| 157 | T_PGDistinctExpr, |
| 158 | T_PGNullIfExpr, |
| 159 | T_PGScalarArrayOpExpr, |
| 160 | T_PGBoolExpr, |
| 161 | T_PGSubLink, |
| 162 | T_PGSubPlan, |
| 163 | T_PGAlternativeSubPlan, |
| 164 | T_PGFieldSelect, |
| 165 | T_PGFieldStore, |
| 166 | T_PGRelabelType, |
| 167 | T_PGCoerceViaIO, |
| 168 | T_PGArrayCoerceExpr, |
| 169 | T_PGConvertRowtypeExpr, |
| 170 | T_PGCollateExpr, |
| 171 | T_PGCaseExpr, |
| 172 | T_PGCaseWhen, |
| 173 | T_PGCaseTestExpr, |
| 174 | T_PGArrayExpr, |
| 175 | T_PGRowExpr, |
| 176 | T_PGRowCompareExpr, |
| 177 | T_PGCoalesceExpr, |
| 178 | T_PGMinMaxExpr, |
| 179 | T_PGSQLValueFunction, |
| 180 | T_PGXmlExpr, |
| 181 | T_PGNullTest, |
| 182 | T_PGBooleanTest, |
| 183 | T_PGCoerceToDomain, |
| 184 | T_PGCoerceToDomainValue, |
| 185 | T_PGSetToDefault, |
| 186 | T_PGCurrentOfExpr, |
| 187 | T_PGNextValueExpr, |
| 188 | T_PGInferenceElem, |
| 189 | T_PGTargetEntry, |
| 190 | T_PGRangeTblRef, |
| 191 | T_PGJoinExpr, |
| 192 | T_PGFromExpr, |
| 193 | T_PGOnConflictExpr, |
| 194 | T_PGIntoClause, |
| 195 | |
| 196 | /* |
| 197 | * TAGS FOR EXPRESSION STATE NODES (execnodes.h) |
| 198 | * |
| 199 | * ExprState represents the evaluation state for a whole expression tree. |
| 200 | * Most Expr-based plan nodes do not have a corresponding expression state |
| 201 | * node, they're fully handled within execExpr* - but sometimes the state |
| 202 | * needs to be shared with other parts of the executor, as for example |
| 203 | * with AggrefExprState, which nodeAgg.c has to modify. |
| 204 | */ |
| 205 | T_PGExprState, |
| 206 | T_PGAggrefExprState, |
| 207 | T_PGWindowFuncExprState, |
| 208 | T_PGSetExprState, |
| 209 | T_PGSubPlanState, |
| 210 | T_PGAlternativeSubPlanState, |
| 211 | T_PGDomainConstraintState, |
| 212 | |
| 213 | /* |
| 214 | * TAGS FOR PLANNER NODES (relation.h) |
| 215 | */ |
| 216 | T_PGPlannerInfo, |
| 217 | T_PGPlannerGlobal, |
| 218 | T_PGRelOptInfo, |
| 219 | T_PGIndexOptInfo, |
| 220 | T_PGForeignKeyOptInfo, |
| 221 | T_PGParamPathInfo, |
| 222 | T_PGPath, |
| 223 | T_PGIndexPath, |
| 224 | T_PGBitmapHeapPath, |
| 225 | T_PGBitmapAndPath, |
| 226 | T_PGBitmapOrPath, |
| 227 | T_PGTidPath, |
| 228 | T_PGSubqueryScanPath, |
| 229 | T_PGForeignPath, |
| 230 | T_PGCustomPath, |
| 231 | T_PGNestPath, |
| 232 | T_PGMergePath, |
| 233 | T_PGHashPath, |
| 234 | T_PGAppendPath, |
| 235 | T_PGMergeAppendPath, |
| 236 | T_PGResultPath, |
| 237 | T_PGMaterialPath, |
| 238 | T_PGUniquePath, |
| 239 | T_PGGatherPath, |
| 240 | T_PGGatherMergePath, |
| 241 | T_PGProjectionPath, |
| 242 | T_PGProjectSetPath, |
| 243 | T_PGSortPath, |
| 244 | T_PGGroupPath, |
| 245 | T_PGUpperUniquePath, |
| 246 | T_PGAggPath, |
| 247 | T_PGGroupingSetsPath, |
| 248 | T_PGMinMaxAggPath, |
| 249 | T_PGWindowAggPath, |
| 250 | T_PGSetOpPath, |
| 251 | T_PGRecursiveUnionPath, |
| 252 | T_PGLockRowsPath, |
| 253 | T_PGModifyTablePath, |
| 254 | T_PGLimitPath, |
| 255 | /* these aren't subclasses of Path: */ |
| 256 | T_PGEquivalenceClass, |
| 257 | T_PGEquivalenceMember, |
| 258 | T_PGPathKey, |
| 259 | T_PGPathTarget, |
| 260 | T_PGRestrictInfo, |
| 261 | T_PGPlaceHolderVar, |
| 262 | T_PGSpecialJoinInfo, |
| 263 | T_PGAppendRelInfo, |
| 264 | T_PGPartitionedChildRelInfo, |
| 265 | T_PGPlaceHolderInfo, |
| 266 | T_PGMinMaxAggInfo, |
| 267 | T_PGPlannerParamItem, |
| 268 | T_PGRollupData, |
| 269 | T_PGGroupingSetData, |
| 270 | T_PGStatisticExtInfo, |
| 271 | |
| 272 | /* |
| 273 | * TAGS FOR MEMORY NODES (memnodes.h) |
| 274 | */ |
| 275 | T_PGMemoryContext, |
| 276 | T_PGAllocSetContext, |
| 277 | T_PGSlabContext, |
| 278 | |
| 279 | /* |
| 280 | * TAGS FOR VALUE NODES (value.h) |
| 281 | */ |
| 282 | T_PGValue, |
| 283 | T_PGInteger, |
| 284 | T_PGFloat, |
| 285 | T_PGString, |
| 286 | T_PGBitString, |
| 287 | T_PGNull, |
| 288 | |
| 289 | /* |
| 290 | * TAGS FOR LIST NODES (pg_list.h) |
| 291 | */ |
| 292 | T_PGList, |
| 293 | T_PGIntList, |
| 294 | T_PGOidList, |
| 295 | |
| 296 | /* |
| 297 | * TAGS FOR EXTENSIBLE NODES (extensible.h) |
| 298 | */ |
| 299 | T_PGExtensibleNode, |
| 300 | |
| 301 | /* |
| 302 | * TAGS FOR STATEMENT NODES (mostly in parsenodes.h) |
| 303 | */ |
| 304 | T_PGRawStmt, |
| 305 | T_PGQuery, |
| 306 | T_PGPlannedStmt, |
| 307 | T_PGInsertStmt, |
| 308 | T_PGDeleteStmt, |
| 309 | T_PGUpdateStmt, |
| 310 | T_PGSelectStmt, |
| 311 | T_PGAlterTableStmt, |
| 312 | T_PGAlterTableCmd, |
| 313 | T_PGAlterDomainStmt, |
| 314 | T_PGSetOperationStmt, |
| 315 | T_PGGrantStmt, |
| 316 | T_PGGrantRoleStmt, |
| 317 | T_PGAlterDefaultPrivilegesStmt, |
| 318 | T_PGClosePortalStmt, |
| 319 | T_PGClusterStmt, |
| 320 | T_PGCopyStmt, |
| 321 | T_PGCreateStmt, |
| 322 | T_PGDefineStmt, |
| 323 | T_PGDropStmt, |
| 324 | T_PGTruncateStmt, |
| 325 | , |
| 326 | T_PGFetchStmt, |
| 327 | T_PGIndexStmt, |
| 328 | T_PGCreateFunctionStmt, |
| 329 | T_PGAlterFunctionStmt, |
| 330 | T_PGDoStmt, |
| 331 | T_PGRenameStmt, |
| 332 | T_PGRuleStmt, |
| 333 | T_PGNotifyStmt, |
| 334 | T_PGListenStmt, |
| 335 | T_PGUnlistenStmt, |
| 336 | T_PGTransactionStmt, |
| 337 | T_PGViewStmt, |
| 338 | T_PGLoadStmt, |
| 339 | T_PGCreateDomainStmt, |
| 340 | T_PGCreatedbStmt, |
| 341 | T_PGDropdbStmt, |
| 342 | T_PGVacuumStmt, |
| 343 | T_PGExplainStmt, |
| 344 | T_PGCreateTableAsStmt, |
| 345 | T_PGCreateSeqStmt, |
| 346 | T_PGAlterSeqStmt, |
| 347 | T_PGVariableSetStmt, |
| 348 | T_PGVariableShowStmt, |
| 349 | T_PGDiscardStmt, |
| 350 | T_PGCreateTrigStmt, |
| 351 | T_PGCreatePLangStmt, |
| 352 | T_PGCreateRoleStmt, |
| 353 | T_PGAlterRoleStmt, |
| 354 | T_PGDropRoleStmt, |
| 355 | T_PGLockStmt, |
| 356 | T_PGConstraintsSetStmt, |
| 357 | T_PGReindexStmt, |
| 358 | T_PGCheckPointStmt, |
| 359 | T_PGCreateSchemaStmt, |
| 360 | T_PGAlterDatabaseStmt, |
| 361 | T_PGAlterDatabaseSetStmt, |
| 362 | T_PGAlterRoleSetStmt, |
| 363 | T_PGCreateConversionStmt, |
| 364 | T_PGCreateCastStmt, |
| 365 | T_PGCreateOpClassStmt, |
| 366 | T_PGCreateOpFamilyStmt, |
| 367 | T_PGAlterOpFamilyStmt, |
| 368 | T_PGPrepareStmt, |
| 369 | T_PGExecuteStmt, |
| 370 | T_PGDeallocateStmt, |
| 371 | T_PGDeclareCursorStmt, |
| 372 | T_PGCreateTableSpaceStmt, |
| 373 | T_PGDropTableSpaceStmt, |
| 374 | T_PGAlterObjectDependsStmt, |
| 375 | T_PGAlterObjectSchemaStmt, |
| 376 | T_PGAlterOwnerStmt, |
| 377 | T_PGAlterOperatorStmt, |
| 378 | T_PGDropOwnedStmt, |
| 379 | T_PGReassignOwnedStmt, |
| 380 | T_PGCompositeTypeStmt, |
| 381 | T_PGCreateEnumStmt, |
| 382 | T_PGCreateRangeStmt, |
| 383 | T_PGAlterEnumStmt, |
| 384 | T_PGAlterTSDictionaryStmt, |
| 385 | T_PGAlterTSConfigurationStmt, |
| 386 | T_PGCreateFdwStmt, |
| 387 | T_PGAlterFdwStmt, |
| 388 | T_PGCreateForeignServerStmt, |
| 389 | T_PGAlterForeignServerStmt, |
| 390 | T_PGCreateUserMappingStmt, |
| 391 | T_PGAlterUserMappingStmt, |
| 392 | T_PGDropUserMappingStmt, |
| 393 | T_PGAlterTableSpaceOptionsStmt, |
| 394 | T_PGAlterTableMoveAllStmt, |
| 395 | T_PGSecLabelStmt, |
| 396 | T_PGCreateForeignTableStmt, |
| 397 | T_PGImportForeignSchemaStmt, |
| 398 | T_PGCreateExtensionStmt, |
| 399 | T_PGAlterExtensionStmt, |
| 400 | T_PGAlterExtensionContentsStmt, |
| 401 | T_PGCreateEventTrigStmt, |
| 402 | T_PGAlterEventTrigStmt, |
| 403 | T_PGRefreshMatViewStmt, |
| 404 | T_PGReplicaIdentityStmt, |
| 405 | T_PGAlterSystemStmt, |
| 406 | T_PGCreatePolicyStmt, |
| 407 | T_PGAlterPolicyStmt, |
| 408 | T_PGCreateTransformStmt, |
| 409 | T_PGCreateAmStmt, |
| 410 | T_PGCreatePublicationStmt, |
| 411 | T_PGAlterPublicationStmt, |
| 412 | T_PGCreateSubscriptionStmt, |
| 413 | T_PGAlterSubscriptionStmt, |
| 414 | T_PGDropSubscriptionStmt, |
| 415 | T_PGCreateStatsStmt, |
| 416 | T_PGAlterCollationStmt, |
| 417 | T_PGPragmaStmt, |
| 418 | |
| 419 | /* |
| 420 | * TAGS FOR PARSE TREE NODES (parsenodes.h) |
| 421 | */ |
| 422 | T_PGAExpr, |
| 423 | T_PGColumnRef, |
| 424 | T_PGParamRef, |
| 425 | T_PGAConst, |
| 426 | T_PGFuncCall, |
| 427 | T_PGAStar, |
| 428 | T_PGAIndices, |
| 429 | T_PGAIndirection, |
| 430 | T_PGAArrayExpr, |
| 431 | T_PGResTarget, |
| 432 | T_PGMultiAssignRef, |
| 433 | T_PGTypeCast, |
| 434 | T_PGCollateClause, |
| 435 | T_PGSortBy, |
| 436 | T_PGWindowDef, |
| 437 | T_PGRangeSubselect, |
| 438 | T_PGRangeFunction, |
| 439 | T_PGRangeTableSample, |
| 440 | T_PGRangeTableFunc, |
| 441 | T_PGRangeTableFuncCol, |
| 442 | T_PGTypeName, |
| 443 | T_PGColumnDef, |
| 444 | T_PGIndexElem, |
| 445 | T_PGConstraint, |
| 446 | T_PGDefElem, |
| 447 | T_PGRangeTblEntry, |
| 448 | T_PGRangeTblFunction, |
| 449 | T_PGTableSampleClause, |
| 450 | T_PGWithCheckOption, |
| 451 | T_PGSortGroupClause, |
| 452 | T_PGGroupingSet, |
| 453 | T_PGWindowClause, |
| 454 | T_PGObjectWithArgs, |
| 455 | T_PGAccessPriv, |
| 456 | T_PGCreateOpClassItem, |
| 457 | T_PGTableLikeClause, |
| 458 | T_PGFunctionParameter, |
| 459 | T_PGLockingClause, |
| 460 | T_PGRowMarkClause, |
| 461 | T_PGXmlSerialize, |
| 462 | T_PGWithClause, |
| 463 | T_PGInferClause, |
| 464 | T_PGOnConflictClause, |
| 465 | T_PGCommonTableExpr, |
| 466 | T_PGRoleSpec, |
| 467 | T_PGTriggerTransition, |
| 468 | T_PGPartitionElem, |
| 469 | T_PGPartitionSpec, |
| 470 | T_PGPartitionBoundSpec, |
| 471 | T_PGPartitionRangeDatum, |
| 472 | T_PGPartitionCmd, |
| 473 | |
| 474 | /* |
| 475 | * TAGS FOR REPLICATION GRAMMAR PARSE NODES (replnodes.h) |
| 476 | */ |
| 477 | T_PGIdentifySystemCmd, |
| 478 | T_PGBaseBackupCmd, |
| 479 | T_PGCreateReplicationSlotCmd, |
| 480 | T_PGDropReplicationSlotCmd, |
| 481 | T_PGStartReplicationCmd, |
| 482 | T_PGTimeLineHistoryCmd, |
| 483 | T_PGSQLCmd, |
| 484 | |
| 485 | /* |
| 486 | * TAGS FOR RANDOM OTHER STUFF |
| 487 | * |
| 488 | * These are objects that aren't part of parse/plan/execute node tree |
| 489 | * structures, but we give them NodeTags anyway for identification |
| 490 | * purposes (usually because they are involved in APIs where we want to |
| 491 | * pass multiple object types through the same pointer). |
| 492 | */ |
| 493 | T_PGTriggerData, /* in commands/trigger.h */ |
| 494 | T_PGEventTriggerData, /* in commands/event_trigger.h */ |
| 495 | T_PGReturnSetInfo, /* in nodes/execnodes.h */ |
| 496 | T_PGWindowObjectData, /* private in nodeWindowAgg.c */ |
| 497 | T_PGTIDBitmap, /* in nodes/tidbitmap.h */ |
| 498 | T_PGInlineCodeBlock, /* in nodes/parsenodes.h */ |
| 499 | T_PGFdwRoutine, /* in foreign/fdwapi.h */ |
| 500 | T_PGIndexAmRoutine, /* in access/amapi.h */ |
| 501 | T_PGTsmRoutine, /* in access/tsmapi.h */ |
| 502 | T_PGForeignKeyCacheInfo /* in utils/rel.h */ |
| 503 | } PGNodeTag; |
| 504 | |
| 505 | /* |
| 506 | * The first field of a node of any type is guaranteed to be the NodeTag. |
| 507 | * Hence the type of any node can be gotten by casting it to Node. Declaring |
| 508 | * a variable to be of PGNode * (instead of void *) can also facilitate |
| 509 | * debugging. |
| 510 | */ |
| 511 | typedef struct PGNode |
| 512 | { |
| 513 | PGNodeTag type; |
| 514 | } PGNode; |
| 515 | |
| 516 | #define nodeTag(nodeptr) (((const PGNode*)(nodeptr))->type) |
| 517 | |
| 518 | /* |
| 519 | * newNode - |
| 520 | * create a new node of the specified size and tag the node with the |
| 521 | * specified tag. |
| 522 | * |
| 523 | * !WARNING!: Avoid using newNode directly. You should be using the |
| 524 | * macro makeNode. eg. to create a PGQuery node, use makeNode(PGQuery) |
| 525 | * |
| 526 | * Note: the size argument should always be a compile-time constant, so the |
| 527 | * apparent risk of multiple evaluation doesn't matter in practice. |
| 528 | */ |
| 529 | #ifdef __GNUC__ |
| 530 | |
| 531 | /* With GCC, we can use a compound statement within an expression */ |
| 532 | #define newNode(size, tag) \ |
| 533 | ({ PGNode *_result; \ |
| 534 | AssertMacro((size) >= sizeof(PGNode)); /* need the tag, at least */ \ |
| 535 | _result = (PGNode *) palloc0fast(size); \ |
| 536 | _result->type = (tag); \ |
| 537 | _result; \ |
| 538 | }) |
| 539 | #else |
| 540 | |
| 541 | /* |
| 542 | * There is no way to dereference the palloc'ed pointer to assign the |
| 543 | * tag, and also return the pointer itself, so we need a holder variable. |
| 544 | * Fortunately, this macro isn't recursive so we just define |
| 545 | * a global variable for this purpose. |
| 546 | */ |
| 547 | extern __thread PGNode *newNodeMacroHolder; |
| 548 | |
| 549 | #define newNode(size, tag) \ |
| 550 | ( \ |
| 551 | AssertMacro((size) >= sizeof(PGNode)), /* need the tag, at least */ \ |
| 552 | newNodeMacroHolder = (PGNode *) palloc0fast(size), \ |
| 553 | newNodeMacroHolder->type = (tag), \ |
| 554 | newNodeMacroHolder \ |
| 555 | ) |
| 556 | #endif /* __GNUC__ */ |
| 557 | |
| 558 | |
| 559 | #define makeNode(_type_) ((_type_ *) newNode(sizeof(_type_),T_##_type_)) |
| 560 | #define NodeSetTag(nodeptr,t) (((PGNode*)(nodeptr))->type = (t)) |
| 561 | |
| 562 | #define IsA(nodeptr,_type_) (nodeTag(nodeptr) == T_##_type_) |
| 563 | |
| 564 | /* |
| 565 | * castNode(type, ptr) casts ptr to "type *", and if assertions are enabled, |
| 566 | * verifies that the node has the appropriate type (using its nodeTag()). |
| 567 | * |
| 568 | * Use an inline function when assertions are enabled, to avoid multiple |
| 569 | * evaluations of the ptr argument (which could e.g. be a function call). |
| 570 | */ |
| 571 | #ifdef USE_ASSERT_CHECKING |
| 572 | static inline PGNode * |
| 573 | castNodeImpl(PGNodeTag type, void *ptr) |
| 574 | { |
| 575 | Assert(ptr == NULL || nodeTag(ptr) == type); |
| 576 | return (PGNode *) ptr; |
| 577 | } |
| 578 | #define castNode(_type_, nodeptr) ((_type_ *) castNodeImpl(T_##_type_, nodeptr)) |
| 579 | #else |
| 580 | #define castNode(_type_, nodeptr) ((_type_ *) (nodeptr)) |
| 581 | #endif /* USE_ASSERT_CHECKING */ |
| 582 | |
| 583 | |
| 584 | /* ---------------------------------------------------------------- |
| 585 | * extern declarations follow |
| 586 | * ---------------------------------------------------------------- |
| 587 | */ |
| 588 | |
| 589 | /* |
| 590 | * nodes/{outfuncs.c,print.c} |
| 591 | */ |
| 592 | struct PGBitmapset; /* not to include bitmapset.h here */ |
| 593 | struct PGStringInfoData; /* not to include stringinfo.h here */ |
| 594 | |
| 595 | extern void outNode(struct PGStringInfoData *str, const void *obj); |
| 596 | extern void outToken(struct PGStringInfoData *str, const char *s); |
| 597 | extern void outBitmapset(struct PGStringInfoData *str, |
| 598 | const struct PGBitmapset *bms); |
| 599 | extern void outDatum(struct PGStringInfoData *str, uintptr_t value, |
| 600 | int typlen, bool typbyval); |
| 601 | extern char *nodeToString(const void *obj); |
| 602 | extern char *bmsToString(const struct PGBitmapset *bms); |
| 603 | |
| 604 | /* |
| 605 | * nodes/{readfuncs.c,read.c} |
| 606 | */ |
| 607 | extern void *stringToNode(char *str); |
| 608 | extern struct PGBitmapset *readBitmapset(void); |
| 609 | extern uintptr_t readDatum(bool typbyval); |
| 610 | extern bool *readBoolCols(int numCols); |
| 611 | extern int *readIntCols(int numCols); |
| 612 | extern PGOid *readOidCols(int numCols); |
| 613 | extern int16_t *readAttrNumberCols(int numCols); |
| 614 | |
| 615 | /* |
| 616 | * nodes/copyfuncs.c |
| 617 | */ |
| 618 | extern void *copyObjectImpl(const void *obj); |
| 619 | |
| 620 | /* cast result back to argument type, if supported by compiler */ |
| 621 | //#ifdef HAVE_TYPEOF |
| 622 | //#define copyObject(obj) ((typeof(obj)) copyObjectImpl(obj)) |
| 623 | //#else |
| 624 | //#define copyObject(obj) copyObjectImpl(obj) |
| 625 | //#endif |
| 626 | |
| 627 | /* |
| 628 | * nodes/equalfuncs.c |
| 629 | */ |
| 630 | //extern bool equal(const void *a, const void *b); |
| 631 | |
| 632 | |
| 633 | /* |
| 634 | * Typedefs for identifying qualifier selectivities and plan costs as such. |
| 635 | * These are just plain "double"s, but declaring a variable as Selectivity |
| 636 | * or Cost makes the intent more obvious. |
| 637 | * |
| 638 | * These could have gone into plannodes.h or some such, but many files |
| 639 | * depend on them... |
| 640 | */ |
| 641 | typedef double Selectivity; /* fraction of tuples a qualifier will pass */ |
| 642 | typedef double Cost; /* execution cost (in page-access units) */ |
| 643 | |
| 644 | |
| 645 | /* |
| 646 | * PGCmdType - |
| 647 | * enums for type of operation represented by a PGQuery or PGPlannedStmt |
| 648 | * |
| 649 | * This is needed in both parsenodes.h and plannodes.h, so put it here... |
| 650 | */ |
| 651 | typedef enum PGCmdType |
| 652 | { |
| 653 | PG_CMD_UNKNOWN, |
| 654 | PG_CMD_SELECT, /* select stmt */ |
| 655 | PG_CMD_UPDATE, /* update stmt */ |
| 656 | PG_CMD_INSERT, /* insert stmt */ |
| 657 | PG_CMD_DELETE, |
| 658 | PG_CMD_UTILITY, /* cmds like create, destroy, copy, vacuum, |
| 659 | * etc. */ |
| 660 | PG_CMD_NOTHING /* dummy command for instead nothing rules |
| 661 | * with qual */ |
| 662 | } PGCmdType; |
| 663 | |
| 664 | |
| 665 | /* |
| 666 | * PGJoinType - |
| 667 | * enums for types of relation joins |
| 668 | * |
| 669 | * PGJoinType determines the exact semantics of joining two relations using |
| 670 | * a matching qualification. For example, it tells what to do with a tuple |
| 671 | * that has no match in the other relation. |
| 672 | * |
| 673 | * This is needed in both parsenodes.h and plannodes.h, so put it here... |
| 674 | */ |
| 675 | typedef enum PGJoinType |
| 676 | { |
| 677 | /* |
| 678 | * The canonical kinds of joins according to the SQL JOIN syntax. Only |
| 679 | * these codes can appear in parser output (e.g., PGJoinExpr nodes). |
| 680 | */ |
| 681 | PG_JOIN_INNER, /* matching tuple pairs only */ |
| 682 | PG_JOIN_LEFT, /* pairs + unmatched LHS tuples */ |
| 683 | PG_JOIN_FULL, /* pairs + unmatched LHS + unmatched RHS */ |
| 684 | PG_JOIN_RIGHT, /* pairs + unmatched RHS tuples */ |
| 685 | |
| 686 | /* |
| 687 | * Semijoins and anti-semijoins (as defined in relational theory) do not |
| 688 | * appear in the SQL JOIN syntax, but there are standard idioms for |
| 689 | * representing them (e.g., using EXISTS). The planner recognizes these |
| 690 | * cases and converts them to joins. So the planner and executor must |
| 691 | * support these codes. NOTE: in PG_JOIN_SEMI output, it is unspecified |
| 692 | * which matching RHS row is joined to. In PG_JOIN_ANTI output, the row is |
| 693 | * guaranteed to be null-extended. |
| 694 | */ |
| 695 | PG_JOIN_SEMI, /* 1 copy of each LHS row that has match(es) */ |
| 696 | PG_JOIN_ANTI, /* 1 copy of each LHS row that has no match */ |
| 697 | |
| 698 | /* |
| 699 | * These codes are used internally in the planner, but are not supported |
| 700 | * by the executor (nor, indeed, by most of the planner). |
| 701 | */ |
| 702 | PG_JOIN_UNIQUE_OUTER, /* LHS path must be made unique */ |
| 703 | PG_JOIN_UNIQUE_INNER /* RHS path must be made unique */ |
| 704 | |
| 705 | /* |
| 706 | * We might need additional join types someday. |
| 707 | */ |
| 708 | } PGJoinType; |
| 709 | |
| 710 | /* |
| 711 | * OUTER joins are those for which pushed-down quals must behave differently |
| 712 | * from the join's own quals. This is in fact everything except INNER and |
| 713 | * SEMI joins. However, this macro must also exclude the JOIN_UNIQUE symbols |
| 714 | * since those are temporary proxies for what will eventually be an INNER |
| 715 | * join. |
| 716 | * |
| 717 | * Note: semijoins are a hybrid case, but we choose to treat them as not |
| 718 | * being outer joins. This is okay principally because the SQL syntax makes |
| 719 | * it impossible to have a pushed-down qual that refers to the inner relation |
| 720 | * of a semijoin; so there is no strong need to distinguish join quals from |
| 721 | * pushed-down quals. This is convenient because for almost all purposes, |
| 722 | * quals attached to a semijoin can be treated the same as innerjoin quals. |
| 723 | */ |
| 724 | #define IS_OUTER_JOIN(jointype) \ |
| 725 | (((1 << (jointype)) & \ |
| 726 | ((1 << PG_JOIN_LEFT) | \ |
| 727 | (1 << PG_JOIN_FULL) | \ |
| 728 | (1 << PG_JOIN_RIGHT) | \ |
| 729 | (1 << PG_JOIN_ANTI))) != 0) |
| 730 | |
| 731 | /* |
| 732 | * PGAggStrategy - |
| 733 | * overall execution strategies for PGAgg plan nodes |
| 734 | * |
| 735 | * This is needed in both plannodes.h and relation.h, so put it here... |
| 736 | */ |
| 737 | typedef enum PGAggStrategy |
| 738 | { |
| 739 | PG_AGG_PLAIN, /* simple agg across all input rows */ |
| 740 | PG_AGG_SORTED, /* grouped agg, input must be sorted */ |
| 741 | PG_AGG_HASHED, /* grouped agg, use internal hashtable */ |
| 742 | AGG_MIXED /* grouped agg, hash and sort both used */ |
| 743 | } PGAggStrategy; |
| 744 | |
| 745 | /* |
| 746 | * PGAggSplit - |
| 747 | * splitting (partial aggregation) modes for PGAgg plan nodes |
| 748 | * |
| 749 | * This is needed in both plannodes.h and relation.h, so put it here... |
| 750 | */ |
| 751 | |
| 752 | /* Primitive options supported by nodeAgg.c: */ |
| 753 | #define AGGSPLITOP_COMBINE 0x01 /* substitute combinefn for transfn */ |
| 754 | #define AGGSPLITOP_SKIPFINAL 0x02 /* skip finalfn, return state as-is */ |
| 755 | #define AGGSPLITOP_SERIALIZE 0x04 /* apply serializefn to output */ |
| 756 | #define AGGSPLITOP_DESERIALIZE 0x08 /* apply deserializefn to input */ |
| 757 | |
| 758 | /* Supported operating modes (i.e., useful combinations of these options): */ |
| 759 | typedef enum PGAggSplit |
| 760 | { |
| 761 | /* Basic, non-split aggregation: */ |
| 762 | PG_AGGSPLIT_SIMPLE = 0, |
| 763 | /* Initial phase of partial aggregation, with serialization: */ |
| 764 | PG_AGGSPLIT_INITIAL_SERIAL = AGGSPLITOP_SKIPFINAL | AGGSPLITOP_SERIALIZE, |
| 765 | /* Final phase of partial aggregation, with deserialization: */ |
| 766 | PG_AGGSPLIT_FINAL_DESERIAL = AGGSPLITOP_COMBINE | AGGSPLITOP_DESERIALIZE |
| 767 | } PGAggSplit; |
| 768 | |
| 769 | /* Test whether an PGAggSplit value selects each primitive option: */ |
| 770 | #define DO_AGGSPLIT_COMBINE(as) (((as) & AGGSPLITOP_COMBINE) != 0) |
| 771 | #define DO_AGGSPLIT_SKIPFINAL(as) (((as) & AGGSPLITOP_SKIPFINAL) != 0) |
| 772 | #define DO_AGGSPLIT_SERIALIZE(as) (((as) & AGGSPLITOP_SERIALIZE) != 0) |
| 773 | #define DO_AGGSPLIT_DESERIALIZE(as) (((as) & AGGSPLITOP_DESERIALIZE) != 0) |
| 774 | |
| 775 | /* |
| 776 | * PGSetOpCmd and PGSetOpStrategy - |
| 777 | * overall semantics and execution strategies for PGSetOp plan nodes |
| 778 | * |
| 779 | * This is needed in both plannodes.h and relation.h, so put it here... |
| 780 | */ |
| 781 | typedef enum PGSetOpCmd |
| 782 | { |
| 783 | PG_SETOPCMD_INTERSECT, |
| 784 | PG_SETOPCMD_INTERSECT_ALL, |
| 785 | PG_SETOPCMD_EXCEPT, |
| 786 | PG_SETOPCMD_EXCEPT_ALL |
| 787 | } PGSetOpCmd; |
| 788 | |
| 789 | typedef enum PGSetOpStrategy |
| 790 | { |
| 791 | PG_SETOP_SORTED, /* input must be sorted */ |
| 792 | PG_SETOP_HASHED /* use internal hashtable */ |
| 793 | } PGSetOpStrategy; |
| 794 | |
| 795 | /* |
| 796 | * PGOnConflictAction - |
| 797 | * "ON CONFLICT" clause type of query |
| 798 | * |
| 799 | * This is needed in both parsenodes.h and plannodes.h, so put it here... |
| 800 | */ |
| 801 | typedef enum PGOnConflictAction |
| 802 | { |
| 803 | PG_ONCONFLICT_NONE, /* No "ON CONFLICT" clause */ |
| 804 | PG_ONCONFLICT_NOTHING, /* ON CONFLICT ... DO NOTHING */ |
| 805 | PG_ONCONFLICT_UPDATE /* ON CONFLICT ... DO UPDATE */ |
| 806 | } PGOnConflictAction; |
| 807 | |
| 808 | |