pg_query 1.1.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (478) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +163 -52
  3. data/README.md +80 -69
  4. data/Rakefile +82 -1
  5. data/ext/pg_query/extconf.rb +3 -31
  6. data/ext/pg_query/guc-file.c +0 -0
  7. data/ext/pg_query/include/access/amapi.h +246 -0
  8. data/ext/pg_query/include/access/attmap.h +52 -0
  9. data/ext/pg_query/include/access/attnum.h +64 -0
  10. data/ext/pg_query/include/access/clog.h +61 -0
  11. data/ext/pg_query/include/access/commit_ts.h +77 -0
  12. data/ext/pg_query/include/access/detoast.h +92 -0
  13. data/ext/pg_query/include/access/genam.h +228 -0
  14. data/ext/pg_query/include/access/gin.h +78 -0
  15. data/ext/pg_query/include/access/htup.h +89 -0
  16. data/ext/pg_query/include/access/htup_details.h +819 -0
  17. data/ext/pg_query/include/access/itup.h +161 -0
  18. data/ext/pg_query/include/access/parallel.h +82 -0
  19. data/ext/pg_query/include/access/printtup.h +35 -0
  20. data/ext/pg_query/include/access/relation.h +28 -0
  21. data/ext/pg_query/include/access/relscan.h +176 -0
  22. data/ext/pg_query/include/access/rmgr.h +35 -0
  23. data/ext/pg_query/include/access/rmgrlist.h +49 -0
  24. data/ext/pg_query/include/access/sdir.h +58 -0
  25. data/ext/pg_query/include/access/skey.h +151 -0
  26. data/ext/pg_query/include/access/stratnum.h +83 -0
  27. data/ext/pg_query/include/access/sysattr.h +29 -0
  28. data/ext/pg_query/include/access/table.h +27 -0
  29. data/ext/pg_query/include/access/tableam.h +1825 -0
  30. data/ext/pg_query/include/access/transam.h +265 -0
  31. data/ext/pg_query/include/access/tupconvert.h +51 -0
  32. data/ext/pg_query/include/access/tupdesc.h +154 -0
  33. data/ext/pg_query/include/access/tupmacs.h +247 -0
  34. data/ext/pg_query/include/access/twophase.h +61 -0
  35. data/ext/pg_query/include/access/xact.h +463 -0
  36. data/ext/pg_query/include/access/xlog.h +398 -0
  37. data/ext/pg_query/include/access/xlog_internal.h +330 -0
  38. data/ext/pg_query/include/access/xlogdefs.h +109 -0
  39. data/ext/pg_query/include/access/xloginsert.h +64 -0
  40. data/ext/pg_query/include/access/xlogreader.h +327 -0
  41. data/ext/pg_query/include/access/xlogrecord.h +227 -0
  42. data/ext/pg_query/include/bootstrap/bootstrap.h +62 -0
  43. data/ext/pg_query/include/c.h +1322 -0
  44. data/ext/pg_query/include/catalog/catalog.h +42 -0
  45. data/ext/pg_query/include/catalog/catversion.h +58 -0
  46. data/ext/pg_query/include/catalog/dependency.h +275 -0
  47. data/ext/pg_query/include/catalog/genbki.h +64 -0
  48. data/ext/pg_query/include/catalog/index.h +199 -0
  49. data/ext/pg_query/include/catalog/indexing.h +366 -0
  50. data/ext/pg_query/include/catalog/namespace.h +188 -0
  51. data/ext/pg_query/include/catalog/objectaccess.h +197 -0
  52. data/ext/pg_query/include/catalog/objectaddress.h +84 -0
  53. data/ext/pg_query/include/catalog/pg_aggregate.h +176 -0
  54. data/ext/pg_query/include/catalog/pg_aggregate_d.h +77 -0
  55. data/ext/pg_query/include/catalog/pg_am.h +60 -0
  56. data/ext/pg_query/include/catalog/pg_am_d.h +45 -0
  57. data/ext/pg_query/include/catalog/pg_attribute.h +204 -0
  58. data/ext/pg_query/include/catalog/pg_attribute_d.h +59 -0
  59. data/ext/pg_query/include/catalog/pg_authid.h +58 -0
  60. data/ext/pg_query/include/catalog/pg_authid_d.h +49 -0
  61. data/ext/pg_query/include/catalog/pg_class.h +200 -0
  62. data/ext/pg_query/include/catalog/pg_class_d.h +103 -0
  63. data/ext/pg_query/include/catalog/pg_collation.h +73 -0
  64. data/ext/pg_query/include/catalog/pg_collation_d.h +45 -0
  65. data/ext/pg_query/include/catalog/pg_constraint.h +247 -0
  66. data/ext/pg_query/include/catalog/pg_constraint_d.h +67 -0
  67. data/ext/pg_query/include/catalog/pg_control.h +250 -0
  68. data/ext/pg_query/include/catalog/pg_conversion.h +72 -0
  69. data/ext/pg_query/include/catalog/pg_conversion_d.h +35 -0
  70. data/ext/pg_query/include/catalog/pg_depend.h +73 -0
  71. data/ext/pg_query/include/catalog/pg_depend_d.h +34 -0
  72. data/ext/pg_query/include/catalog/pg_event_trigger.h +51 -0
  73. data/ext/pg_query/include/catalog/pg_event_trigger_d.h +34 -0
  74. data/ext/pg_query/include/catalog/pg_index.h +80 -0
  75. data/ext/pg_query/include/catalog/pg_index_d.h +56 -0
  76. data/ext/pg_query/include/catalog/pg_language.h +67 -0
  77. data/ext/pg_query/include/catalog/pg_language_d.h +39 -0
  78. data/ext/pg_query/include/catalog/pg_namespace.h +59 -0
  79. data/ext/pg_query/include/catalog/pg_namespace_d.h +34 -0
  80. data/ext/pg_query/include/catalog/pg_opclass.h +85 -0
  81. data/ext/pg_query/include/catalog/pg_opclass_d.h +49 -0
  82. data/ext/pg_query/include/catalog/pg_operator.h +102 -0
  83. data/ext/pg_query/include/catalog/pg_operator_d.h +106 -0
  84. data/ext/pg_query/include/catalog/pg_opfamily.h +60 -0
  85. data/ext/pg_query/include/catalog/pg_opfamily_d.h +47 -0
  86. data/ext/pg_query/include/catalog/pg_partitioned_table.h +63 -0
  87. data/ext/pg_query/include/catalog/pg_partitioned_table_d.h +35 -0
  88. data/ext/pg_query/include/catalog/pg_proc.h +211 -0
  89. data/ext/pg_query/include/catalog/pg_proc_d.h +99 -0
  90. data/ext/pg_query/include/catalog/pg_publication.h +115 -0
  91. data/ext/pg_query/include/catalog/pg_publication_d.h +36 -0
  92. data/ext/pg_query/include/catalog/pg_replication_origin.h +57 -0
  93. data/ext/pg_query/include/catalog/pg_replication_origin_d.h +29 -0
  94. data/ext/pg_query/include/catalog/pg_statistic.h +275 -0
  95. data/ext/pg_query/include/catalog/pg_statistic_d.h +194 -0
  96. data/ext/pg_query/include/catalog/pg_statistic_ext.h +74 -0
  97. data/ext/pg_query/include/catalog/pg_statistic_ext_d.h +40 -0
  98. data/ext/pg_query/include/catalog/pg_transform.h +45 -0
  99. data/ext/pg_query/include/catalog/pg_transform_d.h +32 -0
  100. data/ext/pg_query/include/catalog/pg_trigger.h +137 -0
  101. data/ext/pg_query/include/catalog/pg_trigger_d.h +106 -0
  102. data/ext/pg_query/include/catalog/pg_ts_config.h +50 -0
  103. data/ext/pg_query/include/catalog/pg_ts_config_d.h +32 -0
  104. data/ext/pg_query/include/catalog/pg_ts_dict.h +54 -0
  105. data/ext/pg_query/include/catalog/pg_ts_dict_d.h +33 -0
  106. data/ext/pg_query/include/catalog/pg_ts_parser.h +57 -0
  107. data/ext/pg_query/include/catalog/pg_ts_parser_d.h +35 -0
  108. data/ext/pg_query/include/catalog/pg_ts_template.h +48 -0
  109. data/ext/pg_query/include/catalog/pg_ts_template_d.h +32 -0
  110. data/ext/pg_query/include/catalog/pg_type.h +372 -0
  111. data/ext/pg_query/include/catalog/pg_type_d.h +285 -0
  112. data/ext/pg_query/include/catalog/storage.h +48 -0
  113. data/ext/pg_query/include/commands/async.h +54 -0
  114. data/ext/pg_query/include/commands/dbcommands.h +35 -0
  115. data/ext/pg_query/include/commands/defrem.h +173 -0
  116. data/ext/pg_query/include/commands/event_trigger.h +88 -0
  117. data/ext/pg_query/include/commands/explain.h +127 -0
  118. data/ext/pg_query/include/commands/prepare.h +61 -0
  119. data/ext/pg_query/include/commands/tablespace.h +67 -0
  120. data/ext/pg_query/include/commands/trigger.h +277 -0
  121. data/ext/pg_query/include/commands/user.h +37 -0
  122. data/ext/pg_query/include/commands/vacuum.h +293 -0
  123. data/ext/pg_query/include/commands/variable.h +38 -0
  124. data/ext/pg_query/include/common/file_perm.h +56 -0
  125. data/ext/pg_query/include/common/hashfn.h +104 -0
  126. data/ext/pg_query/include/common/ip.h +37 -0
  127. data/ext/pg_query/include/common/keywords.h +33 -0
  128. data/ext/pg_query/include/common/kwlookup.h +44 -0
  129. data/ext/pg_query/include/common/relpath.h +90 -0
  130. data/ext/pg_query/include/common/string.h +19 -0
  131. data/ext/pg_query/include/common/unicode_combining_table.h +196 -0
  132. data/ext/pg_query/include/datatype/timestamp.h +197 -0
  133. data/ext/pg_query/include/executor/execdesc.h +70 -0
  134. data/ext/pg_query/include/executor/executor.h +614 -0
  135. data/ext/pg_query/include/executor/functions.h +41 -0
  136. data/ext/pg_query/include/executor/instrument.h +101 -0
  137. data/ext/pg_query/include/executor/spi.h +175 -0
  138. data/ext/pg_query/include/executor/tablefunc.h +67 -0
  139. data/ext/pg_query/include/executor/tuptable.h +487 -0
  140. data/ext/pg_query/include/fmgr.h +775 -0
  141. data/ext/pg_query/include/funcapi.h +348 -0
  142. data/ext/pg_query/include/getaddrinfo.h +162 -0
  143. data/ext/pg_query/include/jit/jit.h +105 -0
  144. data/ext/pg_query/include/kwlist_d.h +1072 -0
  145. data/ext/pg_query/include/lib/ilist.h +727 -0
  146. data/ext/pg_query/include/lib/pairingheap.h +102 -0
  147. data/ext/pg_query/include/lib/simplehash.h +1059 -0
  148. data/ext/pg_query/include/lib/stringinfo.h +161 -0
  149. data/ext/pg_query/include/libpq/auth.h +29 -0
  150. data/ext/pg_query/include/libpq/crypt.h +46 -0
  151. data/ext/pg_query/include/libpq/hba.h +140 -0
  152. data/ext/pg_query/include/libpq/libpq-be.h +326 -0
  153. data/ext/pg_query/include/libpq/libpq.h +133 -0
  154. data/ext/pg_query/include/libpq/pqcomm.h +208 -0
  155. data/ext/pg_query/include/libpq/pqformat.h +210 -0
  156. data/ext/pg_query/include/libpq/pqsignal.h +42 -0
  157. data/ext/pg_query/include/mb/pg_wchar.h +672 -0
  158. data/ext/pg_query/include/mb/stringinfo_mb.h +24 -0
  159. data/ext/pg_query/include/miscadmin.h +476 -0
  160. data/ext/pg_query/include/nodes/bitmapset.h +122 -0
  161. data/ext/pg_query/include/nodes/execnodes.h +2520 -0
  162. data/ext/pg_query/include/nodes/extensible.h +160 -0
  163. data/ext/pg_query/include/nodes/lockoptions.h +61 -0
  164. data/ext/pg_query/include/nodes/makefuncs.h +108 -0
  165. data/ext/pg_query/include/nodes/memnodes.h +108 -0
  166. data/ext/pg_query/include/nodes/nodeFuncs.h +162 -0
  167. data/ext/pg_query/include/nodes/nodes.h +842 -0
  168. data/ext/pg_query/include/nodes/params.h +170 -0
  169. data/ext/pg_query/include/nodes/parsenodes.h +3579 -0
  170. data/ext/pg_query/include/nodes/pathnodes.h +2556 -0
  171. data/ext/pg_query/include/nodes/pg_list.h +605 -0
  172. data/ext/pg_query/include/nodes/plannodes.h +1251 -0
  173. data/ext/pg_query/include/nodes/primnodes.h +1541 -0
  174. data/ext/pg_query/include/nodes/print.h +34 -0
  175. data/ext/pg_query/include/nodes/tidbitmap.h +75 -0
  176. data/ext/pg_query/include/nodes/value.h +61 -0
  177. data/ext/pg_query/include/optimizer/cost.h +206 -0
  178. data/ext/pg_query/include/optimizer/geqo.h +88 -0
  179. data/ext/pg_query/include/optimizer/geqo_gene.h +45 -0
  180. data/ext/pg_query/include/optimizer/optimizer.h +199 -0
  181. data/ext/pg_query/include/optimizer/paths.h +249 -0
  182. data/ext/pg_query/include/optimizer/planmain.h +119 -0
  183. data/ext/pg_query/include/parser/analyze.h +49 -0
  184. data/ext/pg_query/include/parser/gram.h +1067 -0
  185. data/ext/pg_query/include/parser/gramparse.h +75 -0
  186. data/ext/pg_query/include/parser/kwlist.h +477 -0
  187. data/ext/pg_query/include/parser/parse_agg.h +68 -0
  188. data/ext/pg_query/include/parser/parse_clause.h +54 -0
  189. data/ext/pg_query/include/parser/parse_coerce.h +97 -0
  190. data/ext/pg_query/include/parser/parse_collate.h +27 -0
  191. data/ext/pg_query/include/parser/parse_expr.h +26 -0
  192. data/ext/pg_query/include/parser/parse_func.h +73 -0
  193. data/ext/pg_query/include/parser/parse_node.h +327 -0
  194. data/ext/pg_query/include/parser/parse_oper.h +67 -0
  195. data/ext/pg_query/include/parser/parse_relation.h +123 -0
  196. data/ext/pg_query/include/parser/parse_target.h +46 -0
  197. data/ext/pg_query/include/parser/parse_type.h +60 -0
  198. data/ext/pg_query/include/parser/parser.h +41 -0
  199. data/ext/pg_query/include/parser/parsetree.h +61 -0
  200. data/ext/pg_query/include/parser/scanner.h +152 -0
  201. data/ext/pg_query/include/parser/scansup.h +30 -0
  202. data/ext/pg_query/include/partitioning/partdefs.h +26 -0
  203. data/ext/pg_query/include/pg_config.h +988 -0
  204. data/ext/pg_query/include/pg_config_ext.h +8 -0
  205. data/ext/pg_query/include/pg_config_manual.h +350 -0
  206. data/ext/pg_query/include/pg_config_os.h +8 -0
  207. data/ext/pg_query/include/pg_getopt.h +56 -0
  208. data/ext/pg_query/include/pg_query.h +121 -0
  209. data/ext/pg_query/include/pg_query_enum_defs.c +2454 -0
  210. data/ext/pg_query/include/pg_query_fingerprint_conds.c +875 -0
  211. data/ext/pg_query/include/pg_query_fingerprint_defs.c +12413 -0
  212. data/ext/pg_query/include/pg_query_json_helper.c +61 -0
  213. data/ext/pg_query/include/pg_query_outfuncs_conds.c +686 -0
  214. data/ext/pg_query/include/pg_query_outfuncs_defs.c +2437 -0
  215. data/ext/pg_query/include/pg_query_readfuncs_conds.c +222 -0
  216. data/ext/pg_query/include/pg_query_readfuncs_defs.c +2878 -0
  217. data/ext/pg_query/include/pg_trace.h +17 -0
  218. data/ext/pg_query/include/pgstat.h +1487 -0
  219. data/ext/pg_query/include/pgtime.h +84 -0
  220. data/ext/pg_query/include/pl_gram.h +385 -0
  221. data/ext/pg_query/include/pl_reserved_kwlist.h +52 -0
  222. data/ext/pg_query/include/pl_reserved_kwlist_d.h +114 -0
  223. data/ext/pg_query/include/pl_unreserved_kwlist.h +112 -0
  224. data/ext/pg_query/include/pl_unreserved_kwlist_d.h +246 -0
  225. data/ext/pg_query/include/plerrcodes.h +990 -0
  226. data/ext/pg_query/include/plpgsql.h +1347 -0
  227. data/ext/pg_query/include/port.h +524 -0
  228. data/ext/pg_query/include/port/atomics.h +524 -0
  229. data/ext/pg_query/include/port/atomics/arch-arm.h +26 -0
  230. data/ext/pg_query/include/port/atomics/arch-ppc.h +254 -0
  231. data/ext/pg_query/include/port/atomics/arch-x86.h +252 -0
  232. data/ext/pg_query/include/port/atomics/fallback.h +170 -0
  233. data/ext/pg_query/include/port/atomics/generic-gcc.h +286 -0
  234. data/ext/pg_query/include/port/atomics/generic.h +401 -0
  235. data/ext/pg_query/include/port/pg_bitutils.h +226 -0
  236. data/ext/pg_query/include/port/pg_bswap.h +161 -0
  237. data/ext/pg_query/include/port/pg_crc32c.h +101 -0
  238. data/ext/pg_query/include/portability/instr_time.h +256 -0
  239. data/ext/pg_query/include/postgres.h +764 -0
  240. data/ext/pg_query/include/postgres_ext.h +74 -0
  241. data/ext/pg_query/include/postmaster/autovacuum.h +83 -0
  242. data/ext/pg_query/include/postmaster/bgworker.h +161 -0
  243. data/ext/pg_query/include/postmaster/bgworker_internals.h +64 -0
  244. data/ext/pg_query/include/postmaster/bgwriter.h +45 -0
  245. data/ext/pg_query/include/postmaster/fork_process.h +17 -0
  246. data/ext/pg_query/include/postmaster/interrupt.h +32 -0
  247. data/ext/pg_query/include/postmaster/pgarch.h +39 -0
  248. data/ext/pg_query/include/postmaster/postmaster.h +77 -0
  249. data/ext/pg_query/include/postmaster/syslogger.h +98 -0
  250. data/ext/pg_query/include/postmaster/walwriter.h +21 -0
  251. data/ext/pg_query/include/protobuf-c.h +1106 -0
  252. data/ext/pg_query/include/protobuf-c/protobuf-c.h +1106 -0
  253. data/ext/pg_query/include/protobuf/pg_query.pb-c.h +10846 -0
  254. data/ext/pg_query/include/protobuf/pg_query.pb.h +124718 -0
  255. data/ext/pg_query/include/regex/regex.h +184 -0
  256. data/ext/pg_query/include/replication/logicallauncher.h +31 -0
  257. data/ext/pg_query/include/replication/logicalproto.h +110 -0
  258. data/ext/pg_query/include/replication/logicalworker.h +19 -0
  259. data/ext/pg_query/include/replication/origin.h +73 -0
  260. data/ext/pg_query/include/replication/reorderbuffer.h +467 -0
  261. data/ext/pg_query/include/replication/slot.h +219 -0
  262. data/ext/pg_query/include/replication/syncrep.h +115 -0
  263. data/ext/pg_query/include/replication/walreceiver.h +340 -0
  264. data/ext/pg_query/include/replication/walsender.h +74 -0
  265. data/ext/pg_query/include/rewrite/prs2lock.h +46 -0
  266. data/ext/pg_query/include/rewrite/rewriteHandler.h +40 -0
  267. data/ext/pg_query/include/rewrite/rewriteManip.h +87 -0
  268. data/ext/pg_query/include/rewrite/rewriteSupport.h +26 -0
  269. data/ext/pg_query/include/storage/backendid.h +37 -0
  270. data/ext/pg_query/include/storage/block.h +121 -0
  271. data/ext/pg_query/include/storage/buf.h +46 -0
  272. data/ext/pg_query/include/storage/bufmgr.h +292 -0
  273. data/ext/pg_query/include/storage/bufpage.h +459 -0
  274. data/ext/pg_query/include/storage/condition_variable.h +62 -0
  275. data/ext/pg_query/include/storage/dsm.h +61 -0
  276. data/ext/pg_query/include/storage/dsm_impl.h +75 -0
  277. data/ext/pg_query/include/storage/fd.h +168 -0
  278. data/ext/pg_query/include/storage/ipc.h +81 -0
  279. data/ext/pg_query/include/storage/item.h +19 -0
  280. data/ext/pg_query/include/storage/itemid.h +184 -0
  281. data/ext/pg_query/include/storage/itemptr.h +206 -0
  282. data/ext/pg_query/include/storage/large_object.h +100 -0
  283. data/ext/pg_query/include/storage/latch.h +190 -0
  284. data/ext/pg_query/include/storage/lmgr.h +114 -0
  285. data/ext/pg_query/include/storage/lock.h +612 -0
  286. data/ext/pg_query/include/storage/lockdefs.h +59 -0
  287. data/ext/pg_query/include/storage/lwlock.h +232 -0
  288. data/ext/pg_query/include/storage/lwlocknames.h +51 -0
  289. data/ext/pg_query/include/storage/off.h +57 -0
  290. data/ext/pg_query/include/storage/pg_sema.h +61 -0
  291. data/ext/pg_query/include/storage/pg_shmem.h +90 -0
  292. data/ext/pg_query/include/storage/pmsignal.h +94 -0
  293. data/ext/pg_query/include/storage/predicate.h +87 -0
  294. data/ext/pg_query/include/storage/proc.h +333 -0
  295. data/ext/pg_query/include/storage/proclist_types.h +51 -0
  296. data/ext/pg_query/include/storage/procsignal.h +75 -0
  297. data/ext/pg_query/include/storage/relfilenode.h +99 -0
  298. data/ext/pg_query/include/storage/s_lock.h +1047 -0
  299. data/ext/pg_query/include/storage/sharedfileset.h +45 -0
  300. data/ext/pg_query/include/storage/shm_mq.h +85 -0
  301. data/ext/pg_query/include/storage/shm_toc.h +58 -0
  302. data/ext/pg_query/include/storage/shmem.h +81 -0
  303. data/ext/pg_query/include/storage/sinval.h +153 -0
  304. data/ext/pg_query/include/storage/sinvaladt.h +43 -0
  305. data/ext/pg_query/include/storage/smgr.h +109 -0
  306. data/ext/pg_query/include/storage/spin.h +77 -0
  307. data/ext/pg_query/include/storage/standby.h +91 -0
  308. data/ext/pg_query/include/storage/standbydefs.h +74 -0
  309. data/ext/pg_query/include/storage/sync.h +62 -0
  310. data/ext/pg_query/include/tcop/cmdtag.h +58 -0
  311. data/ext/pg_query/include/tcop/cmdtaglist.h +217 -0
  312. data/ext/pg_query/include/tcop/deparse_utility.h +108 -0
  313. data/ext/pg_query/include/tcop/dest.h +149 -0
  314. data/ext/pg_query/include/tcop/fastpath.h +21 -0
  315. data/ext/pg_query/include/tcop/pquery.h +45 -0
  316. data/ext/pg_query/include/tcop/tcopprot.h +89 -0
  317. data/ext/pg_query/include/tcop/utility.h +108 -0
  318. data/ext/pg_query/include/tsearch/ts_cache.h +98 -0
  319. data/ext/pg_query/include/utils/acl.h +312 -0
  320. data/ext/pg_query/include/utils/aclchk_internal.h +45 -0
  321. data/ext/pg_query/include/utils/array.h +458 -0
  322. data/ext/pg_query/include/utils/builtins.h +127 -0
  323. data/ext/pg_query/include/utils/bytea.h +27 -0
  324. data/ext/pg_query/include/utils/catcache.h +231 -0
  325. data/ext/pg_query/include/utils/date.h +90 -0
  326. data/ext/pg_query/include/utils/datetime.h +343 -0
  327. data/ext/pg_query/include/utils/datum.h +68 -0
  328. data/ext/pg_query/include/utils/dsa.h +123 -0
  329. data/ext/pg_query/include/utils/dynahash.h +19 -0
  330. data/ext/pg_query/include/utils/elog.h +439 -0
  331. data/ext/pg_query/include/utils/errcodes.h +352 -0
  332. data/ext/pg_query/include/utils/expandeddatum.h +159 -0
  333. data/ext/pg_query/include/utils/expandedrecord.h +231 -0
  334. data/ext/pg_query/include/utils/float.h +356 -0
  335. data/ext/pg_query/include/utils/fmgroids.h +2657 -0
  336. data/ext/pg_query/include/utils/fmgrprotos.h +2646 -0
  337. data/ext/pg_query/include/utils/fmgrtab.h +48 -0
  338. data/ext/pg_query/include/utils/guc.h +443 -0
  339. data/ext/pg_query/include/utils/guc_tables.h +272 -0
  340. data/ext/pg_query/include/utils/hsearch.h +149 -0
  341. data/ext/pg_query/include/utils/inval.h +64 -0
  342. data/ext/pg_query/include/utils/lsyscache.h +197 -0
  343. data/ext/pg_query/include/utils/memdebug.h +82 -0
  344. data/ext/pg_query/include/utils/memutils.h +225 -0
  345. data/ext/pg_query/include/utils/numeric.h +76 -0
  346. data/ext/pg_query/include/utils/palloc.h +136 -0
  347. data/ext/pg_query/include/utils/partcache.h +102 -0
  348. data/ext/pg_query/include/utils/pg_locale.h +119 -0
  349. data/ext/pg_query/include/utils/pg_lsn.h +29 -0
  350. data/ext/pg_query/include/utils/pidfile.h +56 -0
  351. data/ext/pg_query/include/utils/plancache.h +235 -0
  352. data/ext/pg_query/include/utils/portal.h +241 -0
  353. data/ext/pg_query/include/utils/probes.h +114 -0
  354. data/ext/pg_query/include/utils/ps_status.h +25 -0
  355. data/ext/pg_query/include/utils/queryenvironment.h +74 -0
  356. data/ext/pg_query/include/utils/regproc.h +28 -0
  357. data/ext/pg_query/include/utils/rel.h +644 -0
  358. data/ext/pg_query/include/utils/relcache.h +151 -0
  359. data/ext/pg_query/include/utils/reltrigger.h +81 -0
  360. data/ext/pg_query/include/utils/resowner.h +86 -0
  361. data/ext/pg_query/include/utils/rls.h +50 -0
  362. data/ext/pg_query/include/utils/ruleutils.h +44 -0
  363. data/ext/pg_query/include/utils/sharedtuplestore.h +61 -0
  364. data/ext/pg_query/include/utils/snapmgr.h +158 -0
  365. data/ext/pg_query/include/utils/snapshot.h +206 -0
  366. data/ext/pg_query/include/utils/sortsupport.h +276 -0
  367. data/ext/pg_query/include/utils/syscache.h +219 -0
  368. data/ext/pg_query/include/utils/timeout.h +88 -0
  369. data/ext/pg_query/include/utils/timestamp.h +116 -0
  370. data/ext/pg_query/include/utils/tuplesort.h +277 -0
  371. data/ext/pg_query/include/utils/tuplestore.h +91 -0
  372. data/ext/pg_query/include/utils/typcache.h +202 -0
  373. data/ext/pg_query/include/utils/tzparser.h +39 -0
  374. data/ext/pg_query/include/utils/varlena.h +39 -0
  375. data/ext/pg_query/include/utils/xml.h +84 -0
  376. data/ext/pg_query/include/xxhash.h +5445 -0
  377. data/ext/pg_query/include/xxhash/xxhash.h +5445 -0
  378. data/ext/pg_query/pg_query.c +104 -0
  379. data/ext/pg_query/pg_query.pb-c.c +37628 -0
  380. data/ext/pg_query/pg_query_deparse.c +9953 -0
  381. data/ext/pg_query/pg_query_fingerprint.c +292 -0
  382. data/ext/pg_query/pg_query_fingerprint.h +8 -0
  383. data/ext/pg_query/pg_query_internal.h +24 -0
  384. data/ext/pg_query/pg_query_json_plpgsql.c +738 -0
  385. data/ext/pg_query/pg_query_json_plpgsql.h +9 -0
  386. data/ext/pg_query/pg_query_normalize.c +437 -0
  387. data/ext/pg_query/pg_query_outfuncs.h +10 -0
  388. data/ext/pg_query/pg_query_outfuncs_json.c +297 -0
  389. data/ext/pg_query/pg_query_outfuncs_protobuf.c +237 -0
  390. data/ext/pg_query/pg_query_parse.c +148 -0
  391. data/ext/pg_query/pg_query_parse_plpgsql.c +460 -0
  392. data/ext/pg_query/pg_query_readfuncs.h +11 -0
  393. data/ext/pg_query/pg_query_readfuncs_protobuf.c +142 -0
  394. data/ext/pg_query/pg_query_ruby.c +108 -12
  395. data/ext/pg_query/pg_query_scan.c +173 -0
  396. data/ext/pg_query/pg_query_split.c +221 -0
  397. data/ext/pg_query/protobuf-c.c +3660 -0
  398. data/ext/pg_query/src_backend_catalog_namespace.c +1051 -0
  399. data/ext/pg_query/src_backend_catalog_pg_proc.c +142 -0
  400. data/ext/pg_query/src_backend_commands_define.c +117 -0
  401. data/ext/pg_query/src_backend_libpq_pqcomm.c +651 -0
  402. data/ext/pg_query/src_backend_nodes_bitmapset.c +513 -0
  403. data/ext/pg_query/src_backend_nodes_copyfuncs.c +6013 -0
  404. data/ext/pg_query/src_backend_nodes_equalfuncs.c +4003 -0
  405. data/ext/pg_query/src_backend_nodes_extensible.c +99 -0
  406. data/ext/pg_query/src_backend_nodes_list.c +922 -0
  407. data/ext/pg_query/src_backend_nodes_makefuncs.c +417 -0
  408. data/ext/pg_query/src_backend_nodes_nodeFuncs.c +1363 -0
  409. data/ext/pg_query/src_backend_nodes_value.c +84 -0
  410. data/ext/pg_query/src_backend_parser_gram.c +47456 -0
  411. data/ext/pg_query/src_backend_parser_parse_expr.c +313 -0
  412. data/ext/pg_query/src_backend_parser_parser.c +497 -0
  413. data/ext/pg_query/src_backend_parser_scan.c +7091 -0
  414. data/ext/pg_query/src_backend_parser_scansup.c +160 -0
  415. data/ext/pg_query/src_backend_postmaster_postmaster.c +2230 -0
  416. data/ext/pg_query/src_backend_storage_ipc_ipc.c +192 -0
  417. data/ext/pg_query/src_backend_storage_lmgr_s_lock.c +370 -0
  418. data/ext/pg_query/src_backend_tcop_postgres.c +776 -0
  419. data/ext/pg_query/src_backend_utils_adt_datum.c +326 -0
  420. data/ext/pg_query/src_backend_utils_adt_expandeddatum.c +98 -0
  421. data/ext/pg_query/src_backend_utils_adt_format_type.c +136 -0
  422. data/ext/pg_query/src_backend_utils_adt_ruleutils.c +1683 -0
  423. data/ext/pg_query/src_backend_utils_error_assert.c +74 -0
  424. data/ext/pg_query/src_backend_utils_error_elog.c +1748 -0
  425. data/ext/pg_query/src_backend_utils_fmgr_fmgr.c +570 -0
  426. data/ext/pg_query/src_backend_utils_hash_dynahash.c +1086 -0
  427. data/ext/pg_query/src_backend_utils_init_globals.c +168 -0
  428. data/ext/pg_query/src_backend_utils_mb_mbutils.c +839 -0
  429. data/ext/pg_query/src_backend_utils_misc_guc.c +1831 -0
  430. data/ext/pg_query/src_backend_utils_mmgr_aset.c +1560 -0
  431. data/ext/pg_query/src_backend_utils_mmgr_mcxt.c +1006 -0
  432. data/ext/pg_query/src_common_encnames.c +158 -0
  433. data/ext/pg_query/src_common_keywords.c +39 -0
  434. data/ext/pg_query/src_common_kwlist_d.h +1081 -0
  435. data/ext/pg_query/src_common_kwlookup.c +91 -0
  436. data/ext/pg_query/src_common_psprintf.c +158 -0
  437. data/ext/pg_query/src_common_string.c +86 -0
  438. data/ext/pg_query/src_common_stringinfo.c +336 -0
  439. data/ext/pg_query/src_common_wchar.c +1651 -0
  440. data/ext/pg_query/src_pl_plpgsql_src_pl_comp.c +1133 -0
  441. data/ext/pg_query/src_pl_plpgsql_src_pl_funcs.c +877 -0
  442. data/ext/pg_query/src_pl_plpgsql_src_pl_gram.c +6533 -0
  443. data/ext/pg_query/src_pl_plpgsql_src_pl_handler.c +107 -0
  444. data/ext/pg_query/src_pl_plpgsql_src_pl_reserved_kwlist_d.h +123 -0
  445. data/ext/pg_query/src_pl_plpgsql_src_pl_scanner.c +671 -0
  446. data/ext/pg_query/src_pl_plpgsql_src_pl_unreserved_kwlist_d.h +255 -0
  447. data/ext/pg_query/src_port_erand48.c +127 -0
  448. data/ext/pg_query/src_port_pg_bitutils.c +246 -0
  449. data/ext/pg_query/src_port_pgsleep.c +69 -0
  450. data/ext/pg_query/src_port_pgstrcasecmp.c +83 -0
  451. data/ext/pg_query/src_port_qsort.c +240 -0
  452. data/ext/pg_query/src_port_random.c +31 -0
  453. data/ext/pg_query/src_port_snprintf.c +1449 -0
  454. data/ext/pg_query/src_port_strerror.c +324 -0
  455. data/ext/pg_query/src_port_strnlen.c +39 -0
  456. data/ext/pg_query/xxhash.c +43 -0
  457. data/lib/pg_query.rb +7 -4
  458. data/lib/pg_query/constants.rb +21 -0
  459. data/lib/pg_query/deparse.rb +16 -1117
  460. data/lib/pg_query/filter_columns.rb +86 -85
  461. data/lib/pg_query/fingerprint.rb +122 -87
  462. data/lib/pg_query/json_field_names.rb +1402 -0
  463. data/lib/pg_query/node.rb +31 -0
  464. data/lib/pg_query/param_refs.rb +42 -37
  465. data/lib/pg_query/parse.rb +220 -200
  466. data/lib/pg_query/parse_error.rb +1 -1
  467. data/lib/pg_query/pg_query_pb.rb +3211 -0
  468. data/lib/pg_query/scan.rb +23 -0
  469. data/lib/pg_query/treewalker.rb +24 -40
  470. data/lib/pg_query/truncate.rb +64 -43
  471. data/lib/pg_query/version.rb +2 -2
  472. metadata +473 -11
  473. data/ext/pg_query/pg_query_ruby.h +0 -10
  474. data/lib/pg_query/deep_dup.rb +0 -16
  475. data/lib/pg_query/deparse/alter_table.rb +0 -42
  476. data/lib/pg_query/deparse/interval.rb +0 -105
  477. data/lib/pg_query/legacy_parsetree.rb +0 -109
  478. data/lib/pg_query/node_types.rb +0 -284
@@ -0,0 +1,122 @@
1
+ /*-------------------------------------------------------------------------
2
+ *
3
+ * bitmapset.h
4
+ * PostgreSQL generic bitmap set package
5
+ *
6
+ * A bitmap set can represent any set of nonnegative integers, although
7
+ * it is mainly intended for sets where the maximum value is not large,
8
+ * say at most a few hundred. By convention, a NULL pointer is always
9
+ * accepted by all operations to represent the empty set. (But beware
10
+ * that this is not the only representation of the empty set. Use
11
+ * bms_is_empty() in preference to testing for NULL.)
12
+ *
13
+ *
14
+ * Copyright (c) 2003-2020, PostgreSQL Global Development Group
15
+ *
16
+ * src/include/nodes/bitmapset.h
17
+ *
18
+ *-------------------------------------------------------------------------
19
+ */
20
+ #ifndef BITMAPSET_H
21
+ #define BITMAPSET_H
22
+
23
+ /*
24
+ * Forward decl to save including pg_list.h
25
+ */
26
+ struct List;
27
+
28
+ /*
29
+ * Data representation
30
+ *
31
+ * Larger bitmap word sizes generally give better performance, so long as
32
+ * they're not wider than the processor can handle efficiently. We use
33
+ * 64-bit words if pointers are that large, else 32-bit words.
34
+ */
35
+ #if SIZEOF_VOID_P >= 8
36
+
37
+ #define BITS_PER_BITMAPWORD 64
38
+ typedef uint64 bitmapword; /* must be an unsigned type */
39
+ typedef int64 signedbitmapword; /* must be the matching signed type */
40
+
41
+ #else
42
+
43
+ #define BITS_PER_BITMAPWORD 32
44
+ typedef uint32 bitmapword; /* must be an unsigned type */
45
+ typedef int32 signedbitmapword; /* must be the matching signed type */
46
+
47
+ #endif
48
+
49
+ typedef struct Bitmapset
50
+ {
51
+ int nwords; /* number of words in array */
52
+ bitmapword words[FLEXIBLE_ARRAY_MEMBER]; /* really [nwords] */
53
+ } Bitmapset;
54
+
55
+
56
+ /* result of bms_subset_compare */
57
+ typedef enum
58
+ {
59
+ BMS_EQUAL, /* sets are equal */
60
+ BMS_SUBSET1, /* first set is a subset of the second */
61
+ BMS_SUBSET2, /* second set is a subset of the first */
62
+ BMS_DIFFERENT /* neither set is a subset of the other */
63
+ } BMS_Comparison;
64
+
65
+ /* result of bms_membership */
66
+ typedef enum
67
+ {
68
+ BMS_EMPTY_SET, /* 0 members */
69
+ BMS_SINGLETON, /* 1 member */
70
+ BMS_MULTIPLE /* >1 member */
71
+ } BMS_Membership;
72
+
73
+
74
+ /*
75
+ * function prototypes in nodes/bitmapset.c
76
+ */
77
+
78
+ extern Bitmapset *bms_copy(const Bitmapset *a);
79
+ extern bool bms_equal(const Bitmapset *a, const Bitmapset *b);
80
+ extern int bms_compare(const Bitmapset *a, const Bitmapset *b);
81
+ extern Bitmapset *bms_make_singleton(int x);
82
+ extern void bms_free(Bitmapset *a);
83
+
84
+ extern Bitmapset *bms_union(const Bitmapset *a, const Bitmapset *b);
85
+ extern Bitmapset *bms_intersect(const Bitmapset *a, const Bitmapset *b);
86
+ extern Bitmapset *bms_difference(const Bitmapset *a, const Bitmapset *b);
87
+ extern bool bms_is_subset(const Bitmapset *a, const Bitmapset *b);
88
+ extern BMS_Comparison bms_subset_compare(const Bitmapset *a, const Bitmapset *b);
89
+ extern bool bms_is_member(int x, const Bitmapset *a);
90
+ extern int bms_member_index(Bitmapset *a, int x);
91
+ extern bool bms_overlap(const Bitmapset *a, const Bitmapset *b);
92
+ extern bool bms_overlap_list(const Bitmapset *a, const struct List *b);
93
+ extern bool bms_nonempty_difference(const Bitmapset *a, const Bitmapset *b);
94
+ extern int bms_singleton_member(const Bitmapset *a);
95
+ extern bool bms_get_singleton_member(const Bitmapset *a, int *member);
96
+ extern int bms_num_members(const Bitmapset *a);
97
+
98
+ /* optimized tests when we don't need to know exact membership count: */
99
+ extern BMS_Membership bms_membership(const Bitmapset *a);
100
+ extern bool bms_is_empty(const Bitmapset *a);
101
+
102
+ /* these routines recycle (modify or free) their non-const inputs: */
103
+
104
+ extern Bitmapset *bms_add_member(Bitmapset *a, int x);
105
+ extern Bitmapset *bms_del_member(Bitmapset *a, int x);
106
+ extern Bitmapset *bms_add_members(Bitmapset *a, const Bitmapset *b);
107
+ extern Bitmapset *bms_add_range(Bitmapset *a, int lower, int upper);
108
+ extern Bitmapset *bms_int_members(Bitmapset *a, const Bitmapset *b);
109
+ extern Bitmapset *bms_del_members(Bitmapset *a, const Bitmapset *b);
110
+ extern Bitmapset *bms_join(Bitmapset *a, Bitmapset *b);
111
+
112
+ /* support for iterating through the integer elements of a set: */
113
+ extern int bms_first_member(Bitmapset *a);
114
+ extern int bms_next_member(const Bitmapset *a, int prevbit);
115
+ extern int bms_prev_member(const Bitmapset *a, int prevbit);
116
+
117
+ /* support for hashtables using Bitmapsets as keys: */
118
+ extern uint32 bms_hash_value(const Bitmapset *a);
119
+ extern uint32 bitmap_hash(const void *key, Size keysize);
120
+ extern int bitmap_match(const void *key1, const void *key2, Size keysize);
121
+
122
+ #endif /* BITMAPSET_H */
@@ -0,0 +1,2520 @@
1
+ /*-------------------------------------------------------------------------
2
+ *
3
+ * execnodes.h
4
+ * definitions for executor state nodes
5
+ *
6
+ *
7
+ * Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group
8
+ * Portions Copyright (c) 1994, Regents of the University of California
9
+ *
10
+ * src/include/nodes/execnodes.h
11
+ *
12
+ *-------------------------------------------------------------------------
13
+ */
14
+ #ifndef EXECNODES_H
15
+ #define EXECNODES_H
16
+
17
+ #include "access/tupconvert.h"
18
+ #include "executor/instrument.h"
19
+ #include "fmgr.h"
20
+ #include "lib/pairingheap.h"
21
+ #include "nodes/params.h"
22
+ #include "nodes/plannodes.h"
23
+ #include "nodes/tidbitmap.h"
24
+ #include "partitioning/partdefs.h"
25
+ #include "storage/condition_variable.h"
26
+ #include "utils/hsearch.h"
27
+ #include "utils/queryenvironment.h"
28
+ #include "utils/reltrigger.h"
29
+ #include "utils/sharedtuplestore.h"
30
+ #include "utils/snapshot.h"
31
+ #include "utils/sortsupport.h"
32
+ #include "utils/tuplesort.h"
33
+ #include "utils/tuplestore.h"
34
+
35
+ struct PlanState; /* forward references in this file */
36
+ struct PartitionRoutingInfo;
37
+ struct ParallelHashJoinState;
38
+ struct ExecRowMark;
39
+ struct ExprState;
40
+ struct ExprContext;
41
+ struct RangeTblEntry; /* avoid including parsenodes.h here */
42
+ struct ExprEvalStep; /* avoid including execExpr.h everywhere */
43
+ struct CopyMultiInsertBuffer;
44
+
45
+
46
+ /* ----------------
47
+ * ExprState node
48
+ *
49
+ * ExprState is the top-level node for expression evaluation.
50
+ * It contains instructions (in ->steps) to evaluate the expression.
51
+ * ----------------
52
+ */
53
+ typedef Datum (*ExprStateEvalFunc) (struct ExprState *expression,
54
+ struct ExprContext *econtext,
55
+ bool *isNull);
56
+
57
+ /* Bits in ExprState->flags (see also execExpr.h for private flag bits): */
58
+ /* expression is for use with ExecQual() */
59
+ #define EEO_FLAG_IS_QUAL (1 << 0)
60
+
61
+ typedef struct ExprState
62
+ {
63
+ NodeTag tag;
64
+
65
+ uint8 flags; /* bitmask of EEO_FLAG_* bits, see above */
66
+
67
+ /*
68
+ * Storage for result value of a scalar expression, or for individual
69
+ * column results within expressions built by ExecBuildProjectionInfo().
70
+ */
71
+ #define FIELDNO_EXPRSTATE_RESNULL 2
72
+ bool resnull;
73
+ #define FIELDNO_EXPRSTATE_RESVALUE 3
74
+ Datum resvalue;
75
+
76
+ /*
77
+ * If projecting a tuple result, this slot holds the result; else NULL.
78
+ */
79
+ #define FIELDNO_EXPRSTATE_RESULTSLOT 4
80
+ TupleTableSlot *resultslot;
81
+
82
+ /*
83
+ * Instructions to compute expression's return value.
84
+ */
85
+ struct ExprEvalStep *steps;
86
+
87
+ /*
88
+ * Function that actually evaluates the expression. This can be set to
89
+ * different values depending on the complexity of the expression.
90
+ */
91
+ ExprStateEvalFunc evalfunc;
92
+
93
+ /* original expression tree, for debugging only */
94
+ Expr *expr;
95
+
96
+ /* private state for an evalfunc */
97
+ void *evalfunc_private;
98
+
99
+ /*
100
+ * XXX: following fields only needed during "compilation" (ExecInitExpr);
101
+ * could be thrown away afterwards.
102
+ */
103
+
104
+ int steps_len; /* number of steps currently */
105
+ int steps_alloc; /* allocated length of steps array */
106
+
107
+ #define FIELDNO_EXPRSTATE_PARENT 11
108
+ struct PlanState *parent; /* parent PlanState node, if any */
109
+ ParamListInfo ext_params; /* for compiling PARAM_EXTERN nodes */
110
+
111
+ Datum *innermost_caseval;
112
+ bool *innermost_casenull;
113
+
114
+ Datum *innermost_domainval;
115
+ bool *innermost_domainnull;
116
+ } ExprState;
117
+
118
+
119
+ /* ----------------
120
+ * IndexInfo information
121
+ *
122
+ * this struct holds the information needed to construct new index
123
+ * entries for a particular index. Used for both index_build and
124
+ * retail creation of index entries.
125
+ *
126
+ * NumIndexAttrs total number of columns in this index
127
+ * NumIndexKeyAttrs number of key columns in index
128
+ * IndexAttrNumbers underlying-rel attribute numbers used as keys
129
+ * (zeroes indicate expressions). It also contains
130
+ * info about included columns.
131
+ * Expressions expr trees for expression entries, or NIL if none
132
+ * ExpressionsState exec state for expressions, or NIL if none
133
+ * Predicate partial-index predicate, or NIL if none
134
+ * PredicateState exec state for predicate, or NIL if none
135
+ * ExclusionOps Per-column exclusion operators, or NULL if none
136
+ * ExclusionProcs Underlying function OIDs for ExclusionOps
137
+ * ExclusionStrats Opclass strategy numbers for ExclusionOps
138
+ * UniqueOps These are like Exclusion*, but for unique indexes
139
+ * UniqueProcs
140
+ * UniqueStrats
141
+ * Unique is it a unique index?
142
+ * OpclassOptions opclass-specific options, or NULL if none
143
+ * ReadyForInserts is it valid for inserts?
144
+ * Concurrent are we doing a concurrent index build?
145
+ * BrokenHotChain did we detect any broken HOT chains?
146
+ * ParallelWorkers # of workers requested (excludes leader)
147
+ * Am Oid of index AM
148
+ * AmCache private cache area for index AM
149
+ * Context memory context holding this IndexInfo
150
+ *
151
+ * ii_Concurrent, ii_BrokenHotChain, and ii_ParallelWorkers are used only
152
+ * during index build; they're conventionally zeroed otherwise.
153
+ * ----------------
154
+ */
155
+ typedef struct IndexInfo
156
+ {
157
+ NodeTag type;
158
+ int ii_NumIndexAttrs; /* total number of columns in index */
159
+ int ii_NumIndexKeyAttrs; /* number of key columns in index */
160
+ AttrNumber ii_IndexAttrNumbers[INDEX_MAX_KEYS];
161
+ List *ii_Expressions; /* list of Expr */
162
+ List *ii_ExpressionsState; /* list of ExprState */
163
+ List *ii_Predicate; /* list of Expr */
164
+ ExprState *ii_PredicateState;
165
+ Oid *ii_ExclusionOps; /* array with one entry per column */
166
+ Oid *ii_ExclusionProcs; /* array with one entry per column */
167
+ uint16 *ii_ExclusionStrats; /* array with one entry per column */
168
+ Oid *ii_UniqueOps; /* array with one entry per column */
169
+ Oid *ii_UniqueProcs; /* array with one entry per column */
170
+ uint16 *ii_UniqueStrats; /* array with one entry per column */
171
+ Datum *ii_OpclassOptions; /* array with one entry per column */
172
+ bool ii_Unique;
173
+ bool ii_ReadyForInserts;
174
+ bool ii_Concurrent;
175
+ bool ii_BrokenHotChain;
176
+ int ii_ParallelWorkers;
177
+ Oid ii_Am;
178
+ void *ii_AmCache;
179
+ MemoryContext ii_Context;
180
+ } IndexInfo;
181
+
182
+ /* ----------------
183
+ * ExprContext_CB
184
+ *
185
+ * List of callbacks to be called at ExprContext shutdown.
186
+ * ----------------
187
+ */
188
+ typedef void (*ExprContextCallbackFunction) (Datum arg);
189
+
190
+ typedef struct ExprContext_CB
191
+ {
192
+ struct ExprContext_CB *next;
193
+ ExprContextCallbackFunction function;
194
+ Datum arg;
195
+ } ExprContext_CB;
196
+
197
+ /* ----------------
198
+ * ExprContext
199
+ *
200
+ * This class holds the "current context" information
201
+ * needed to evaluate expressions for doing tuple qualifications
202
+ * and tuple projections. For example, if an expression refers
203
+ * to an attribute in the current inner tuple then we need to know
204
+ * what the current inner tuple is and so we look at the expression
205
+ * context.
206
+ *
207
+ * There are two memory contexts associated with an ExprContext:
208
+ * * ecxt_per_query_memory is a query-lifespan context, typically the same
209
+ * context the ExprContext node itself is allocated in. This context
210
+ * can be used for purposes such as storing function call cache info.
211
+ * * ecxt_per_tuple_memory is a short-term context for expression results.
212
+ * As the name suggests, it will typically be reset once per tuple,
213
+ * before we begin to evaluate expressions for that tuple. Each
214
+ * ExprContext normally has its very own per-tuple memory context.
215
+ *
216
+ * CurrentMemoryContext should be set to ecxt_per_tuple_memory before
217
+ * calling ExecEvalExpr() --- see ExecEvalExprSwitchContext().
218
+ * ----------------
219
+ */
220
+ typedef struct ExprContext
221
+ {
222
+ NodeTag type;
223
+
224
+ /* Tuples that Var nodes in expression may refer to */
225
+ #define FIELDNO_EXPRCONTEXT_SCANTUPLE 1
226
+ TupleTableSlot *ecxt_scantuple;
227
+ #define FIELDNO_EXPRCONTEXT_INNERTUPLE 2
228
+ TupleTableSlot *ecxt_innertuple;
229
+ #define FIELDNO_EXPRCONTEXT_OUTERTUPLE 3
230
+ TupleTableSlot *ecxt_outertuple;
231
+
232
+ /* Memory contexts for expression evaluation --- see notes above */
233
+ MemoryContext ecxt_per_query_memory;
234
+ MemoryContext ecxt_per_tuple_memory;
235
+
236
+ /* Values to substitute for Param nodes in expression */
237
+ ParamExecData *ecxt_param_exec_vals; /* for PARAM_EXEC params */
238
+ ParamListInfo ecxt_param_list_info; /* for other param types */
239
+
240
+ /*
241
+ * Values to substitute for Aggref nodes in the expressions of an Agg
242
+ * node, or for WindowFunc nodes within a WindowAgg node.
243
+ */
244
+ #define FIELDNO_EXPRCONTEXT_AGGVALUES 8
245
+ Datum *ecxt_aggvalues; /* precomputed values for aggs/windowfuncs */
246
+ #define FIELDNO_EXPRCONTEXT_AGGNULLS 9
247
+ bool *ecxt_aggnulls; /* null flags for aggs/windowfuncs */
248
+
249
+ /* Value to substitute for CaseTestExpr nodes in expression */
250
+ #define FIELDNO_EXPRCONTEXT_CASEDATUM 10
251
+ Datum caseValue_datum;
252
+ #define FIELDNO_EXPRCONTEXT_CASENULL 11
253
+ bool caseValue_isNull;
254
+
255
+ /* Value to substitute for CoerceToDomainValue nodes in expression */
256
+ #define FIELDNO_EXPRCONTEXT_DOMAINDATUM 12
257
+ Datum domainValue_datum;
258
+ #define FIELDNO_EXPRCONTEXT_DOMAINNULL 13
259
+ bool domainValue_isNull;
260
+
261
+ /* Link to containing EState (NULL if a standalone ExprContext) */
262
+ struct EState *ecxt_estate;
263
+
264
+ /* Functions to call back when ExprContext is shut down or rescanned */
265
+ ExprContext_CB *ecxt_callbacks;
266
+ } ExprContext;
267
+
268
+ /*
269
+ * Set-result status used when evaluating functions potentially returning a
270
+ * set.
271
+ */
272
+ typedef enum
273
+ {
274
+ ExprSingleResult, /* expression does not return a set */
275
+ ExprMultipleResult, /* this result is an element of a set */
276
+ ExprEndResult /* there are no more elements in the set */
277
+ } ExprDoneCond;
278
+
279
+ /*
280
+ * Return modes for functions returning sets. Note values must be chosen
281
+ * as separate bits so that a bitmask can be formed to indicate supported
282
+ * modes. SFRM_Materialize_Random and SFRM_Materialize_Preferred are
283
+ * auxiliary flags about SFRM_Materialize mode, rather than separate modes.
284
+ */
285
+ typedef enum
286
+ {
287
+ SFRM_ValuePerCall = 0x01, /* one value returned per call */
288
+ SFRM_Materialize = 0x02, /* result set instantiated in Tuplestore */
289
+ SFRM_Materialize_Random = 0x04, /* Tuplestore needs randomAccess */
290
+ SFRM_Materialize_Preferred = 0x08 /* caller prefers Tuplestore */
291
+ } SetFunctionReturnMode;
292
+
293
+ /*
294
+ * When calling a function that might return a set (multiple rows),
295
+ * a node of this type is passed as fcinfo->resultinfo to allow
296
+ * return status to be passed back. A function returning set should
297
+ * raise an error if no such resultinfo is provided.
298
+ */
299
+ typedef struct ReturnSetInfo
300
+ {
301
+ NodeTag type;
302
+ /* values set by caller: */
303
+ ExprContext *econtext; /* context function is being called in */
304
+ TupleDesc expectedDesc; /* tuple descriptor expected by caller */
305
+ int allowedModes; /* bitmask: return modes caller can handle */
306
+ /* result status from function (but pre-initialized by caller): */
307
+ SetFunctionReturnMode returnMode; /* actual return mode */
308
+ ExprDoneCond isDone; /* status for ValuePerCall mode */
309
+ /* fields filled by function in Materialize return mode: */
310
+ Tuplestorestate *setResult; /* holds the complete returned tuple set */
311
+ TupleDesc setDesc; /* actual descriptor for returned tuples */
312
+ } ReturnSetInfo;
313
+
314
+ /* ----------------
315
+ * ProjectionInfo node information
316
+ *
317
+ * This is all the information needed to perform projections ---
318
+ * that is, form new tuples by evaluation of targetlist expressions.
319
+ * Nodes which need to do projections create one of these.
320
+ *
321
+ * The target tuple slot is kept in ProjectionInfo->pi_state.resultslot.
322
+ * ExecProject() evaluates the tlist, forms a tuple, and stores it
323
+ * in the given slot. Note that the result will be a "virtual" tuple
324
+ * unless ExecMaterializeSlot() is then called to force it to be
325
+ * converted to a physical tuple. The slot must have a tupledesc
326
+ * that matches the output of the tlist!
327
+ * ----------------
328
+ */
329
+ typedef struct ProjectionInfo
330
+ {
331
+ NodeTag type;
332
+ /* instructions to evaluate projection */
333
+ ExprState pi_state;
334
+ /* expression context in which to evaluate expression */
335
+ ExprContext *pi_exprContext;
336
+ } ProjectionInfo;
337
+
338
+ /* ----------------
339
+ * JunkFilter
340
+ *
341
+ * This class is used to store information regarding junk attributes.
342
+ * A junk attribute is an attribute in a tuple that is needed only for
343
+ * storing intermediate information in the executor, and does not belong
344
+ * in emitted tuples. For example, when we do an UPDATE query,
345
+ * the planner adds a "junk" entry to the targetlist so that the tuples
346
+ * returned to ExecutePlan() contain an extra attribute: the ctid of
347
+ * the tuple to be updated. This is needed to do the update, but we
348
+ * don't want the ctid to be part of the stored new tuple! So, we
349
+ * apply a "junk filter" to remove the junk attributes and form the
350
+ * real output tuple. The junkfilter code also provides routines to
351
+ * extract the values of the junk attribute(s) from the input tuple.
352
+ *
353
+ * targetList: the original target list (including junk attributes).
354
+ * cleanTupType: the tuple descriptor for the "clean" tuple (with
355
+ * junk attributes removed).
356
+ * cleanMap: A map with the correspondence between the non-junk
357
+ * attribute numbers of the "original" tuple and the
358
+ * attribute numbers of the "clean" tuple.
359
+ * resultSlot: tuple slot used to hold cleaned tuple.
360
+ * junkAttNo: not used by junkfilter code. Can be used by caller
361
+ * to remember the attno of a specific junk attribute
362
+ * (nodeModifyTable.c keeps the "ctid" or "wholerow"
363
+ * attno here).
364
+ * ----------------
365
+ */
366
+ typedef struct JunkFilter
367
+ {
368
+ NodeTag type;
369
+ List *jf_targetList;
370
+ TupleDesc jf_cleanTupType;
371
+ AttrNumber *jf_cleanMap;
372
+ TupleTableSlot *jf_resultSlot;
373
+ AttrNumber jf_junkAttNo;
374
+ } JunkFilter;
375
+
376
+ /*
377
+ * OnConflictSetState
378
+ *
379
+ * Executor state of an ON CONFLICT DO UPDATE operation.
380
+ */
381
+ typedef struct OnConflictSetState
382
+ {
383
+ NodeTag type;
384
+
385
+ TupleTableSlot *oc_Existing; /* slot to store existing target tuple in */
386
+ TupleTableSlot *oc_ProjSlot; /* CONFLICT ... SET ... projection target */
387
+ ProjectionInfo *oc_ProjInfo; /* for ON CONFLICT DO UPDATE SET */
388
+ ExprState *oc_WhereClause; /* state for the WHERE clause */
389
+ } OnConflictSetState;
390
+
391
+ /*
392
+ * ResultRelInfo
393
+ *
394
+ * Whenever we update an existing relation, we have to update indexes on the
395
+ * relation, and perhaps also fire triggers. ResultRelInfo holds all the
396
+ * information needed about a result relation, including indexes.
397
+ *
398
+ * Normally, a ResultRelInfo refers to a table that is in the query's
399
+ * range table; then ri_RangeTableIndex is the RT index and ri_RelationDesc
400
+ * is just a copy of the relevant es_relations[] entry. But sometimes,
401
+ * in ResultRelInfos used only for triggers, ri_RangeTableIndex is zero
402
+ * and ri_RelationDesc is a separately-opened relcache pointer that needs
403
+ * to be separately closed. See ExecGetTriggerResultRel.
404
+ */
405
+ typedef struct ResultRelInfo
406
+ {
407
+ NodeTag type;
408
+
409
+ /* result relation's range table index, or 0 if not in range table */
410
+ Index ri_RangeTableIndex;
411
+
412
+ /* relation descriptor for result relation */
413
+ Relation ri_RelationDesc;
414
+
415
+ /* # of indices existing on result relation */
416
+ int ri_NumIndices;
417
+
418
+ /* array of relation descriptors for indices */
419
+ RelationPtr ri_IndexRelationDescs;
420
+
421
+ /* array of key/attr info for indices */
422
+ IndexInfo **ri_IndexRelationInfo;
423
+
424
+ /* triggers to be fired, if any */
425
+ TriggerDesc *ri_TrigDesc;
426
+
427
+ /* cached lookup info for trigger functions */
428
+ FmgrInfo *ri_TrigFunctions;
429
+
430
+ /* array of trigger WHEN expr states */
431
+ ExprState **ri_TrigWhenExprs;
432
+
433
+ /* optional runtime measurements for triggers */
434
+ Instrumentation *ri_TrigInstrument;
435
+
436
+ /* On-demand created slots for triggers / returning processing */
437
+ TupleTableSlot *ri_ReturningSlot; /* for trigger output tuples */
438
+ TupleTableSlot *ri_TrigOldSlot; /* for a trigger's old tuple */
439
+ TupleTableSlot *ri_TrigNewSlot; /* for a trigger's new tuple */
440
+
441
+ /* FDW callback functions, if foreign table */
442
+ struct FdwRoutine *ri_FdwRoutine;
443
+
444
+ /* available to save private state of FDW */
445
+ void *ri_FdwState;
446
+
447
+ /* true when modifying foreign table directly */
448
+ bool ri_usesFdwDirectModify;
449
+
450
+ /* list of WithCheckOption's to be checked */
451
+ List *ri_WithCheckOptions;
452
+
453
+ /* list of WithCheckOption expr states */
454
+ List *ri_WithCheckOptionExprs;
455
+
456
+ /* array of constraint-checking expr states */
457
+ ExprState **ri_ConstraintExprs;
458
+
459
+ /* array of stored generated columns expr states */
460
+ ExprState **ri_GeneratedExprs;
461
+
462
+ /* number of stored generated columns we need to compute */
463
+ int ri_NumGeneratedNeeded;
464
+
465
+ /* for removing junk attributes from tuples */
466
+ JunkFilter *ri_junkFilter;
467
+
468
+ /* list of RETURNING expressions */
469
+ List *ri_returningList;
470
+
471
+ /* for computing a RETURNING list */
472
+ ProjectionInfo *ri_projectReturning;
473
+
474
+ /* list of arbiter indexes to use to check conflicts */
475
+ List *ri_onConflictArbiterIndexes;
476
+
477
+ /* ON CONFLICT evaluation state */
478
+ OnConflictSetState *ri_onConflict;
479
+
480
+ /* partition check expression */
481
+ List *ri_PartitionCheck;
482
+
483
+ /* partition check expression state */
484
+ ExprState *ri_PartitionCheckExpr;
485
+
486
+ /*
487
+ * RootResultRelInfo gives the target relation mentioned in the query, if
488
+ * it's a partitioned table. It is not set if the target relation
489
+ * mentioned in the query is an inherited table, nor when tuple routing is
490
+ * not needed.
491
+ */
492
+ struct ResultRelInfo *ri_RootResultRelInfo;
493
+
494
+ /* Additional information specific to partition tuple routing */
495
+ struct PartitionRoutingInfo *ri_PartitionInfo;
496
+
497
+ /* For use by copy.c when performing multi-inserts */
498
+ struct CopyMultiInsertBuffer *ri_CopyMultiInsertBuffer;
499
+ } ResultRelInfo;
500
+
501
+ /* ----------------
502
+ * EState information
503
+ *
504
+ * Master working state for an Executor invocation
505
+ * ----------------
506
+ */
507
+ typedef struct EState
508
+ {
509
+ NodeTag type;
510
+
511
+ /* Basic state for all query types: */
512
+ ScanDirection es_direction; /* current scan direction */
513
+ Snapshot es_snapshot; /* time qual to use */
514
+ Snapshot es_crosscheck_snapshot; /* crosscheck time qual for RI */
515
+ List *es_range_table; /* List of RangeTblEntry */
516
+ Index es_range_table_size; /* size of the range table arrays */
517
+ Relation *es_relations; /* Array of per-range-table-entry Relation
518
+ * pointers, or NULL if not yet opened */
519
+ struct ExecRowMark **es_rowmarks; /* Array of per-range-table-entry
520
+ * ExecRowMarks, or NULL if none */
521
+ PlannedStmt *es_plannedstmt; /* link to top of plan tree */
522
+ const char *es_sourceText; /* Source text from QueryDesc */
523
+
524
+ JunkFilter *es_junkFilter; /* top-level junk filter, if any */
525
+
526
+ /* If query can insert/delete tuples, the command ID to mark them with */
527
+ CommandId es_output_cid;
528
+
529
+ /* Info about target table(s) for insert/update/delete queries: */
530
+ ResultRelInfo *es_result_relations; /* array of ResultRelInfos */
531
+ int es_num_result_relations; /* length of array */
532
+ ResultRelInfo *es_result_relation_info; /* currently active array elt */
533
+
534
+ /*
535
+ * Info about the partition root table(s) for insert/update/delete queries
536
+ * targeting partitioned tables. Only leaf partitions are mentioned in
537
+ * es_result_relations, but we need access to the roots for firing
538
+ * triggers and for runtime tuple routing.
539
+ */
540
+ ResultRelInfo *es_root_result_relations; /* array of ResultRelInfos */
541
+ int es_num_root_result_relations; /* length of the array */
542
+ PartitionDirectory es_partition_directory; /* for PartitionDesc lookup */
543
+
544
+ /*
545
+ * The following list contains ResultRelInfos created by the tuple routing
546
+ * code for partitions that don't already have one.
547
+ */
548
+ List *es_tuple_routing_result_relations;
549
+
550
+ /* Stuff used for firing triggers: */
551
+ List *es_trig_target_relations; /* trigger-only ResultRelInfos */
552
+
553
+ /* Parameter info: */
554
+ ParamListInfo es_param_list_info; /* values of external params */
555
+ ParamExecData *es_param_exec_vals; /* values of internal params */
556
+
557
+ QueryEnvironment *es_queryEnv; /* query environment */
558
+
559
+ /* Other working state: */
560
+ MemoryContext es_query_cxt; /* per-query context in which EState lives */
561
+
562
+ List *es_tupleTable; /* List of TupleTableSlots */
563
+
564
+ uint64 es_processed; /* # of tuples processed */
565
+
566
+ int es_top_eflags; /* eflags passed to ExecutorStart */
567
+ int es_instrument; /* OR of InstrumentOption flags */
568
+ bool es_finished; /* true when ExecutorFinish is done */
569
+
570
+ List *es_exprcontexts; /* List of ExprContexts within EState */
571
+
572
+ List *es_subplanstates; /* List of PlanState for SubPlans */
573
+
574
+ List *es_auxmodifytables; /* List of secondary ModifyTableStates */
575
+
576
+ /*
577
+ * this ExprContext is for per-output-tuple operations, such as constraint
578
+ * checks and index-value computations. It will be reset for each output
579
+ * tuple. Note that it will be created only if needed.
580
+ */
581
+ ExprContext *es_per_tuple_exprcontext;
582
+
583
+ /*
584
+ * If not NULL, this is an EPQState's EState. This is a field in EState
585
+ * both to allow EvalPlanQual aware executor nodes to detect that they
586
+ * need to perform EPQ related work, and to provide necessary information
587
+ * to do so.
588
+ */
589
+ struct EPQState *es_epq_active;
590
+
591
+ bool es_use_parallel_mode; /* can we use parallel workers? */
592
+
593
+ /* The per-query shared memory area to use for parallel execution. */
594
+ struct dsa_area *es_query_dsa;
595
+
596
+ /*
597
+ * JIT information. es_jit_flags indicates whether JIT should be performed
598
+ * and with which options. es_jit is created on-demand when JITing is
599
+ * performed.
600
+ *
601
+ * es_jit_worker_instr is the combined, on demand allocated,
602
+ * instrumentation from all workers. The leader's instrumentation is kept
603
+ * separate, and is combined on demand by ExplainPrintJITSummary().
604
+ */
605
+ int es_jit_flags;
606
+ struct JitContext *es_jit;
607
+ struct JitInstrumentation *es_jit_worker_instr;
608
+ } EState;
609
+
610
+
611
+ /*
612
+ * ExecRowMark -
613
+ * runtime representation of FOR [KEY] UPDATE/SHARE clauses
614
+ *
615
+ * When doing UPDATE, DELETE, or SELECT FOR [KEY] UPDATE/SHARE, we will have an
616
+ * ExecRowMark for each non-target relation in the query (except inheritance
617
+ * parent RTEs, which can be ignored at runtime). Virtual relations such as
618
+ * subqueries-in-FROM will have an ExecRowMark with relation == NULL. See
619
+ * PlanRowMark for details about most of the fields. In addition to fields
620
+ * directly derived from PlanRowMark, we store an activity flag (to denote
621
+ * inactive children of inheritance trees), curCtid, which is used by the
622
+ * WHERE CURRENT OF code, and ermExtra, which is available for use by the plan
623
+ * node that sources the relation (e.g., for a foreign table the FDW can use
624
+ * ermExtra to hold information).
625
+ *
626
+ * EState->es_rowmarks is an array of these structs, indexed by RT index,
627
+ * with NULLs for irrelevant RT indexes. es_rowmarks itself is NULL if
628
+ * there are no rowmarks.
629
+ */
630
+ typedef struct ExecRowMark
631
+ {
632
+ Relation relation; /* opened and suitably locked relation */
633
+ Oid relid; /* its OID (or InvalidOid, if subquery) */
634
+ Index rti; /* its range table index */
635
+ Index prti; /* parent range table index, if child */
636
+ Index rowmarkId; /* unique identifier for resjunk columns */
637
+ RowMarkType markType; /* see enum in nodes/plannodes.h */
638
+ LockClauseStrength strength; /* LockingClause's strength, or LCS_NONE */
639
+ LockWaitPolicy waitPolicy; /* NOWAIT and SKIP LOCKED */
640
+ bool ermActive; /* is this mark relevant for current tuple? */
641
+ ItemPointerData curCtid; /* ctid of currently locked tuple, if any */
642
+ void *ermExtra; /* available for use by relation source node */
643
+ } ExecRowMark;
644
+
645
+ /*
646
+ * ExecAuxRowMark -
647
+ * additional runtime representation of FOR [KEY] UPDATE/SHARE clauses
648
+ *
649
+ * Each LockRows and ModifyTable node keeps a list of the rowmarks it needs to
650
+ * deal with. In addition to a pointer to the related entry in es_rowmarks,
651
+ * this struct carries the column number(s) of the resjunk columns associated
652
+ * with the rowmark (see comments for PlanRowMark for more detail). In the
653
+ * case of ModifyTable, there has to be a separate ExecAuxRowMark list for
654
+ * each child plan, because the resjunk columns could be at different physical
655
+ * column positions in different subplans.
656
+ */
657
+ typedef struct ExecAuxRowMark
658
+ {
659
+ ExecRowMark *rowmark; /* related entry in es_rowmarks */
660
+ AttrNumber ctidAttNo; /* resno of ctid junk attribute, if any */
661
+ AttrNumber toidAttNo; /* resno of tableoid junk attribute, if any */
662
+ AttrNumber wholeAttNo; /* resno of whole-row junk attribute, if any */
663
+ } ExecAuxRowMark;
664
+
665
+
666
+ /* ----------------------------------------------------------------
667
+ * Tuple Hash Tables
668
+ *
669
+ * All-in-memory tuple hash tables are used for a number of purposes.
670
+ *
671
+ * Note: tab_hash_funcs are for the key datatype(s) stored in the table,
672
+ * and tab_eq_funcs are non-cross-type equality operators for those types.
673
+ * Normally these are the only functions used, but FindTupleHashEntry()
674
+ * supports searching a hashtable using cross-data-type hashing. For that,
675
+ * the caller must supply hash functions for the LHS datatype as well as
676
+ * the cross-type equality operators to use. in_hash_funcs and cur_eq_func
677
+ * are set to point to the caller's function arrays while doing such a search.
678
+ * During LookupTupleHashEntry(), they point to tab_hash_funcs and
679
+ * tab_eq_func respectively.
680
+ * ----------------------------------------------------------------
681
+ */
682
+ typedef struct TupleHashEntryData *TupleHashEntry;
683
+ typedef struct TupleHashTableData *TupleHashTable;
684
+
685
+ typedef struct TupleHashEntryData
686
+ {
687
+ MinimalTuple firstTuple; /* copy of first tuple in this group */
688
+ void *additional; /* user data */
689
+ uint32 status; /* hash status */
690
+ uint32 hash; /* hash value (cached) */
691
+ } TupleHashEntryData;
692
+
693
+ /* define parameters necessary to generate the tuple hash table interface */
694
+ #define SH_PREFIX tuplehash
695
+ #define SH_ELEMENT_TYPE TupleHashEntryData
696
+ #define SH_KEY_TYPE MinimalTuple
697
+ #define SH_SCOPE extern
698
+ #define SH_DECLARE
699
+ #include "lib/simplehash.h"
700
+
701
+ typedef struct TupleHashTableData
702
+ {
703
+ tuplehash_hash *hashtab; /* underlying hash table */
704
+ int numCols; /* number of columns in lookup key */
705
+ AttrNumber *keyColIdx; /* attr numbers of key columns */
706
+ FmgrInfo *tab_hash_funcs; /* hash functions for table datatype(s) */
707
+ ExprState *tab_eq_func; /* comparator for table datatype(s) */
708
+ Oid *tab_collations; /* collations for hash and comparison */
709
+ MemoryContext tablecxt; /* memory context containing table */
710
+ MemoryContext tempcxt; /* context for function evaluations */
711
+ Size entrysize; /* actual size to make each hash entry */
712
+ TupleTableSlot *tableslot; /* slot for referencing table entries */
713
+ /* The following fields are set transiently for each table search: */
714
+ TupleTableSlot *inputslot; /* current input tuple's slot */
715
+ FmgrInfo *in_hash_funcs; /* hash functions for input datatype(s) */
716
+ ExprState *cur_eq_func; /* comparator for input vs. table */
717
+ uint32 hash_iv; /* hash-function IV */
718
+ ExprContext *exprcontext; /* expression context */
719
+ } TupleHashTableData;
720
+
721
+ typedef tuplehash_iterator TupleHashIterator;
722
+
723
+ /*
724
+ * Use InitTupleHashIterator/TermTupleHashIterator for a read/write scan.
725
+ * Use ResetTupleHashIterator if the table can be frozen (in this case no
726
+ * explicit scan termination is needed).
727
+ */
728
+ #define InitTupleHashIterator(htable, iter) \
729
+ tuplehash_start_iterate(htable->hashtab, iter)
730
+ #define TermTupleHashIterator(iter) \
731
+ ((void) 0)
732
+ #define ResetTupleHashIterator(htable, iter) \
733
+ InitTupleHashIterator(htable, iter)
734
+ #define ScanTupleHashTable(htable, iter) \
735
+ tuplehash_iterate(htable->hashtab, iter)
736
+
737
+
738
+ /* ----------------------------------------------------------------
739
+ * Expression State Nodes
740
+ *
741
+ * Formerly, there was a separate executor expression state node corresponding
742
+ * to each node in a planned expression tree. That's no longer the case; for
743
+ * common expression node types, all the execution info is embedded into
744
+ * step(s) in a single ExprState node. But we still have a few executor state
745
+ * node types for selected expression node types, mostly those in which info
746
+ * has to be shared with other parts of the execution state tree.
747
+ * ----------------------------------------------------------------
748
+ */
749
+
750
+ /* ----------------
751
+ * AggrefExprState node
752
+ * ----------------
753
+ */
754
+ typedef struct AggrefExprState
755
+ {
756
+ NodeTag type;
757
+ Aggref *aggref; /* expression plan node */
758
+ int aggno; /* ID number for agg within its plan node */
759
+ } AggrefExprState;
760
+
761
+ /* ----------------
762
+ * WindowFuncExprState node
763
+ * ----------------
764
+ */
765
+ typedef struct WindowFuncExprState
766
+ {
767
+ NodeTag type;
768
+ WindowFunc *wfunc; /* expression plan node */
769
+ List *args; /* ExprStates for argument expressions */
770
+ ExprState *aggfilter; /* FILTER expression */
771
+ int wfuncno; /* ID number for wfunc within its plan node */
772
+ } WindowFuncExprState;
773
+
774
+
775
+ /* ----------------
776
+ * SetExprState node
777
+ *
778
+ * State for evaluating a potentially set-returning expression (like FuncExpr
779
+ * or OpExpr). In some cases, like some of the expressions in ROWS FROM(...)
780
+ * the expression might not be a SRF, but nonetheless it uses the same
781
+ * machinery as SRFs; it will be treated as a SRF returning a single row.
782
+ * ----------------
783
+ */
784
+ typedef struct SetExprState
785
+ {
786
+ NodeTag type;
787
+ Expr *expr; /* expression plan node */
788
+ List *args; /* ExprStates for argument expressions */
789
+
790
+ /*
791
+ * In ROWS FROM, functions can be inlined, removing the FuncExpr normally
792
+ * inside. In such a case this is the compiled expression (which cannot
793
+ * return a set), which'll be evaluated using regular ExecEvalExpr().
794
+ */
795
+ ExprState *elidedFuncState;
796
+
797
+ /*
798
+ * Function manager's lookup info for the target function. If func.fn_oid
799
+ * is InvalidOid, we haven't initialized it yet (nor any of the following
800
+ * fields, except funcReturnsSet).
801
+ */
802
+ FmgrInfo func;
803
+
804
+ /*
805
+ * For a set-returning function (SRF) that returns a tuplestore, we keep
806
+ * the tuplestore here and dole out the result rows one at a time. The
807
+ * slot holds the row currently being returned.
808
+ */
809
+ Tuplestorestate *funcResultStore;
810
+ TupleTableSlot *funcResultSlot;
811
+
812
+ /*
813
+ * In some cases we need to compute a tuple descriptor for the function's
814
+ * output. If so, it's stored here.
815
+ */
816
+ TupleDesc funcResultDesc;
817
+ bool funcReturnsTuple; /* valid when funcResultDesc isn't NULL */
818
+
819
+ /*
820
+ * Remember whether the function is declared to return a set. This is set
821
+ * by ExecInitExpr, and is valid even before the FmgrInfo is set up.
822
+ */
823
+ bool funcReturnsSet;
824
+
825
+ /*
826
+ * setArgsValid is true when we are evaluating a set-returning function
827
+ * that uses value-per-call mode and we are in the middle of a call
828
+ * series; we want to pass the same argument values to the function again
829
+ * (and again, until it returns ExprEndResult). This indicates that
830
+ * fcinfo_data already contains valid argument data.
831
+ */
832
+ bool setArgsValid;
833
+
834
+ /*
835
+ * Flag to remember whether we have registered a shutdown callback for
836
+ * this SetExprState. We do so only if funcResultStore or setArgsValid
837
+ * has been set at least once (since all the callback is for is to release
838
+ * the tuplestore or clear setArgsValid).
839
+ */
840
+ bool shutdown_reg; /* a shutdown callback is registered */
841
+
842
+ /*
843
+ * Call parameter structure for the function. This has been initialized
844
+ * (by InitFunctionCallInfoData) if func.fn_oid is valid. It also saves
845
+ * argument values between calls, when setArgsValid is true.
846
+ */
847
+ FunctionCallInfo fcinfo;
848
+ } SetExprState;
849
+
850
+ /* ----------------
851
+ * SubPlanState node
852
+ * ----------------
853
+ */
854
+ typedef struct SubPlanState
855
+ {
856
+ NodeTag type;
857
+ SubPlan *subplan; /* expression plan node */
858
+ struct PlanState *planstate; /* subselect plan's state tree */
859
+ struct PlanState *parent; /* parent plan node's state tree */
860
+ ExprState *testexpr; /* state of combining expression */
861
+ List *args; /* states of argument expression(s) */
862
+ HeapTuple curTuple; /* copy of most recent tuple from subplan */
863
+ Datum curArray; /* most recent array from ARRAY() subplan */
864
+ /* these are used when hashing the subselect's output: */
865
+ TupleDesc descRight; /* subselect desc after projection */
866
+ ProjectionInfo *projLeft; /* for projecting lefthand exprs */
867
+ ProjectionInfo *projRight; /* for projecting subselect output */
868
+ TupleHashTable hashtable; /* hash table for no-nulls subselect rows */
869
+ TupleHashTable hashnulls; /* hash table for rows with null(s) */
870
+ bool havehashrows; /* true if hashtable is not empty */
871
+ bool havenullrows; /* true if hashnulls is not empty */
872
+ MemoryContext hashtablecxt; /* memory context containing hash tables */
873
+ MemoryContext hashtempcxt; /* temp memory context for hash tables */
874
+ ExprContext *innerecontext; /* econtext for computing inner tuples */
875
+ int numCols; /* number of columns being hashed */
876
+ /* each of the remaining fields is an array of length numCols: */
877
+ AttrNumber *keyColIdx; /* control data for hash tables */
878
+ Oid *tab_eq_funcoids; /* equality func oids for table
879
+ * datatype(s) */
880
+ Oid *tab_collations; /* collations for hash and comparison */
881
+ FmgrInfo *tab_hash_funcs; /* hash functions for table datatype(s) */
882
+ FmgrInfo *tab_eq_funcs; /* equality functions for table datatype(s) */
883
+ FmgrInfo *lhs_hash_funcs; /* hash functions for lefthand datatype(s) */
884
+ FmgrInfo *cur_eq_funcs; /* equality functions for LHS vs. table */
885
+ ExprState *cur_eq_comp; /* equality comparator for LHS vs. table */
886
+ } SubPlanState;
887
+
888
+ /* ----------------
889
+ * AlternativeSubPlanState node
890
+ * ----------------
891
+ */
892
+ typedef struct AlternativeSubPlanState
893
+ {
894
+ NodeTag type;
895
+ AlternativeSubPlan *subplan; /* expression plan node */
896
+ List *subplans; /* SubPlanStates of alternative subplans */
897
+ int active; /* list index of the one we're using */
898
+ } AlternativeSubPlanState;
899
+
900
+ /*
901
+ * DomainConstraintState - one item to check during CoerceToDomain
902
+ *
903
+ * Note: we consider this to be part of an ExprState tree, so we give it
904
+ * a name following the xxxState convention. But there's no directly
905
+ * associated plan-tree node.
906
+ */
907
+ typedef enum DomainConstraintType
908
+ {
909
+ DOM_CONSTRAINT_NOTNULL,
910
+ DOM_CONSTRAINT_CHECK
911
+ } DomainConstraintType;
912
+
913
+ typedef struct DomainConstraintState
914
+ {
915
+ NodeTag type;
916
+ DomainConstraintType constrainttype; /* constraint type */
917
+ char *name; /* name of constraint (for error msgs) */
918
+ Expr *check_expr; /* for CHECK, a boolean expression */
919
+ ExprState *check_exprstate; /* check_expr's eval state, or NULL */
920
+ } DomainConstraintState;
921
+
922
+
923
+ /* ----------------------------------------------------------------
924
+ * Executor State Trees
925
+ *
926
+ * An executing query has a PlanState tree paralleling the Plan tree
927
+ * that describes the plan.
928
+ * ----------------------------------------------------------------
929
+ */
930
+
931
+ /* ----------------
932
+ * ExecProcNodeMtd
933
+ *
934
+ * This is the method called by ExecProcNode to return the next tuple
935
+ * from an executor node. It returns NULL, or an empty TupleTableSlot,
936
+ * if no more tuples are available.
937
+ * ----------------
938
+ */
939
+ typedef TupleTableSlot *(*ExecProcNodeMtd) (struct PlanState *pstate);
940
+
941
+ /* ----------------
942
+ * PlanState node
943
+ *
944
+ * We never actually instantiate any PlanState nodes; this is just the common
945
+ * abstract superclass for all PlanState-type nodes.
946
+ * ----------------
947
+ */
948
+ typedef struct PlanState
949
+ {
950
+ NodeTag type;
951
+
952
+ Plan *plan; /* associated Plan node */
953
+
954
+ EState *state; /* at execution time, states of individual
955
+ * nodes point to one EState for the whole
956
+ * top-level plan */
957
+
958
+ ExecProcNodeMtd ExecProcNode; /* function to return next tuple */
959
+ ExecProcNodeMtd ExecProcNodeReal; /* actual function, if above is a
960
+ * wrapper */
961
+
962
+ Instrumentation *instrument; /* Optional runtime stats for this node */
963
+ WorkerInstrumentation *worker_instrument; /* per-worker instrumentation */
964
+
965
+ /* Per-worker JIT instrumentation */
966
+ struct SharedJitInstrumentation *worker_jit_instrument;
967
+
968
+ /*
969
+ * Common structural data for all Plan types. These links to subsidiary
970
+ * state trees parallel links in the associated plan tree (except for the
971
+ * subPlan list, which does not exist in the plan tree).
972
+ */
973
+ ExprState *qual; /* boolean qual condition */
974
+ struct PlanState *lefttree; /* input plan tree(s) */
975
+ struct PlanState *righttree;
976
+
977
+ List *initPlan; /* Init SubPlanState nodes (un-correlated expr
978
+ * subselects) */
979
+ List *subPlan; /* SubPlanState nodes in my expressions */
980
+
981
+ /*
982
+ * State for management of parameter-change-driven rescanning
983
+ */
984
+ Bitmapset *chgParam; /* set of IDs of changed Params */
985
+
986
+ /*
987
+ * Other run-time state needed by most if not all node types.
988
+ */
989
+ TupleDesc ps_ResultTupleDesc; /* node's return type */
990
+ TupleTableSlot *ps_ResultTupleSlot; /* slot for my result tuples */
991
+ ExprContext *ps_ExprContext; /* node's expression-evaluation context */
992
+ ProjectionInfo *ps_ProjInfo; /* info for doing tuple projection */
993
+
994
+ /*
995
+ * Scanslot's descriptor if known. This is a bit of a hack, but otherwise
996
+ * it's hard for expression compilation to optimize based on the
997
+ * descriptor, without encoding knowledge about all executor nodes.
998
+ */
999
+ TupleDesc scandesc;
1000
+
1001
+ /*
1002
+ * Define the slot types for inner, outer and scanslots for expression
1003
+ * contexts with this state as a parent. If *opsset is set, then
1004
+ * *opsfixed indicates whether *ops is guaranteed to be the type of slot
1005
+ * used. That means that every slot in the corresponding
1006
+ * ExprContext.ecxt_*tuple will point to a slot of that type, while
1007
+ * evaluating the expression. If *opsfixed is false, but *ops is set,
1008
+ * that indicates the most likely type of slot.
1009
+ *
1010
+ * The scan* fields are set by ExecInitScanTupleSlot(). If that's not
1011
+ * called, nodes can initialize the fields themselves.
1012
+ *
1013
+ * If outer/inneropsset is false, the information is inferred on-demand
1014
+ * using ExecGetResultSlotOps() on ->righttree/lefttree, using the
1015
+ * corresponding node's resultops* fields.
1016
+ *
1017
+ * The result* fields are automatically set when ExecInitResultSlot is
1018
+ * used (be it directly or when the slot is created by
1019
+ * ExecAssignScanProjectionInfo() /
1020
+ * ExecConditionalAssignProjectionInfo()). If no projection is necessary
1021
+ * ExecConditionalAssignProjectionInfo() defaults those fields to the scan
1022
+ * operations.
1023
+ */
1024
+ const TupleTableSlotOps *scanops;
1025
+ const TupleTableSlotOps *outerops;
1026
+ const TupleTableSlotOps *innerops;
1027
+ const TupleTableSlotOps *resultops;
1028
+ bool scanopsfixed;
1029
+ bool outeropsfixed;
1030
+ bool inneropsfixed;
1031
+ bool resultopsfixed;
1032
+ bool scanopsset;
1033
+ bool outeropsset;
1034
+ bool inneropsset;
1035
+ bool resultopsset;
1036
+ } PlanState;
1037
+
1038
+ /* ----------------
1039
+ * these are defined to avoid confusion problems with "left"
1040
+ * and "right" and "inner" and "outer". The convention is that
1041
+ * the "left" plan is the "outer" plan and the "right" plan is
1042
+ * the inner plan, but these make the code more readable.
1043
+ * ----------------
1044
+ */
1045
+ #define innerPlanState(node) (((PlanState *)(node))->righttree)
1046
+ #define outerPlanState(node) (((PlanState *)(node))->lefttree)
1047
+
1048
+ /* Macros for inline access to certain instrumentation counters */
1049
+ #define InstrCountTuples2(node, delta) \
1050
+ do { \
1051
+ if (((PlanState *)(node))->instrument) \
1052
+ ((PlanState *)(node))->instrument->ntuples2 += (delta); \
1053
+ } while (0)
1054
+ #define InstrCountFiltered1(node, delta) \
1055
+ do { \
1056
+ if (((PlanState *)(node))->instrument) \
1057
+ ((PlanState *)(node))->instrument->nfiltered1 += (delta); \
1058
+ } while(0)
1059
+ #define InstrCountFiltered2(node, delta) \
1060
+ do { \
1061
+ if (((PlanState *)(node))->instrument) \
1062
+ ((PlanState *)(node))->instrument->nfiltered2 += (delta); \
1063
+ } while(0)
1064
+
1065
+ /*
1066
+ * EPQState is state for executing an EvalPlanQual recheck on a candidate
1067
+ * tuples e.g. in ModifyTable or LockRows.
1068
+ *
1069
+ * To execute EPQ a separate EState is created (stored in ->recheckestate),
1070
+ * which shares some resources, like the rangetable, with the main query's
1071
+ * EState (stored in ->parentestate). The (sub-)tree of the plan that needs to
1072
+ * be rechecked (in ->plan), is separately initialized (into
1073
+ * ->recheckplanstate), but shares plan nodes with the corresponding nodes in
1074
+ * the main query. The scan nodes in that separate executor tree are changed
1075
+ * to return only the current tuple of interest for the respective
1076
+ * table. Those tuples are either provided by the caller (using
1077
+ * EvalPlanQualSlot), and/or found using the rowmark mechanism (non-locking
1078
+ * rowmarks by the EPQ machinery itself, locking ones by the caller).
1079
+ *
1080
+ * While the plan to be checked may be changed using EvalPlanQualSetPlan() -
1081
+ * e.g. so all source plans for a ModifyTable node can be processed - all such
1082
+ * plans need to share the same EState.
1083
+ */
1084
+ typedef struct EPQState
1085
+ {
1086
+ /* Initialized at EvalPlanQualInit() time: */
1087
+
1088
+ EState *parentestate; /* main query's EState */
1089
+ int epqParam; /* ID of Param to force scan node re-eval */
1090
+
1091
+ /*
1092
+ * Tuples to be substituted by scan nodes. They need to set up, before
1093
+ * calling EvalPlanQual()/EvalPlanQualNext(), into the slot returned by
1094
+ * EvalPlanQualSlot(scanrelid). The array is indexed by scanrelid - 1.
1095
+ */
1096
+ List *tuple_table; /* tuple table for relsubs_slot */
1097
+ TupleTableSlot **relsubs_slot;
1098
+
1099
+ /*
1100
+ * Initialized by EvalPlanQualInit(), may be changed later with
1101
+ * EvalPlanQualSetPlan():
1102
+ */
1103
+
1104
+ Plan *plan; /* plan tree to be executed */
1105
+ List *arowMarks; /* ExecAuxRowMarks (non-locking only) */
1106
+
1107
+
1108
+ /*
1109
+ * The original output tuple to be rechecked. Set by
1110
+ * EvalPlanQualSetSlot(), before EvalPlanQualNext() or EvalPlanQual() may
1111
+ * be called.
1112
+ */
1113
+ TupleTableSlot *origslot;
1114
+
1115
+
1116
+ /* Initialized or reset by EvalPlanQualBegin(): */
1117
+
1118
+ EState *recheckestate; /* EState for EPQ execution, see above */
1119
+
1120
+ /*
1121
+ * Rowmarks that can be fetched on-demand using
1122
+ * EvalPlanQualFetchRowMark(), indexed by scanrelid - 1. Only non-locking
1123
+ * rowmarks.
1124
+ */
1125
+ ExecAuxRowMark **relsubs_rowmark;
1126
+
1127
+ /*
1128
+ * True if a relation's EPQ tuple has been fetched for relation, indexed
1129
+ * by scanrelid - 1.
1130
+ */
1131
+ bool *relsubs_done;
1132
+
1133
+ PlanState *recheckplanstate; /* EPQ specific exec nodes, for ->plan */
1134
+ } EPQState;
1135
+
1136
+
1137
+ /* ----------------
1138
+ * ResultState information
1139
+ * ----------------
1140
+ */
1141
+ typedef struct ResultState
1142
+ {
1143
+ PlanState ps; /* its first field is NodeTag */
1144
+ ExprState *resconstantqual;
1145
+ bool rs_done; /* are we done? */
1146
+ bool rs_checkqual; /* do we need to check the qual? */
1147
+ } ResultState;
1148
+
1149
+ /* ----------------
1150
+ * ProjectSetState information
1151
+ *
1152
+ * Note: at least one of the "elems" will be a SetExprState; the rest are
1153
+ * regular ExprStates.
1154
+ * ----------------
1155
+ */
1156
+ typedef struct ProjectSetState
1157
+ {
1158
+ PlanState ps; /* its first field is NodeTag */
1159
+ Node **elems; /* array of expression states */
1160
+ ExprDoneCond *elemdone; /* array of per-SRF is-done states */
1161
+ int nelems; /* length of elemdone[] array */
1162
+ bool pending_srf_tuples; /* still evaluating srfs in tlist? */
1163
+ MemoryContext argcontext; /* context for SRF arguments */
1164
+ } ProjectSetState;
1165
+
1166
+ /* ----------------
1167
+ * ModifyTableState information
1168
+ * ----------------
1169
+ */
1170
+ typedef struct ModifyTableState
1171
+ {
1172
+ PlanState ps; /* its first field is NodeTag */
1173
+ CmdType operation; /* INSERT, UPDATE, or DELETE */
1174
+ bool canSetTag; /* do we set the command tag/es_processed? */
1175
+ bool mt_done; /* are we done? */
1176
+ PlanState **mt_plans; /* subplans (one per target rel) */
1177
+ int mt_nplans; /* number of plans in the array */
1178
+ int mt_whichplan; /* which one is being executed (0..n-1) */
1179
+ TupleTableSlot **mt_scans; /* input tuple corresponding to underlying
1180
+ * plans */
1181
+ ResultRelInfo *resultRelInfo; /* per-subplan target relations */
1182
+ ResultRelInfo *rootResultRelInfo; /* root target relation (partitioned
1183
+ * table root) */
1184
+ List **mt_arowmarks; /* per-subplan ExecAuxRowMark lists */
1185
+ EPQState mt_epqstate; /* for evaluating EvalPlanQual rechecks */
1186
+ bool fireBSTriggers; /* do we need to fire stmt triggers? */
1187
+
1188
+ /*
1189
+ * Slot for storing tuples in the root partitioned table's rowtype during
1190
+ * an UPDATE of a partitioned table.
1191
+ */
1192
+ TupleTableSlot *mt_root_tuple_slot;
1193
+
1194
+ /* Tuple-routing support info */
1195
+ struct PartitionTupleRouting *mt_partition_tuple_routing;
1196
+
1197
+ /* controls transition table population for specified operation */
1198
+ struct TransitionCaptureState *mt_transition_capture;
1199
+
1200
+ /* controls transition table population for INSERT...ON CONFLICT UPDATE */
1201
+ struct TransitionCaptureState *mt_oc_transition_capture;
1202
+
1203
+ /* Per plan map for tuple conversion from child to root */
1204
+ TupleConversionMap **mt_per_subplan_tupconv_maps;
1205
+ } ModifyTableState;
1206
+
1207
+ /* ----------------
1208
+ * AppendState information
1209
+ *
1210
+ * nplans how many plans are in the array
1211
+ * whichplan which plan is being executed (0 .. n-1), or a
1212
+ * special negative value. See nodeAppend.c.
1213
+ * prune_state details required to allow partitions to be
1214
+ * eliminated from the scan, or NULL if not possible.
1215
+ * valid_subplans for runtime pruning, valid appendplans indexes to
1216
+ * scan.
1217
+ * ----------------
1218
+ */
1219
+
1220
+ struct AppendState;
1221
+ typedef struct AppendState AppendState;
1222
+ struct ParallelAppendState;
1223
+ typedef struct ParallelAppendState ParallelAppendState;
1224
+ struct PartitionPruneState;
1225
+
1226
+ struct AppendState
1227
+ {
1228
+ PlanState ps; /* its first field is NodeTag */
1229
+ PlanState **appendplans; /* array of PlanStates for my inputs */
1230
+ int as_nplans;
1231
+ int as_whichplan;
1232
+ int as_first_partial_plan; /* Index of 'appendplans' containing
1233
+ * the first partial plan */
1234
+ ParallelAppendState *as_pstate; /* parallel coordination info */
1235
+ Size pstate_len; /* size of parallel coordination info */
1236
+ struct PartitionPruneState *as_prune_state;
1237
+ Bitmapset *as_valid_subplans;
1238
+ bool (*choose_next_subplan) (AppendState *);
1239
+ };
1240
+
1241
+ /* ----------------
1242
+ * MergeAppendState information
1243
+ *
1244
+ * nplans how many plans are in the array
1245
+ * nkeys number of sort key columns
1246
+ * sortkeys sort keys in SortSupport representation
1247
+ * slots current output tuple of each subplan
1248
+ * heap heap of active tuples
1249
+ * initialized true if we have fetched first tuple from each subplan
1250
+ * prune_state details required to allow partitions to be
1251
+ * eliminated from the scan, or NULL if not possible.
1252
+ * valid_subplans for runtime pruning, valid mergeplans indexes to
1253
+ * scan.
1254
+ * ----------------
1255
+ */
1256
+ typedef struct MergeAppendState
1257
+ {
1258
+ PlanState ps; /* its first field is NodeTag */
1259
+ PlanState **mergeplans; /* array of PlanStates for my inputs */
1260
+ int ms_nplans;
1261
+ int ms_nkeys;
1262
+ SortSupport ms_sortkeys; /* array of length ms_nkeys */
1263
+ TupleTableSlot **ms_slots; /* array of length ms_nplans */
1264
+ struct binaryheap *ms_heap; /* binary heap of slot indices */
1265
+ bool ms_initialized; /* are subplans started? */
1266
+ struct PartitionPruneState *ms_prune_state;
1267
+ Bitmapset *ms_valid_subplans;
1268
+ } MergeAppendState;
1269
+
1270
+ /* ----------------
1271
+ * RecursiveUnionState information
1272
+ *
1273
+ * RecursiveUnionState is used for performing a recursive union.
1274
+ *
1275
+ * recursing T when we're done scanning the non-recursive term
1276
+ * intermediate_empty T if intermediate_table is currently empty
1277
+ * working_table working table (to be scanned by recursive term)
1278
+ * intermediate_table current recursive output (next generation of WT)
1279
+ * ----------------
1280
+ */
1281
+ typedef struct RecursiveUnionState
1282
+ {
1283
+ PlanState ps; /* its first field is NodeTag */
1284
+ bool recursing;
1285
+ bool intermediate_empty;
1286
+ Tuplestorestate *working_table;
1287
+ Tuplestorestate *intermediate_table;
1288
+ /* Remaining fields are unused in UNION ALL case */
1289
+ Oid *eqfuncoids; /* per-grouping-field equality fns */
1290
+ FmgrInfo *hashfunctions; /* per-grouping-field hash fns */
1291
+ MemoryContext tempContext; /* short-term context for comparisons */
1292
+ TupleHashTable hashtable; /* hash table for tuples already seen */
1293
+ MemoryContext tableContext; /* memory context containing hash table */
1294
+ } RecursiveUnionState;
1295
+
1296
+ /* ----------------
1297
+ * BitmapAndState information
1298
+ * ----------------
1299
+ */
1300
+ typedef struct BitmapAndState
1301
+ {
1302
+ PlanState ps; /* its first field is NodeTag */
1303
+ PlanState **bitmapplans; /* array of PlanStates for my inputs */
1304
+ int nplans; /* number of input plans */
1305
+ } BitmapAndState;
1306
+
1307
+ /* ----------------
1308
+ * BitmapOrState information
1309
+ * ----------------
1310
+ */
1311
+ typedef struct BitmapOrState
1312
+ {
1313
+ PlanState ps; /* its first field is NodeTag */
1314
+ PlanState **bitmapplans; /* array of PlanStates for my inputs */
1315
+ int nplans; /* number of input plans */
1316
+ } BitmapOrState;
1317
+
1318
+ /* ----------------------------------------------------------------
1319
+ * Scan State Information
1320
+ * ----------------------------------------------------------------
1321
+ */
1322
+
1323
+ /* ----------------
1324
+ * ScanState information
1325
+ *
1326
+ * ScanState extends PlanState for node types that represent
1327
+ * scans of an underlying relation. It can also be used for nodes
1328
+ * that scan the output of an underlying plan node --- in that case,
1329
+ * only ScanTupleSlot is actually useful, and it refers to the tuple
1330
+ * retrieved from the subplan.
1331
+ *
1332
+ * currentRelation relation being scanned (NULL if none)
1333
+ * currentScanDesc current scan descriptor for scan (NULL if none)
1334
+ * ScanTupleSlot pointer to slot in tuple table holding scan tuple
1335
+ * ----------------
1336
+ */
1337
+ typedef struct ScanState
1338
+ {
1339
+ PlanState ps; /* its first field is NodeTag */
1340
+ Relation ss_currentRelation;
1341
+ struct TableScanDescData *ss_currentScanDesc;
1342
+ TupleTableSlot *ss_ScanTupleSlot;
1343
+ } ScanState;
1344
+
1345
+ /* ----------------
1346
+ * SeqScanState information
1347
+ * ----------------
1348
+ */
1349
+ typedef struct SeqScanState
1350
+ {
1351
+ ScanState ss; /* its first field is NodeTag */
1352
+ Size pscan_len; /* size of parallel heap scan descriptor */
1353
+ } SeqScanState;
1354
+
1355
+ /* ----------------
1356
+ * SampleScanState information
1357
+ * ----------------
1358
+ */
1359
+ typedef struct SampleScanState
1360
+ {
1361
+ ScanState ss;
1362
+ List *args; /* expr states for TABLESAMPLE params */
1363
+ ExprState *repeatable; /* expr state for REPEATABLE expr */
1364
+ /* use struct pointer to avoid including tsmapi.h here */
1365
+ struct TsmRoutine *tsmroutine; /* descriptor for tablesample method */
1366
+ void *tsm_state; /* tablesample method can keep state here */
1367
+ bool use_bulkread; /* use bulkread buffer access strategy? */
1368
+ bool use_pagemode; /* use page-at-a-time visibility checking? */
1369
+ bool begun; /* false means need to call BeginSampleScan */
1370
+ uint32 seed; /* random seed */
1371
+ int64 donetuples; /* number of tuples already returned */
1372
+ bool haveblock; /* has a block for sampling been determined */
1373
+ bool done; /* exhausted all tuples? */
1374
+ } SampleScanState;
1375
+
1376
+ /*
1377
+ * These structs store information about index quals that don't have simple
1378
+ * constant right-hand sides. See comments for ExecIndexBuildScanKeys()
1379
+ * for discussion.
1380
+ */
1381
+ typedef struct
1382
+ {
1383
+ struct ScanKeyData *scan_key; /* scankey to put value into */
1384
+ ExprState *key_expr; /* expr to evaluate to get value */
1385
+ bool key_toastable; /* is expr's result a toastable datatype? */
1386
+ } IndexRuntimeKeyInfo;
1387
+
1388
+ typedef struct
1389
+ {
1390
+ struct ScanKeyData *scan_key; /* scankey to put value into */
1391
+ ExprState *array_expr; /* expr to evaluate to get array value */
1392
+ int next_elem; /* next array element to use */
1393
+ int num_elems; /* number of elems in current array value */
1394
+ Datum *elem_values; /* array of num_elems Datums */
1395
+ bool *elem_nulls; /* array of num_elems is-null flags */
1396
+ } IndexArrayKeyInfo;
1397
+
1398
+ /* ----------------
1399
+ * IndexScanState information
1400
+ *
1401
+ * indexqualorig execution state for indexqualorig expressions
1402
+ * indexorderbyorig execution state for indexorderbyorig expressions
1403
+ * ScanKeys Skey structures for index quals
1404
+ * NumScanKeys number of ScanKeys
1405
+ * OrderByKeys Skey structures for index ordering operators
1406
+ * NumOrderByKeys number of OrderByKeys
1407
+ * RuntimeKeys info about Skeys that must be evaluated at runtime
1408
+ * NumRuntimeKeys number of RuntimeKeys
1409
+ * RuntimeKeysReady true if runtime Skeys have been computed
1410
+ * RuntimeContext expr context for evaling runtime Skeys
1411
+ * RelationDesc index relation descriptor
1412
+ * ScanDesc index scan descriptor
1413
+ *
1414
+ * ReorderQueue tuples that need reordering due to re-check
1415
+ * ReachedEnd have we fetched all tuples from index already?
1416
+ * OrderByValues values of ORDER BY exprs of last fetched tuple
1417
+ * OrderByNulls null flags for OrderByValues
1418
+ * SortSupport for reordering ORDER BY exprs
1419
+ * OrderByTypByVals is the datatype of order by expression pass-by-value?
1420
+ * OrderByTypLens typlens of the datatypes of order by expressions
1421
+ * PscanLen size of parallel index scan descriptor
1422
+ * ----------------
1423
+ */
1424
+ typedef struct IndexScanState
1425
+ {
1426
+ ScanState ss; /* its first field is NodeTag */
1427
+ ExprState *indexqualorig;
1428
+ List *indexorderbyorig;
1429
+ struct ScanKeyData *iss_ScanKeys;
1430
+ int iss_NumScanKeys;
1431
+ struct ScanKeyData *iss_OrderByKeys;
1432
+ int iss_NumOrderByKeys;
1433
+ IndexRuntimeKeyInfo *iss_RuntimeKeys;
1434
+ int iss_NumRuntimeKeys;
1435
+ bool iss_RuntimeKeysReady;
1436
+ ExprContext *iss_RuntimeContext;
1437
+ Relation iss_RelationDesc;
1438
+ struct IndexScanDescData *iss_ScanDesc;
1439
+
1440
+ /* These are needed for re-checking ORDER BY expr ordering */
1441
+ pairingheap *iss_ReorderQueue;
1442
+ bool iss_ReachedEnd;
1443
+ Datum *iss_OrderByValues;
1444
+ bool *iss_OrderByNulls;
1445
+ SortSupport iss_SortSupport;
1446
+ bool *iss_OrderByTypByVals;
1447
+ int16 *iss_OrderByTypLens;
1448
+ Size iss_PscanLen;
1449
+ } IndexScanState;
1450
+
1451
+ /* ----------------
1452
+ * IndexOnlyScanState information
1453
+ *
1454
+ * indexqual execution state for indexqual expressions
1455
+ * ScanKeys Skey structures for index quals
1456
+ * NumScanKeys number of ScanKeys
1457
+ * OrderByKeys Skey structures for index ordering operators
1458
+ * NumOrderByKeys number of OrderByKeys
1459
+ * RuntimeKeys info about Skeys that must be evaluated at runtime
1460
+ * NumRuntimeKeys number of RuntimeKeys
1461
+ * RuntimeKeysReady true if runtime Skeys have been computed
1462
+ * RuntimeContext expr context for evaling runtime Skeys
1463
+ * RelationDesc index relation descriptor
1464
+ * ScanDesc index scan descriptor
1465
+ * TableSlot slot for holding tuples fetched from the table
1466
+ * VMBuffer buffer in use for visibility map testing, if any
1467
+ * PscanLen size of parallel index-only scan descriptor
1468
+ * ----------------
1469
+ */
1470
+ typedef struct IndexOnlyScanState
1471
+ {
1472
+ ScanState ss; /* its first field is NodeTag */
1473
+ ExprState *indexqual;
1474
+ struct ScanKeyData *ioss_ScanKeys;
1475
+ int ioss_NumScanKeys;
1476
+ struct ScanKeyData *ioss_OrderByKeys;
1477
+ int ioss_NumOrderByKeys;
1478
+ IndexRuntimeKeyInfo *ioss_RuntimeKeys;
1479
+ int ioss_NumRuntimeKeys;
1480
+ bool ioss_RuntimeKeysReady;
1481
+ ExprContext *ioss_RuntimeContext;
1482
+ Relation ioss_RelationDesc;
1483
+ struct IndexScanDescData *ioss_ScanDesc;
1484
+ TupleTableSlot *ioss_TableSlot;
1485
+ Buffer ioss_VMBuffer;
1486
+ Size ioss_PscanLen;
1487
+ } IndexOnlyScanState;
1488
+
1489
+ /* ----------------
1490
+ * BitmapIndexScanState information
1491
+ *
1492
+ * result bitmap to return output into, or NULL
1493
+ * ScanKeys Skey structures for index quals
1494
+ * NumScanKeys number of ScanKeys
1495
+ * RuntimeKeys info about Skeys that must be evaluated at runtime
1496
+ * NumRuntimeKeys number of RuntimeKeys
1497
+ * ArrayKeys info about Skeys that come from ScalarArrayOpExprs
1498
+ * NumArrayKeys number of ArrayKeys
1499
+ * RuntimeKeysReady true if runtime Skeys have been computed
1500
+ * RuntimeContext expr context for evaling runtime Skeys
1501
+ * RelationDesc index relation descriptor
1502
+ * ScanDesc index scan descriptor
1503
+ * ----------------
1504
+ */
1505
+ typedef struct BitmapIndexScanState
1506
+ {
1507
+ ScanState ss; /* its first field is NodeTag */
1508
+ TIDBitmap *biss_result;
1509
+ struct ScanKeyData *biss_ScanKeys;
1510
+ int biss_NumScanKeys;
1511
+ IndexRuntimeKeyInfo *biss_RuntimeKeys;
1512
+ int biss_NumRuntimeKeys;
1513
+ IndexArrayKeyInfo *biss_ArrayKeys;
1514
+ int biss_NumArrayKeys;
1515
+ bool biss_RuntimeKeysReady;
1516
+ ExprContext *biss_RuntimeContext;
1517
+ Relation biss_RelationDesc;
1518
+ struct IndexScanDescData *biss_ScanDesc;
1519
+ } BitmapIndexScanState;
1520
+
1521
+ /* ----------------
1522
+ * SharedBitmapState information
1523
+ *
1524
+ * BM_INITIAL TIDBitmap creation is not yet started, so first worker
1525
+ * to see this state will set the state to BM_INPROGRESS
1526
+ * and that process will be responsible for creating
1527
+ * TIDBitmap.
1528
+ * BM_INPROGRESS TIDBitmap creation is in progress; workers need to
1529
+ * sleep until it's finished.
1530
+ * BM_FINISHED TIDBitmap creation is done, so now all workers can
1531
+ * proceed to iterate over TIDBitmap.
1532
+ * ----------------
1533
+ */
1534
+ typedef enum
1535
+ {
1536
+ BM_INITIAL,
1537
+ BM_INPROGRESS,
1538
+ BM_FINISHED
1539
+ } SharedBitmapState;
1540
+
1541
+ /* ----------------
1542
+ * ParallelBitmapHeapState information
1543
+ * tbmiterator iterator for scanning current pages
1544
+ * prefetch_iterator iterator for prefetching ahead of current page
1545
+ * mutex mutual exclusion for the prefetching variable
1546
+ * and state
1547
+ * prefetch_pages # pages prefetch iterator is ahead of current
1548
+ * prefetch_target current target prefetch distance
1549
+ * state current state of the TIDBitmap
1550
+ * cv conditional wait variable
1551
+ * phs_snapshot_data snapshot data shared to workers
1552
+ * ----------------
1553
+ */
1554
+ typedef struct ParallelBitmapHeapState
1555
+ {
1556
+ dsa_pointer tbmiterator;
1557
+ dsa_pointer prefetch_iterator;
1558
+ slock_t mutex;
1559
+ int prefetch_pages;
1560
+ int prefetch_target;
1561
+ SharedBitmapState state;
1562
+ ConditionVariable cv;
1563
+ char phs_snapshot_data[FLEXIBLE_ARRAY_MEMBER];
1564
+ } ParallelBitmapHeapState;
1565
+
1566
+ /* ----------------
1567
+ * BitmapHeapScanState information
1568
+ *
1569
+ * bitmapqualorig execution state for bitmapqualorig expressions
1570
+ * tbm bitmap obtained from child index scan(s)
1571
+ * tbmiterator iterator for scanning current pages
1572
+ * tbmres current-page data
1573
+ * can_skip_fetch can we potentially skip tuple fetches in this scan?
1574
+ * return_empty_tuples number of empty tuples to return
1575
+ * vmbuffer buffer for visibility-map lookups
1576
+ * pvmbuffer ditto, for prefetched pages
1577
+ * exact_pages total number of exact pages retrieved
1578
+ * lossy_pages total number of lossy pages retrieved
1579
+ * prefetch_iterator iterator for prefetching ahead of current page
1580
+ * prefetch_pages # pages prefetch iterator is ahead of current
1581
+ * prefetch_target current target prefetch distance
1582
+ * prefetch_maximum maximum value for prefetch_target
1583
+ * pscan_len size of the shared memory for parallel bitmap
1584
+ * initialized is node is ready to iterate
1585
+ * shared_tbmiterator shared iterator
1586
+ * shared_prefetch_iterator shared iterator for prefetching
1587
+ * pstate shared state for parallel bitmap scan
1588
+ * ----------------
1589
+ */
1590
+ typedef struct BitmapHeapScanState
1591
+ {
1592
+ ScanState ss; /* its first field is NodeTag */
1593
+ ExprState *bitmapqualorig;
1594
+ TIDBitmap *tbm;
1595
+ TBMIterator *tbmiterator;
1596
+ TBMIterateResult *tbmres;
1597
+ bool can_skip_fetch;
1598
+ int return_empty_tuples;
1599
+ Buffer vmbuffer;
1600
+ Buffer pvmbuffer;
1601
+ long exact_pages;
1602
+ long lossy_pages;
1603
+ TBMIterator *prefetch_iterator;
1604
+ int prefetch_pages;
1605
+ int prefetch_target;
1606
+ int prefetch_maximum;
1607
+ Size pscan_len;
1608
+ bool initialized;
1609
+ TBMSharedIterator *shared_tbmiterator;
1610
+ TBMSharedIterator *shared_prefetch_iterator;
1611
+ ParallelBitmapHeapState *pstate;
1612
+ } BitmapHeapScanState;
1613
+
1614
+ /* ----------------
1615
+ * TidScanState information
1616
+ *
1617
+ * tidexprs list of TidExpr structs (see nodeTidscan.c)
1618
+ * isCurrentOf scan has a CurrentOfExpr qual
1619
+ * NumTids number of tids in this scan
1620
+ * TidPtr index of currently fetched tid
1621
+ * TidList evaluated item pointers (array of size NumTids)
1622
+ * htup currently-fetched tuple, if any
1623
+ * ----------------
1624
+ */
1625
+ typedef struct TidScanState
1626
+ {
1627
+ ScanState ss; /* its first field is NodeTag */
1628
+ List *tss_tidexprs;
1629
+ bool tss_isCurrentOf;
1630
+ int tss_NumTids;
1631
+ int tss_TidPtr;
1632
+ ItemPointerData *tss_TidList;
1633
+ HeapTupleData tss_htup;
1634
+ } TidScanState;
1635
+
1636
+ /* ----------------
1637
+ * SubqueryScanState information
1638
+ *
1639
+ * SubqueryScanState is used for scanning a sub-query in the range table.
1640
+ * ScanTupleSlot references the current output tuple of the sub-query.
1641
+ * ----------------
1642
+ */
1643
+ typedef struct SubqueryScanState
1644
+ {
1645
+ ScanState ss; /* its first field is NodeTag */
1646
+ PlanState *subplan;
1647
+ } SubqueryScanState;
1648
+
1649
+ /* ----------------
1650
+ * FunctionScanState information
1651
+ *
1652
+ * Function nodes are used to scan the results of a
1653
+ * function appearing in FROM (typically a function returning set).
1654
+ *
1655
+ * eflags node's capability flags
1656
+ * ordinality is this scan WITH ORDINALITY?
1657
+ * simple true if we have 1 function and no ordinality
1658
+ * ordinal current ordinal column value
1659
+ * nfuncs number of functions being executed
1660
+ * funcstates per-function execution states (private in
1661
+ * nodeFunctionscan.c)
1662
+ * argcontext memory context to evaluate function arguments in
1663
+ * ----------------
1664
+ */
1665
+ struct FunctionScanPerFuncState;
1666
+
1667
+ typedef struct FunctionScanState
1668
+ {
1669
+ ScanState ss; /* its first field is NodeTag */
1670
+ int eflags;
1671
+ bool ordinality;
1672
+ bool simple;
1673
+ int64 ordinal;
1674
+ int nfuncs;
1675
+ struct FunctionScanPerFuncState *funcstates; /* array of length nfuncs */
1676
+ MemoryContext argcontext;
1677
+ } FunctionScanState;
1678
+
1679
+ /* ----------------
1680
+ * ValuesScanState information
1681
+ *
1682
+ * ValuesScan nodes are used to scan the results of a VALUES list
1683
+ *
1684
+ * rowcontext per-expression-list context
1685
+ * exprlists array of expression lists being evaluated
1686
+ * exprstatelists array of expression state lists, for SubPlans only
1687
+ * array_len size of above arrays
1688
+ * curr_idx current array index (0-based)
1689
+ *
1690
+ * Note: ss.ps.ps_ExprContext is used to evaluate any qual or projection
1691
+ * expressions attached to the node. We create a second ExprContext,
1692
+ * rowcontext, in which to build the executor expression state for each
1693
+ * Values sublist. Resetting this context lets us get rid of expression
1694
+ * state for each row, avoiding major memory leakage over a long values list.
1695
+ * However, that doesn't work for sublists containing SubPlans, because a
1696
+ * SubPlan has to be connected up to the outer plan tree to work properly.
1697
+ * Therefore, for only those sublists containing SubPlans, we do expression
1698
+ * state construction at executor start, and store those pointers in
1699
+ * exprstatelists[]. NULL entries in that array correspond to simple
1700
+ * subexpressions that are handled as described above.
1701
+ * ----------------
1702
+ */
1703
+ typedef struct ValuesScanState
1704
+ {
1705
+ ScanState ss; /* its first field is NodeTag */
1706
+ ExprContext *rowcontext;
1707
+ List **exprlists;
1708
+ List **exprstatelists;
1709
+ int array_len;
1710
+ int curr_idx;
1711
+ } ValuesScanState;
1712
+
1713
+ /* ----------------
1714
+ * TableFuncScanState node
1715
+ *
1716
+ * Used in table-expression functions like XMLTABLE.
1717
+ * ----------------
1718
+ */
1719
+ typedef struct TableFuncScanState
1720
+ {
1721
+ ScanState ss; /* its first field is NodeTag */
1722
+ ExprState *docexpr; /* state for document expression */
1723
+ ExprState *rowexpr; /* state for row-generating expression */
1724
+ List *colexprs; /* state for column-generating expression */
1725
+ List *coldefexprs; /* state for column default expressions */
1726
+ List *ns_names; /* same as TableFunc.ns_names */
1727
+ List *ns_uris; /* list of states of namespace URI exprs */
1728
+ Bitmapset *notnulls; /* nullability flag for each output column */
1729
+ void *opaque; /* table builder private space */
1730
+ const struct TableFuncRoutine *routine; /* table builder methods */
1731
+ FmgrInfo *in_functions; /* input function for each column */
1732
+ Oid *typioparams; /* typioparam for each column */
1733
+ int64 ordinal; /* row number to be output next */
1734
+ MemoryContext perTableCxt; /* per-table context */
1735
+ Tuplestorestate *tupstore; /* output tuple store */
1736
+ } TableFuncScanState;
1737
+
1738
+ /* ----------------
1739
+ * CteScanState information
1740
+ *
1741
+ * CteScan nodes are used to scan a CommonTableExpr query.
1742
+ *
1743
+ * Multiple CteScan nodes can read out from the same CTE query. We use
1744
+ * a tuplestore to hold rows that have been read from the CTE query but
1745
+ * not yet consumed by all readers.
1746
+ * ----------------
1747
+ */
1748
+ typedef struct CteScanState
1749
+ {
1750
+ ScanState ss; /* its first field is NodeTag */
1751
+ int eflags; /* capability flags to pass to tuplestore */
1752
+ int readptr; /* index of my tuplestore read pointer */
1753
+ PlanState *cteplanstate; /* PlanState for the CTE query itself */
1754
+ /* Link to the "leader" CteScanState (possibly this same node) */
1755
+ struct CteScanState *leader;
1756
+ /* The remaining fields are only valid in the "leader" CteScanState */
1757
+ Tuplestorestate *cte_table; /* rows already read from the CTE query */
1758
+ bool eof_cte; /* reached end of CTE query? */
1759
+ } CteScanState;
1760
+
1761
+ /* ----------------
1762
+ * NamedTuplestoreScanState information
1763
+ *
1764
+ * NamedTuplestoreScan nodes are used to scan a Tuplestore created and
1765
+ * named prior to execution of the query. An example is a transition
1766
+ * table for an AFTER trigger.
1767
+ *
1768
+ * Multiple NamedTuplestoreScan nodes can read out from the same Tuplestore.
1769
+ * ----------------
1770
+ */
1771
+ typedef struct NamedTuplestoreScanState
1772
+ {
1773
+ ScanState ss; /* its first field is NodeTag */
1774
+ int readptr; /* index of my tuplestore read pointer */
1775
+ TupleDesc tupdesc; /* format of the tuples in the tuplestore */
1776
+ Tuplestorestate *relation; /* the rows */
1777
+ } NamedTuplestoreScanState;
1778
+
1779
+ /* ----------------
1780
+ * WorkTableScanState information
1781
+ *
1782
+ * WorkTableScan nodes are used to scan the work table created by
1783
+ * a RecursiveUnion node. We locate the RecursiveUnion node
1784
+ * during executor startup.
1785
+ * ----------------
1786
+ */
1787
+ typedef struct WorkTableScanState
1788
+ {
1789
+ ScanState ss; /* its first field is NodeTag */
1790
+ RecursiveUnionState *rustate;
1791
+ } WorkTableScanState;
1792
+
1793
+ /* ----------------
1794
+ * ForeignScanState information
1795
+ *
1796
+ * ForeignScan nodes are used to scan foreign-data tables.
1797
+ * ----------------
1798
+ */
1799
+ typedef struct ForeignScanState
1800
+ {
1801
+ ScanState ss; /* its first field is NodeTag */
1802
+ ExprState *fdw_recheck_quals; /* original quals not in ss.ps.qual */
1803
+ Size pscan_len; /* size of parallel coordination information */
1804
+ /* use struct pointer to avoid including fdwapi.h here */
1805
+ struct FdwRoutine *fdwroutine;
1806
+ void *fdw_state; /* foreign-data wrapper can keep state here */
1807
+ } ForeignScanState;
1808
+
1809
+ /* ----------------
1810
+ * CustomScanState information
1811
+ *
1812
+ * CustomScan nodes are used to execute custom code within executor.
1813
+ *
1814
+ * Core code must avoid assuming that the CustomScanState is only as large as
1815
+ * the structure declared here; providers are allowed to make it the first
1816
+ * element in a larger structure, and typically would need to do so. The
1817
+ * struct is actually allocated by the CreateCustomScanState method associated
1818
+ * with the plan node. Any additional fields can be initialized there, or in
1819
+ * the BeginCustomScan method.
1820
+ * ----------------
1821
+ */
1822
+ struct CustomExecMethods;
1823
+
1824
+ typedef struct CustomScanState
1825
+ {
1826
+ ScanState ss;
1827
+ uint32 flags; /* mask of CUSTOMPATH_* flags, see
1828
+ * nodes/extensible.h */
1829
+ List *custom_ps; /* list of child PlanState nodes, if any */
1830
+ Size pscan_len; /* size of parallel coordination information */
1831
+ const struct CustomExecMethods *methods;
1832
+ } CustomScanState;
1833
+
1834
+ /* ----------------------------------------------------------------
1835
+ * Join State Information
1836
+ * ----------------------------------------------------------------
1837
+ */
1838
+
1839
+ /* ----------------
1840
+ * JoinState information
1841
+ *
1842
+ * Superclass for state nodes of join plans.
1843
+ * ----------------
1844
+ */
1845
+ typedef struct JoinState
1846
+ {
1847
+ PlanState ps;
1848
+ JoinType jointype;
1849
+ bool single_match; /* True if we should skip to next outer tuple
1850
+ * after finding one inner match */
1851
+ ExprState *joinqual; /* JOIN quals (in addition to ps.qual) */
1852
+ } JoinState;
1853
+
1854
+ /* ----------------
1855
+ * NestLoopState information
1856
+ *
1857
+ * NeedNewOuter true if need new outer tuple on next call
1858
+ * MatchedOuter true if found a join match for current outer tuple
1859
+ * NullInnerTupleSlot prepared null tuple for left outer joins
1860
+ * ----------------
1861
+ */
1862
+ typedef struct NestLoopState
1863
+ {
1864
+ JoinState js; /* its first field is NodeTag */
1865
+ bool nl_NeedNewOuter;
1866
+ bool nl_MatchedOuter;
1867
+ TupleTableSlot *nl_NullInnerTupleSlot;
1868
+ } NestLoopState;
1869
+
1870
+ /* ----------------
1871
+ * MergeJoinState information
1872
+ *
1873
+ * NumClauses number of mergejoinable join clauses
1874
+ * Clauses info for each mergejoinable clause
1875
+ * JoinState current state of ExecMergeJoin state machine
1876
+ * SkipMarkRestore true if we may skip Mark and Restore operations
1877
+ * ExtraMarks true to issue extra Mark operations on inner scan
1878
+ * ConstFalseJoin true if we have a constant-false joinqual
1879
+ * FillOuter true if should emit unjoined outer tuples anyway
1880
+ * FillInner true if should emit unjoined inner tuples anyway
1881
+ * MatchedOuter true if found a join match for current outer tuple
1882
+ * MatchedInner true if found a join match for current inner tuple
1883
+ * OuterTupleSlot slot in tuple table for cur outer tuple
1884
+ * InnerTupleSlot slot in tuple table for cur inner tuple
1885
+ * MarkedTupleSlot slot in tuple table for marked tuple
1886
+ * NullOuterTupleSlot prepared null tuple for right outer joins
1887
+ * NullInnerTupleSlot prepared null tuple for left outer joins
1888
+ * OuterEContext workspace for computing outer tuple's join values
1889
+ * InnerEContext workspace for computing inner tuple's join values
1890
+ * ----------------
1891
+ */
1892
+ /* private in nodeMergejoin.c: */
1893
+ typedef struct MergeJoinClauseData *MergeJoinClause;
1894
+
1895
+ typedef struct MergeJoinState
1896
+ {
1897
+ JoinState js; /* its first field is NodeTag */
1898
+ int mj_NumClauses;
1899
+ MergeJoinClause mj_Clauses; /* array of length mj_NumClauses */
1900
+ int mj_JoinState;
1901
+ bool mj_SkipMarkRestore;
1902
+ bool mj_ExtraMarks;
1903
+ bool mj_ConstFalseJoin;
1904
+ bool mj_FillOuter;
1905
+ bool mj_FillInner;
1906
+ bool mj_MatchedOuter;
1907
+ bool mj_MatchedInner;
1908
+ TupleTableSlot *mj_OuterTupleSlot;
1909
+ TupleTableSlot *mj_InnerTupleSlot;
1910
+ TupleTableSlot *mj_MarkedTupleSlot;
1911
+ TupleTableSlot *mj_NullOuterTupleSlot;
1912
+ TupleTableSlot *mj_NullInnerTupleSlot;
1913
+ ExprContext *mj_OuterEContext;
1914
+ ExprContext *mj_InnerEContext;
1915
+ } MergeJoinState;
1916
+
1917
+ /* ----------------
1918
+ * HashJoinState information
1919
+ *
1920
+ * hashclauses original form of the hashjoin condition
1921
+ * hj_OuterHashKeys the outer hash keys in the hashjoin condition
1922
+ * hj_HashOperators the join operators in the hashjoin condition
1923
+ * hj_HashTable hash table for the hashjoin
1924
+ * (NULL if table not built yet)
1925
+ * hj_CurHashValue hash value for current outer tuple
1926
+ * hj_CurBucketNo regular bucket# for current outer tuple
1927
+ * hj_CurSkewBucketNo skew bucket# for current outer tuple
1928
+ * hj_CurTuple last inner tuple matched to current outer
1929
+ * tuple, or NULL if starting search
1930
+ * (hj_CurXXX variables are undefined if
1931
+ * OuterTupleSlot is empty!)
1932
+ * hj_OuterTupleSlot tuple slot for outer tuples
1933
+ * hj_HashTupleSlot tuple slot for inner (hashed) tuples
1934
+ * hj_NullOuterTupleSlot prepared null tuple for right/full outer joins
1935
+ * hj_NullInnerTupleSlot prepared null tuple for left/full outer joins
1936
+ * hj_FirstOuterTupleSlot first tuple retrieved from outer plan
1937
+ * hj_JoinState current state of ExecHashJoin state machine
1938
+ * hj_MatchedOuter true if found a join match for current outer
1939
+ * hj_OuterNotEmpty true if outer relation known not empty
1940
+ * ----------------
1941
+ */
1942
+
1943
+ /* these structs are defined in executor/hashjoin.h: */
1944
+ typedef struct HashJoinTupleData *HashJoinTuple;
1945
+ typedef struct HashJoinTableData *HashJoinTable;
1946
+
1947
+ typedef struct HashJoinState
1948
+ {
1949
+ JoinState js; /* its first field is NodeTag */
1950
+ ExprState *hashclauses;
1951
+ List *hj_OuterHashKeys; /* list of ExprState nodes */
1952
+ List *hj_HashOperators; /* list of operator OIDs */
1953
+ List *hj_Collations;
1954
+ HashJoinTable hj_HashTable;
1955
+ uint32 hj_CurHashValue;
1956
+ int hj_CurBucketNo;
1957
+ int hj_CurSkewBucketNo;
1958
+ HashJoinTuple hj_CurTuple;
1959
+ TupleTableSlot *hj_OuterTupleSlot;
1960
+ TupleTableSlot *hj_HashTupleSlot;
1961
+ TupleTableSlot *hj_NullOuterTupleSlot;
1962
+ TupleTableSlot *hj_NullInnerTupleSlot;
1963
+ TupleTableSlot *hj_FirstOuterTupleSlot;
1964
+ int hj_JoinState;
1965
+ bool hj_MatchedOuter;
1966
+ bool hj_OuterNotEmpty;
1967
+ } HashJoinState;
1968
+
1969
+
1970
+ /* ----------------------------------------------------------------
1971
+ * Materialization State Information
1972
+ * ----------------------------------------------------------------
1973
+ */
1974
+
1975
+ /* ----------------
1976
+ * MaterialState information
1977
+ *
1978
+ * materialize nodes are used to materialize the results
1979
+ * of a subplan into a temporary file.
1980
+ *
1981
+ * ss.ss_ScanTupleSlot refers to output of underlying plan.
1982
+ * ----------------
1983
+ */
1984
+ typedef struct MaterialState
1985
+ {
1986
+ ScanState ss; /* its first field is NodeTag */
1987
+ int eflags; /* capability flags to pass to tuplestore */
1988
+ bool eof_underlying; /* reached end of underlying plan? */
1989
+ Tuplestorestate *tuplestorestate;
1990
+ } MaterialState;
1991
+
1992
+
1993
+ /* ----------------
1994
+ * When performing sorting by multiple keys, it's possible that the input
1995
+ * dataset is already sorted on a prefix of those keys. We call these
1996
+ * "presorted keys".
1997
+ * PresortedKeyData represents information about one such key.
1998
+ * ----------------
1999
+ */
2000
+ typedef struct PresortedKeyData
2001
+ {
2002
+ FmgrInfo flinfo; /* comparison function info */
2003
+ FunctionCallInfo fcinfo; /* comparison function call info */
2004
+ OffsetNumber attno; /* attribute number in tuple */
2005
+ } PresortedKeyData;
2006
+
2007
+ /* ----------------
2008
+ * Shared memory container for per-worker sort information
2009
+ * ----------------
2010
+ */
2011
+ typedef struct SharedSortInfo
2012
+ {
2013
+ int num_workers;
2014
+ TuplesortInstrumentation sinstrument[FLEXIBLE_ARRAY_MEMBER];
2015
+ } SharedSortInfo;
2016
+
2017
+ /* ----------------
2018
+ * SortState information
2019
+ * ----------------
2020
+ */
2021
+ typedef struct SortState
2022
+ {
2023
+ ScanState ss; /* its first field is NodeTag */
2024
+ bool randomAccess; /* need random access to sort output? */
2025
+ bool bounded; /* is the result set bounded? */
2026
+ int64 bound; /* if bounded, how many tuples are needed */
2027
+ bool sort_Done; /* sort completed yet? */
2028
+ bool bounded_Done; /* value of bounded we did the sort with */
2029
+ int64 bound_Done; /* value of bound we did the sort with */
2030
+ void *tuplesortstate; /* private state of tuplesort.c */
2031
+ bool am_worker; /* are we a worker? */
2032
+ SharedSortInfo *shared_info; /* one entry per worker */
2033
+ } SortState;
2034
+
2035
+ /* ----------------
2036
+ * Instrumentation information for IncrementalSort
2037
+ * ----------------
2038
+ */
2039
+ typedef struct IncrementalSortGroupInfo
2040
+ {
2041
+ int64 groupCount;
2042
+ int64 maxDiskSpaceUsed;
2043
+ int64 totalDiskSpaceUsed;
2044
+ int64 maxMemorySpaceUsed;
2045
+ int64 totalMemorySpaceUsed;
2046
+ bits32 sortMethods; /* bitmask of TuplesortMethod */
2047
+ } IncrementalSortGroupInfo;
2048
+
2049
+ typedef struct IncrementalSortInfo
2050
+ {
2051
+ IncrementalSortGroupInfo fullsortGroupInfo;
2052
+ IncrementalSortGroupInfo prefixsortGroupInfo;
2053
+ } IncrementalSortInfo;
2054
+
2055
+ /* ----------------
2056
+ * Shared memory container for per-worker incremental sort information
2057
+ * ----------------
2058
+ */
2059
+ typedef struct SharedIncrementalSortInfo
2060
+ {
2061
+ int num_workers;
2062
+ IncrementalSortInfo sinfo[FLEXIBLE_ARRAY_MEMBER];
2063
+ } SharedIncrementalSortInfo;
2064
+
2065
+ /* ----------------
2066
+ * IncrementalSortState information
2067
+ * ----------------
2068
+ */
2069
+ typedef enum
2070
+ {
2071
+ INCSORT_LOADFULLSORT,
2072
+ INCSORT_LOADPREFIXSORT,
2073
+ INCSORT_READFULLSORT,
2074
+ INCSORT_READPREFIXSORT,
2075
+ } IncrementalSortExecutionStatus;
2076
+
2077
+ typedef struct IncrementalSortState
2078
+ {
2079
+ ScanState ss; /* its first field is NodeTag */
2080
+ bool bounded; /* is the result set bounded? */
2081
+ int64 bound; /* if bounded, how many tuples are needed */
2082
+ bool outerNodeDone; /* finished fetching tuples from outer node */
2083
+ int64 bound_Done; /* value of bound we did the sort with */
2084
+ IncrementalSortExecutionStatus execution_status;
2085
+ int64 n_fullsort_remaining;
2086
+ Tuplesortstate *fullsort_state; /* private state of tuplesort.c */
2087
+ Tuplesortstate *prefixsort_state; /* private state of tuplesort.c */
2088
+ /* the keys by which the input path is already sorted */
2089
+ PresortedKeyData *presorted_keys;
2090
+
2091
+ IncrementalSortInfo incsort_info;
2092
+
2093
+ /* slot for pivot tuple defining values of presorted keys within group */
2094
+ TupleTableSlot *group_pivot;
2095
+ TupleTableSlot *transfer_tuple;
2096
+ bool am_worker; /* are we a worker? */
2097
+ SharedIncrementalSortInfo *shared_info; /* one entry per worker */
2098
+ } IncrementalSortState;
2099
+
2100
+ /* ---------------------
2101
+ * GroupState information
2102
+ * ---------------------
2103
+ */
2104
+ typedef struct GroupState
2105
+ {
2106
+ ScanState ss; /* its first field is NodeTag */
2107
+ ExprState *eqfunction; /* equality function */
2108
+ bool grp_done; /* indicates completion of Group scan */
2109
+ } GroupState;
2110
+
2111
+ /* ---------------------
2112
+ * per-worker aggregate information
2113
+ * ---------------------
2114
+ */
2115
+ typedef struct AggregateInstrumentation
2116
+ {
2117
+ Size hash_mem_peak; /* peak hash table memory usage */
2118
+ uint64 hash_disk_used; /* kB of disk space used */
2119
+ int hash_batches_used; /* batches used during entire execution */
2120
+ } AggregateInstrumentation;
2121
+
2122
+ /* ----------------
2123
+ * Shared memory container for per-worker aggregate information
2124
+ * ----------------
2125
+ */
2126
+ typedef struct SharedAggInfo
2127
+ {
2128
+ int num_workers;
2129
+ AggregateInstrumentation sinstrument[FLEXIBLE_ARRAY_MEMBER];
2130
+ } SharedAggInfo;
2131
+
2132
+ /* ---------------------
2133
+ * AggState information
2134
+ *
2135
+ * ss.ss_ScanTupleSlot refers to output of underlying plan.
2136
+ *
2137
+ * Note: ss.ps.ps_ExprContext contains ecxt_aggvalues and
2138
+ * ecxt_aggnulls arrays, which hold the computed agg values for the current
2139
+ * input group during evaluation of an Agg node's output tuple(s). We
2140
+ * create a second ExprContext, tmpcontext, in which to evaluate input
2141
+ * expressions and run the aggregate transition functions.
2142
+ * ---------------------
2143
+ */
2144
+ /* these structs are private in nodeAgg.c: */
2145
+ typedef struct AggStatePerAggData *AggStatePerAgg;
2146
+ typedef struct AggStatePerTransData *AggStatePerTrans;
2147
+ typedef struct AggStatePerGroupData *AggStatePerGroup;
2148
+ typedef struct AggStatePerPhaseData *AggStatePerPhase;
2149
+ typedef struct AggStatePerHashData *AggStatePerHash;
2150
+
2151
+ typedef struct AggState
2152
+ {
2153
+ ScanState ss; /* its first field is NodeTag */
2154
+ List *aggs; /* all Aggref nodes in targetlist & quals */
2155
+ int numaggs; /* length of list (could be zero!) */
2156
+ int numtrans; /* number of pertrans items */
2157
+ AggStrategy aggstrategy; /* strategy mode */
2158
+ AggSplit aggsplit; /* agg-splitting mode, see nodes.h */
2159
+ AggStatePerPhase phase; /* pointer to current phase data */
2160
+ int numphases; /* number of phases (including phase 0) */
2161
+ int current_phase; /* current phase number */
2162
+ AggStatePerAgg peragg; /* per-Aggref information */
2163
+ AggStatePerTrans pertrans; /* per-Trans state information */
2164
+ ExprContext *hashcontext; /* econtexts for long-lived data (hashtable) */
2165
+ ExprContext **aggcontexts; /* econtexts for long-lived data (per GS) */
2166
+ ExprContext *tmpcontext; /* econtext for input expressions */
2167
+ #define FIELDNO_AGGSTATE_CURAGGCONTEXT 14
2168
+ ExprContext *curaggcontext; /* currently active aggcontext */
2169
+ AggStatePerAgg curperagg; /* currently active aggregate, if any */
2170
+ #define FIELDNO_AGGSTATE_CURPERTRANS 16
2171
+ AggStatePerTrans curpertrans; /* currently active trans state, if any */
2172
+ bool input_done; /* indicates end of input */
2173
+ bool agg_done; /* indicates completion of Agg scan */
2174
+ int projected_set; /* The last projected grouping set */
2175
+ #define FIELDNO_AGGSTATE_CURRENT_SET 20
2176
+ int current_set; /* The current grouping set being evaluated */
2177
+ Bitmapset *grouped_cols; /* grouped cols in current projection */
2178
+ List *all_grouped_cols; /* list of all grouped cols in DESC order */
2179
+ Bitmapset *colnos_needed; /* all columns needed from the outer plan */
2180
+ int max_colno_needed; /* highest colno needed from outer plan */
2181
+ bool all_cols_needed; /* are all cols from outer plan needed? */
2182
+ /* These fields are for grouping set phase data */
2183
+ int maxsets; /* The max number of sets in any phase */
2184
+ AggStatePerPhase phases; /* array of all phases */
2185
+ Tuplesortstate *sort_in; /* sorted input to phases > 1 */
2186
+ Tuplesortstate *sort_out; /* input is copied here for next phase */
2187
+ TupleTableSlot *sort_slot; /* slot for sort results */
2188
+ /* these fields are used in AGG_PLAIN and AGG_SORTED modes: */
2189
+ AggStatePerGroup *pergroups; /* grouping set indexed array of per-group
2190
+ * pointers */
2191
+ HeapTuple grp_firstTuple; /* copy of first tuple of current group */
2192
+ /* these fields are used in AGG_HASHED and AGG_MIXED modes: */
2193
+ bool table_filled; /* hash table filled yet? */
2194
+ int num_hashes;
2195
+ MemoryContext hash_metacxt; /* memory for hash table itself */
2196
+ struct HashTapeInfo *hash_tapeinfo; /* metadata for spill tapes */
2197
+ struct HashAggSpill *hash_spills; /* HashAggSpill for each grouping set,
2198
+ * exists only during first pass */
2199
+ TupleTableSlot *hash_spill_rslot; /* for reading spill files */
2200
+ TupleTableSlot *hash_spill_wslot; /* for writing spill files */
2201
+ List *hash_batches; /* hash batches remaining to be processed */
2202
+ bool hash_ever_spilled; /* ever spilled during this execution? */
2203
+ bool hash_spill_mode; /* we hit a limit during the current batch
2204
+ * and we must not create new groups */
2205
+ Size hash_mem_limit; /* limit before spilling hash table */
2206
+ uint64 hash_ngroups_limit; /* limit before spilling hash table */
2207
+ int hash_planned_partitions; /* number of partitions planned
2208
+ * for first pass */
2209
+ double hashentrysize; /* estimate revised during execution */
2210
+ Size hash_mem_peak; /* peak hash table memory usage */
2211
+ uint64 hash_ngroups_current; /* number of groups currently in
2212
+ * memory in all hash tables */
2213
+ uint64 hash_disk_used; /* kB of disk space used */
2214
+ int hash_batches_used; /* batches used during entire execution */
2215
+
2216
+ AggStatePerHash perhash; /* array of per-hashtable data */
2217
+ AggStatePerGroup *hash_pergroup; /* grouping set indexed array of
2218
+ * per-group pointers */
2219
+
2220
+ /* support for evaluation of agg input expressions: */
2221
+ #define FIELDNO_AGGSTATE_ALL_PERGROUPS 53
2222
+ AggStatePerGroup *all_pergroups; /* array of first ->pergroups, than
2223
+ * ->hash_pergroup */
2224
+ ProjectionInfo *combinedproj; /* projection machinery */
2225
+ SharedAggInfo *shared_info; /* one entry per worker */
2226
+ } AggState;
2227
+
2228
+ /* ----------------
2229
+ * WindowAggState information
2230
+ * ----------------
2231
+ */
2232
+ /* these structs are private in nodeWindowAgg.c: */
2233
+ typedef struct WindowStatePerFuncData *WindowStatePerFunc;
2234
+ typedef struct WindowStatePerAggData *WindowStatePerAgg;
2235
+
2236
+ typedef struct WindowAggState
2237
+ {
2238
+ ScanState ss; /* its first field is NodeTag */
2239
+
2240
+ /* these fields are filled in by ExecInitExpr: */
2241
+ List *funcs; /* all WindowFunc nodes in targetlist */
2242
+ int numfuncs; /* total number of window functions */
2243
+ int numaggs; /* number that are plain aggregates */
2244
+
2245
+ WindowStatePerFunc perfunc; /* per-window-function information */
2246
+ WindowStatePerAgg peragg; /* per-plain-aggregate information */
2247
+ ExprState *partEqfunction; /* equality funcs for partition columns */
2248
+ ExprState *ordEqfunction; /* equality funcs for ordering columns */
2249
+ Tuplestorestate *buffer; /* stores rows of current partition */
2250
+ int current_ptr; /* read pointer # for current row */
2251
+ int framehead_ptr; /* read pointer # for frame head, if used */
2252
+ int frametail_ptr; /* read pointer # for frame tail, if used */
2253
+ int grouptail_ptr; /* read pointer # for group tail, if used */
2254
+ int64 spooled_rows; /* total # of rows in buffer */
2255
+ int64 currentpos; /* position of current row in partition */
2256
+ int64 frameheadpos; /* current frame head position */
2257
+ int64 frametailpos; /* current frame tail position (frame end+1) */
2258
+ /* use struct pointer to avoid including windowapi.h here */
2259
+ struct WindowObjectData *agg_winobj; /* winobj for aggregate fetches */
2260
+ int64 aggregatedbase; /* start row for current aggregates */
2261
+ int64 aggregatedupto; /* rows before this one are aggregated */
2262
+
2263
+ int frameOptions; /* frame_clause options, see WindowDef */
2264
+ ExprState *startOffset; /* expression for starting bound offset */
2265
+ ExprState *endOffset; /* expression for ending bound offset */
2266
+ Datum startOffsetValue; /* result of startOffset evaluation */
2267
+ Datum endOffsetValue; /* result of endOffset evaluation */
2268
+
2269
+ /* these fields are used with RANGE offset PRECEDING/FOLLOWING: */
2270
+ FmgrInfo startInRangeFunc; /* in_range function for startOffset */
2271
+ FmgrInfo endInRangeFunc; /* in_range function for endOffset */
2272
+ Oid inRangeColl; /* collation for in_range tests */
2273
+ bool inRangeAsc; /* use ASC sort order for in_range tests? */
2274
+ bool inRangeNullsFirst; /* nulls sort first for in_range tests? */
2275
+
2276
+ /* these fields are used in GROUPS mode: */
2277
+ int64 currentgroup; /* peer group # of current row in partition */
2278
+ int64 frameheadgroup; /* peer group # of frame head row */
2279
+ int64 frametailgroup; /* peer group # of frame tail row */
2280
+ int64 groupheadpos; /* current row's peer group head position */
2281
+ int64 grouptailpos; /* " " " " tail position (group end+1) */
2282
+
2283
+ MemoryContext partcontext; /* context for partition-lifespan data */
2284
+ MemoryContext aggcontext; /* shared context for aggregate working data */
2285
+ MemoryContext curaggcontext; /* current aggregate's working data */
2286
+ ExprContext *tmpcontext; /* short-term evaluation context */
2287
+
2288
+ bool all_first; /* true if the scan is starting */
2289
+ bool all_done; /* true if the scan is finished */
2290
+ bool partition_spooled; /* true if all tuples in current partition
2291
+ * have been spooled into tuplestore */
2292
+ bool more_partitions; /* true if there's more partitions after
2293
+ * this one */
2294
+ bool framehead_valid; /* true if frameheadpos is known up to
2295
+ * date for current row */
2296
+ bool frametail_valid; /* true if frametailpos is known up to
2297
+ * date for current row */
2298
+ bool grouptail_valid; /* true if grouptailpos is known up to
2299
+ * date for current row */
2300
+
2301
+ TupleTableSlot *first_part_slot; /* first tuple of current or next
2302
+ * partition */
2303
+ TupleTableSlot *framehead_slot; /* first tuple of current frame */
2304
+ TupleTableSlot *frametail_slot; /* first tuple after current frame */
2305
+
2306
+ /* temporary slots for tuples fetched back from tuplestore */
2307
+ TupleTableSlot *agg_row_slot;
2308
+ TupleTableSlot *temp_slot_1;
2309
+ TupleTableSlot *temp_slot_2;
2310
+ } WindowAggState;
2311
+
2312
+ /* ----------------
2313
+ * UniqueState information
2314
+ *
2315
+ * Unique nodes are used "on top of" sort nodes to discard
2316
+ * duplicate tuples returned from the sort phase. Basically
2317
+ * all it does is compare the current tuple from the subplan
2318
+ * with the previously fetched tuple (stored in its result slot).
2319
+ * If the two are identical in all interesting fields, then
2320
+ * we just fetch another tuple from the sort and try again.
2321
+ * ----------------
2322
+ */
2323
+ typedef struct UniqueState
2324
+ {
2325
+ PlanState ps; /* its first field is NodeTag */
2326
+ ExprState *eqfunction; /* tuple equality qual */
2327
+ } UniqueState;
2328
+
2329
+ /* ----------------
2330
+ * GatherState information
2331
+ *
2332
+ * Gather nodes launch 1 or more parallel workers, run a subplan
2333
+ * in those workers, and collect the results.
2334
+ * ----------------
2335
+ */
2336
+ typedef struct GatherState
2337
+ {
2338
+ PlanState ps; /* its first field is NodeTag */
2339
+ bool initialized; /* workers launched? */
2340
+ bool need_to_scan_locally; /* need to read from local plan? */
2341
+ int64 tuples_needed; /* tuple bound, see ExecSetTupleBound */
2342
+ /* these fields are set up once: */
2343
+ TupleTableSlot *funnel_slot;
2344
+ struct ParallelExecutorInfo *pei;
2345
+ /* all remaining fields are reinitialized during a rescan: */
2346
+ int nworkers_launched; /* original number of workers */
2347
+ int nreaders; /* number of still-active workers */
2348
+ int nextreader; /* next one to try to read from */
2349
+ struct TupleQueueReader **reader; /* array with nreaders active entries */
2350
+ } GatherState;
2351
+
2352
+ /* ----------------
2353
+ * GatherMergeState information
2354
+ *
2355
+ * Gather merge nodes launch 1 or more parallel workers, run a
2356
+ * subplan which produces sorted output in each worker, and then
2357
+ * merge the results into a single sorted stream.
2358
+ * ----------------
2359
+ */
2360
+ struct GMReaderTupleBuffer; /* private in nodeGatherMerge.c */
2361
+
2362
+ typedef struct GatherMergeState
2363
+ {
2364
+ PlanState ps; /* its first field is NodeTag */
2365
+ bool initialized; /* workers launched? */
2366
+ bool gm_initialized; /* gather_merge_init() done? */
2367
+ bool need_to_scan_locally; /* need to read from local plan? */
2368
+ int64 tuples_needed; /* tuple bound, see ExecSetTupleBound */
2369
+ /* these fields are set up once: */
2370
+ TupleDesc tupDesc; /* descriptor for subplan result tuples */
2371
+ int gm_nkeys; /* number of sort columns */
2372
+ SortSupport gm_sortkeys; /* array of length gm_nkeys */
2373
+ struct ParallelExecutorInfo *pei;
2374
+ /* all remaining fields are reinitialized during a rescan */
2375
+ /* (but the arrays are not reallocated, just cleared) */
2376
+ int nworkers_launched; /* original number of workers */
2377
+ int nreaders; /* number of active workers */
2378
+ TupleTableSlot **gm_slots; /* array with nreaders+1 entries */
2379
+ struct TupleQueueReader **reader; /* array with nreaders active entries */
2380
+ struct GMReaderTupleBuffer *gm_tuple_buffers; /* nreaders tuple buffers */
2381
+ struct binaryheap *gm_heap; /* binary heap of slot indices */
2382
+ } GatherMergeState;
2383
+
2384
+ /* ----------------
2385
+ * Values displayed by EXPLAIN ANALYZE
2386
+ * ----------------
2387
+ */
2388
+ typedef struct HashInstrumentation
2389
+ {
2390
+ int nbuckets; /* number of buckets at end of execution */
2391
+ int nbuckets_original; /* planned number of buckets */
2392
+ int nbatch; /* number of batches at end of execution */
2393
+ int nbatch_original; /* planned number of batches */
2394
+ Size space_peak; /* peak memory usage in bytes */
2395
+ } HashInstrumentation;
2396
+
2397
+ /* ----------------
2398
+ * Shared memory container for per-worker hash information
2399
+ * ----------------
2400
+ */
2401
+ typedef struct SharedHashInfo
2402
+ {
2403
+ int num_workers;
2404
+ HashInstrumentation hinstrument[FLEXIBLE_ARRAY_MEMBER];
2405
+ } SharedHashInfo;
2406
+
2407
+ /* ----------------
2408
+ * HashState information
2409
+ * ----------------
2410
+ */
2411
+ typedef struct HashState
2412
+ {
2413
+ PlanState ps; /* its first field is NodeTag */
2414
+ HashJoinTable hashtable; /* hash table for the hashjoin */
2415
+ List *hashkeys; /* list of ExprState nodes */
2416
+
2417
+ /*
2418
+ * In a parallelized hash join, the leader retains a pointer to the
2419
+ * shared-memory stats area in its shared_info field, and then copies the
2420
+ * shared-memory info back to local storage before DSM shutdown. The
2421
+ * shared_info field remains NULL in workers, or in non-parallel joins.
2422
+ */
2423
+ SharedHashInfo *shared_info;
2424
+
2425
+ /*
2426
+ * If we are collecting hash stats, this points to an initially-zeroed
2427
+ * collection area, which could be either local storage or in shared
2428
+ * memory; either way it's for just one process.
2429
+ */
2430
+ HashInstrumentation *hinstrument;
2431
+
2432
+ /* Parallel hash state. */
2433
+ struct ParallelHashJoinState *parallel_state;
2434
+ } HashState;
2435
+
2436
+ /* ----------------
2437
+ * SetOpState information
2438
+ *
2439
+ * Even in "sorted" mode, SetOp nodes are more complex than a simple
2440
+ * Unique, since we have to count how many duplicates to return. But
2441
+ * we also support hashing, so this is really more like a cut-down
2442
+ * form of Agg.
2443
+ * ----------------
2444
+ */
2445
+ /* this struct is private in nodeSetOp.c: */
2446
+ typedef struct SetOpStatePerGroupData *SetOpStatePerGroup;
2447
+
2448
+ typedef struct SetOpState
2449
+ {
2450
+ PlanState ps; /* its first field is NodeTag */
2451
+ ExprState *eqfunction; /* equality comparator */
2452
+ Oid *eqfuncoids; /* per-grouping-field equality fns */
2453
+ FmgrInfo *hashfunctions; /* per-grouping-field hash fns */
2454
+ bool setop_done; /* indicates completion of output scan */
2455
+ long numOutput; /* number of dups left to output */
2456
+ /* these fields are used in SETOP_SORTED mode: */
2457
+ SetOpStatePerGroup pergroup; /* per-group working state */
2458
+ HeapTuple grp_firstTuple; /* copy of first tuple of current group */
2459
+ /* these fields are used in SETOP_HASHED mode: */
2460
+ TupleHashTable hashtable; /* hash table with one entry per group */
2461
+ MemoryContext tableContext; /* memory context containing hash table */
2462
+ bool table_filled; /* hash table filled yet? */
2463
+ TupleHashIterator hashiter; /* for iterating through hash table */
2464
+ } SetOpState;
2465
+
2466
+ /* ----------------
2467
+ * LockRowsState information
2468
+ *
2469
+ * LockRows nodes are used to enforce FOR [KEY] UPDATE/SHARE locking.
2470
+ * ----------------
2471
+ */
2472
+ typedef struct LockRowsState
2473
+ {
2474
+ PlanState ps; /* its first field is NodeTag */
2475
+ List *lr_arowMarks; /* List of ExecAuxRowMarks */
2476
+ EPQState lr_epqstate; /* for evaluating EvalPlanQual rechecks */
2477
+ } LockRowsState;
2478
+
2479
+ /* ----------------
2480
+ * LimitState information
2481
+ *
2482
+ * Limit nodes are used to enforce LIMIT/OFFSET clauses.
2483
+ * They just select the desired subrange of their subplan's output.
2484
+ *
2485
+ * offset is the number of initial tuples to skip (0 does nothing).
2486
+ * count is the number of tuples to return after skipping the offset tuples.
2487
+ * If no limit count was specified, count is undefined and noCount is true.
2488
+ * When lstate == LIMIT_INITIAL, offset/count/noCount haven't been set yet.
2489
+ * ----------------
2490
+ */
2491
+ typedef enum
2492
+ {
2493
+ LIMIT_INITIAL, /* initial state for LIMIT node */
2494
+ LIMIT_RESCAN, /* rescan after recomputing parameters */
2495
+ LIMIT_EMPTY, /* there are no returnable rows */
2496
+ LIMIT_INWINDOW, /* have returned a row in the window */
2497
+ LIMIT_WINDOWEND_TIES, /* have returned a tied row */
2498
+ LIMIT_SUBPLANEOF, /* at EOF of subplan (within window) */
2499
+ LIMIT_WINDOWEND, /* stepped off end of window */
2500
+ LIMIT_WINDOWSTART /* stepped off beginning of window */
2501
+ } LimitStateCond;
2502
+
2503
+ typedef struct LimitState
2504
+ {
2505
+ PlanState ps; /* its first field is NodeTag */
2506
+ ExprState *limitOffset; /* OFFSET parameter, or NULL if none */
2507
+ ExprState *limitCount; /* COUNT parameter, or NULL if none */
2508
+ LimitOption limitOption; /* limit specification type */
2509
+ int64 offset; /* current OFFSET value */
2510
+ int64 count; /* current COUNT, if any */
2511
+ bool noCount; /* if true, ignore count */
2512
+ LimitStateCond lstate; /* state machine status, as above */
2513
+ int64 position; /* 1-based index of last tuple returned */
2514
+ TupleTableSlot *subSlot; /* tuple last obtained from subplan */
2515
+ ExprState *eqfunction; /* tuple equality qual in case of WITH TIES
2516
+ * option */
2517
+ TupleTableSlot *last_slot; /* slot for evaluation of ties */
2518
+ } LimitState;
2519
+
2520
+ #endif /* EXECNODES_H */