pg_query 2.0.3 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (557) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +165 -0
  3. data/README.md +67 -29
  4. data/Rakefile +8 -23
  5. data/ext/pg_query/extconf.rb +21 -3
  6. data/ext/pg_query/include/pg_query.h +29 -4
  7. data/ext/pg_query/include/pg_query_enum_defs.c +551 -272
  8. data/ext/pg_query/include/pg_query_fingerprint_conds.c +563 -470
  9. data/ext/pg_query/include/pg_query_fingerprint_defs.c +5403 -3945
  10. data/ext/pg_query/include/pg_query_outfuncs_conds.c +402 -330
  11. data/ext/pg_query/include/pg_query_outfuncs_defs.c +1319 -1059
  12. data/ext/pg_query/include/pg_query_readfuncs_conds.c +141 -118
  13. data/ext/pg_query/include/pg_query_readfuncs_defs.c +1685 -1379
  14. data/ext/pg_query/include/{access → postgres/access}/amapi.h +47 -1
  15. data/ext/pg_query/include/{access → postgres/access}/attmap.h +5 -3
  16. data/ext/pg_query/include/{access → postgres/access}/attnum.h +2 -2
  17. data/ext/pg_query/include/{access → postgres/access}/clog.h +4 -2
  18. data/ext/pg_query/include/{access → postgres/access}/commit_ts.h +6 -9
  19. data/ext/pg_query/include/{access → postgres/access}/detoast.h +1 -11
  20. data/ext/pg_query/include/{access → postgres/access}/genam.h +21 -16
  21. data/ext/pg_query/include/{access → postgres/access}/gin.h +17 -4
  22. data/ext/pg_query/include/{access → postgres/access}/htup.h +1 -1
  23. data/ext/pg_query/include/{access → postgres/access}/htup_details.h +80 -88
  24. data/ext/pg_query/include/{access → postgres/access}/itup.h +61 -52
  25. data/ext/pg_query/include/{access → postgres/access}/parallel.h +2 -2
  26. data/ext/pg_query/include/{access → postgres/access}/printtup.h +1 -1
  27. data/ext/pg_query/include/{access → postgres/access}/relation.h +1 -1
  28. data/ext/pg_query/include/{access → postgres/access}/relscan.h +17 -2
  29. data/ext/pg_query/include/postgres/access/rmgr.h +62 -0
  30. data/ext/pg_query/include/{access → postgres/access}/rmgrlist.h +24 -24
  31. data/ext/pg_query/include/{access → postgres/access}/sdir.h +12 -3
  32. data/ext/pg_query/include/{access → postgres/access}/skey.h +1 -1
  33. data/ext/pg_query/include/{access → postgres/access}/stratnum.h +4 -2
  34. data/ext/pg_query/include/{access → postgres/access}/sysattr.h +1 -1
  35. data/ext/pg_query/include/{access → postgres/access}/table.h +2 -1
  36. data/ext/pg_query/include/{access → postgres/access}/tableam.h +337 -62
  37. data/ext/pg_query/include/postgres/access/toast_compression.h +73 -0
  38. data/ext/pg_query/include/{access → postgres/access}/transam.h +123 -13
  39. data/ext/pg_query/include/postgres/access/tsmapi.h +82 -0
  40. data/ext/pg_query/include/{access → postgres/access}/tupconvert.h +5 -2
  41. data/ext/pg_query/include/{access → postgres/access}/tupdesc.h +2 -2
  42. data/ext/pg_query/include/{access → postgres/access}/tupmacs.h +60 -100
  43. data/ext/pg_query/include/{access → postgres/access}/twophase.h +5 -1
  44. data/ext/pg_query/include/{access → postgres/access}/xact.h +99 -32
  45. data/ext/pg_query/include/{access → postgres/access}/xlog.h +69 -165
  46. data/ext/pg_query/include/{access → postgres/access}/xlog_internal.h +147 -73
  47. data/ext/pg_query/include/postgres/access/xlogbackup.h +41 -0
  48. data/ext/pg_query/include/{access → postgres/access}/xlogdefs.h +13 -40
  49. data/ext/pg_query/include/postgres/access/xlogprefetcher.h +55 -0
  50. data/ext/pg_query/include/{access → postgres/access}/xlogreader.h +154 -37
  51. data/ext/pg_query/include/{access → postgres/access}/xlogrecord.h +34 -13
  52. data/ext/pg_query/include/postgres/access/xlogrecovery.h +158 -0
  53. data/ext/pg_query/include/postgres/archive/archive_module.h +59 -0
  54. data/ext/pg_query/include/{c.h → postgres/c.h} +245 -188
  55. data/ext/pg_query/include/{catalog → postgres/catalog}/catalog.h +6 -3
  56. data/ext/pg_query/include/{catalog → postgres/catalog}/catversion.h +6 -2
  57. data/ext/pg_query/include/{catalog → postgres/catalog}/dependency.h +14 -19
  58. data/ext/pg_query/include/postgres/catalog/genbki.h +143 -0
  59. data/ext/pg_query/include/{catalog → postgres/catalog}/index.h +20 -5
  60. data/ext/pg_query/include/postgres/catalog/indexing.h +54 -0
  61. data/ext/pg_query/include/{catalog → postgres/catalog}/namespace.h +5 -3
  62. data/ext/pg_query/include/{catalog → postgres/catalog}/objectaccess.h +73 -3
  63. data/ext/pg_query/include/{catalog → postgres/catalog}/objectaddress.h +12 -7
  64. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_aggregate.h +14 -10
  65. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_aggregate_d.h +2 -1
  66. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_am.h +4 -1
  67. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_am_d.h +3 -1
  68. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_attribute.h +45 -26
  69. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_attribute_d.h +19 -16
  70. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_authid.h +7 -2
  71. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_authid_d.h +19 -9
  72. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_class.h +45 -15
  73. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_class_d.h +31 -2
  74. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_collation.h +35 -8
  75. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_collation_d.h +21 -3
  76. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_constraint.h +39 -13
  77. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_constraint_d.h +10 -4
  78. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_control.h +13 -5
  79. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_conversion.h +8 -5
  80. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_conversion_d.h +4 -1
  81. data/ext/pg_query/include/postgres/catalog/pg_database.h +124 -0
  82. data/ext/pg_query/include/postgres/catalog/pg_database_d.h +52 -0
  83. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_depend.h +11 -7
  84. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_depend_d.h +3 -1
  85. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_event_trigger.h +9 -3
  86. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_event_trigger_d.h +3 -1
  87. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_index.h +17 -7
  88. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_index_d.h +20 -17
  89. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_language.h +10 -5
  90. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_language_d.h +3 -1
  91. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_namespace.h +7 -2
  92. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_namespace_d.h +3 -1
  93. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_opclass.h +8 -5
  94. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_opclass_d.h +3 -1
  95. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_operator.h +21 -16
  96. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_operator_d.h +37 -1
  97. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_opfamily.h +8 -4
  98. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_opfamily_d.h +6 -2
  99. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_partitioned_table.h +20 -9
  100. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_partitioned_table_d.h +2 -1
  101. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_proc.h +20 -11
  102. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_proc_d.h +10 -8
  103. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_publication.h +49 -6
  104. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_publication_d.h +3 -1
  105. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_replication_origin.h +6 -1
  106. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_replication_origin_d.h +5 -1
  107. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_statistic.h +19 -12
  108. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_statistic_d.h +2 -1
  109. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_statistic_ext.h +19 -5
  110. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_statistic_ext_d.h +7 -2
  111. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_transform.h +8 -5
  112. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_transform_d.h +3 -1
  113. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_trigger.h +24 -8
  114. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_trigger_d.h +4 -1
  115. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_ts_config.h +6 -3
  116. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_ts_config_d.h +3 -1
  117. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_ts_dict.h +8 -3
  118. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_ts_dict_d.h +3 -1
  119. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_ts_parser.h +6 -3
  120. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_ts_parser_d.h +3 -1
  121. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_ts_template.h +6 -3
  122. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_ts_template_d.h +3 -1
  123. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_type.h +56 -24
  124. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_type_d.h +70 -31
  125. data/ext/pg_query/include/{catalog → postgres/catalog}/storage.h +9 -7
  126. data/ext/pg_query/include/{commands → postgres/commands}/async.h +4 -5
  127. data/ext/pg_query/include/{commands → postgres/commands}/dbcommands.h +3 -1
  128. data/ext/pg_query/include/{commands → postgres/commands}/defrem.h +12 -24
  129. data/ext/pg_query/include/{commands → postgres/commands}/event_trigger.h +2 -2
  130. data/ext/pg_query/include/{commands → postgres/commands}/explain.h +3 -1
  131. data/ext/pg_query/include/{commands → postgres/commands}/prepare.h +1 -1
  132. data/ext/pg_query/include/{commands → postgres/commands}/tablespace.h +6 -4
  133. data/ext/pg_query/include/{commands → postgres/commands}/trigger.h +36 -25
  134. data/ext/pg_query/include/{commands → postgres/commands}/user.h +10 -4
  135. data/ext/pg_query/include/{commands → postgres/commands}/vacuum.h +140 -47
  136. data/ext/pg_query/include/postgres/common/cryptohash.h +39 -0
  137. data/ext/pg_query/include/{common → postgres/common}/file_perm.h +4 -4
  138. data/ext/pg_query/include/{common → postgres/common}/hashfn.h +1 -1
  139. data/ext/pg_query/include/postgres/common/int.h +437 -0
  140. data/ext/pg_query/include/{common → postgres/common}/keywords.h +2 -6
  141. data/ext/pg_query/include/{common → postgres/common}/kwlookup.h +2 -2
  142. data/ext/pg_query/include/postgres/common/pg_prng.h +61 -0
  143. data/ext/pg_query/include/{common → postgres/common}/relpath.h +21 -14
  144. data/ext/pg_query/include/postgres/common/scram-common.h +70 -0
  145. data/ext/pg_query/include/postgres/common/sha2.h +32 -0
  146. data/ext/pg_query/include/postgres/common/string.h +44 -0
  147. data/ext/pg_query/include/postgres/common/unicode_east_asian_fw_table.h +125 -0
  148. data/ext/pg_query/include/{common/unicode_combining_table.h → postgres/common/unicode_nonspacing_table.h} +138 -8
  149. data/ext/pg_query/include/postgres/copyfuncs.funcs.c +5013 -0
  150. data/ext/pg_query/include/postgres/copyfuncs.switch.c +938 -0
  151. data/ext/pg_query/include/{datatype → postgres/datatype}/timestamp.h +50 -4
  152. data/ext/pg_query/include/postgres/equalfuncs.funcs.c +3097 -0
  153. data/ext/pg_query/include/postgres/equalfuncs.switch.c +785 -0
  154. data/ext/pg_query/include/{executor → postgres/executor}/execdesc.h +1 -1
  155. data/ext/pg_query/include/{executor → postgres/executor}/executor.h +98 -32
  156. data/ext/pg_query/include/{executor → postgres/executor}/functions.h +17 -3
  157. data/ext/pg_query/include/{executor → postgres/executor}/instrument.h +33 -16
  158. data/ext/pg_query/include/{executor → postgres/executor}/spi.h +42 -4
  159. data/ext/pg_query/include/{executor → postgres/executor}/tablefunc.h +1 -1
  160. data/ext/pg_query/include/{executor → postgres/executor}/tuptable.h +18 -11
  161. data/ext/pg_query/include/{fmgr.h → postgres/fmgr.h} +33 -8
  162. data/ext/pg_query/include/postgres/foreign/fdwapi.h +294 -0
  163. data/ext/pg_query/include/{funcapi.h → postgres/funcapi.h} +22 -10
  164. data/ext/pg_query/include/postgres/gram.h +1127 -0
  165. data/ext/pg_query/include/{parser → postgres}/gramparse.h +4 -4
  166. data/ext/pg_query/include/{jit → postgres/jit}/jit.h +12 -12
  167. data/ext/pg_query/include/postgres/kwlist_d.h +1119 -0
  168. data/ext/pg_query/include/postgres/lib/dshash.h +115 -0
  169. data/ext/pg_query/include/{lib → postgres/lib}/ilist.h +454 -22
  170. data/ext/pg_query/include/{lib → postgres/lib}/pairingheap.h +1 -1
  171. data/ext/pg_query/include/{lib → postgres/lib}/simplehash.h +158 -33
  172. data/ext/pg_query/include/postgres/lib/sort_template.h +432 -0
  173. data/ext/pg_query/include/{lib → postgres/lib}/stringinfo.h +3 -3
  174. data/ext/pg_query/include/{libpq → postgres/libpq}/auth.h +12 -4
  175. data/ext/pg_query/include/{libpq → postgres/libpq}/crypt.h +5 -4
  176. data/ext/pg_query/include/{libpq → postgres/libpq}/hba.h +54 -8
  177. data/ext/pg_query/include/{libpq → postgres/libpq}/libpq-be.h +45 -17
  178. data/ext/pg_query/include/{libpq → postgres/libpq}/libpq.h +31 -20
  179. data/ext/pg_query/include/{libpq → postgres/libpq}/pqcomm.h +26 -71
  180. data/ext/pg_query/include/{libpq → postgres/libpq}/pqformat.h +2 -2
  181. data/ext/pg_query/include/{libpq → postgres/libpq}/pqsignal.h +25 -13
  182. data/ext/pg_query/include/postgres/libpq/sasl.h +136 -0
  183. data/ext/pg_query/include/postgres/libpq/scram.h +37 -0
  184. data/ext/pg_query/include/{mb → postgres/mb}/pg_wchar.h +125 -25
  185. data/ext/pg_query/include/{mb → postgres/mb}/stringinfo_mb.h +1 -1
  186. data/ext/pg_query/include/{miscadmin.h → postgres/miscadmin.h} +96 -65
  187. data/ext/pg_query/include/{nodes → postgres/nodes}/bitmapset.h +11 -7
  188. data/ext/pg_query/include/{nodes → postgres/nodes}/execnodes.h +351 -103
  189. data/ext/pg_query/include/{nodes → postgres/nodes}/extensible.h +8 -4
  190. data/ext/pg_query/include/{nodes → postgres/nodes}/lockoptions.h +1 -1
  191. data/ext/pg_query/include/{nodes → postgres/nodes}/makefuncs.h +19 -6
  192. data/ext/pg_query/include/{nodes → postgres/nodes}/memnodes.h +11 -6
  193. data/ext/pg_query/include/postgres/nodes/miscnodes.h +56 -0
  194. data/ext/pg_query/include/{nodes → postgres/nodes}/nodeFuncs.h +89 -29
  195. data/ext/pg_query/include/{nodes → postgres/nodes}/nodes.h +100 -496
  196. data/ext/pg_query/include/postgres/nodes/nodetags.h +471 -0
  197. data/ext/pg_query/include/{nodes → postgres/nodes}/params.h +3 -3
  198. data/ext/pg_query/include/{nodes → postgres/nodes}/parsenodes.h +678 -207
  199. data/ext/pg_query/include/{nodes → postgres/nodes}/pathnodes.h +1282 -454
  200. data/ext/pg_query/include/{nodes → postgres/nodes}/pg_list.h +103 -73
  201. data/ext/pg_query/include/{nodes → postgres/nodes}/plannodes.h +474 -133
  202. data/ext/pg_query/include/{nodes → postgres/nodes}/primnodes.h +754 -254
  203. data/ext/pg_query/include/{nodes → postgres/nodes}/print.h +1 -1
  204. data/ext/pg_query/include/postgres/nodes/queryjumble.h +86 -0
  205. data/ext/pg_query/include/postgres/nodes/replnodes.h +111 -0
  206. data/ext/pg_query/include/postgres/nodes/supportnodes.h +346 -0
  207. data/ext/pg_query/include/{nodes → postgres/nodes}/tidbitmap.h +1 -1
  208. data/ext/pg_query/include/postgres/nodes/value.h +90 -0
  209. data/ext/pg_query/include/{optimizer → postgres/optimizer}/cost.h +14 -5
  210. data/ext/pg_query/include/{optimizer → postgres/optimizer}/geqo.h +9 -7
  211. data/ext/pg_query/include/{optimizer → postgres/optimizer}/geqo_gene.h +1 -1
  212. data/ext/pg_query/include/{optimizer → postgres/optimizer}/optimizer.h +31 -28
  213. data/ext/pg_query/include/{optimizer → postgres/optimizer}/paths.h +29 -12
  214. data/ext/pg_query/include/{optimizer → postgres/optimizer}/planmain.h +15 -17
  215. data/ext/pg_query/include/{parser → postgres/parser}/analyze.h +20 -5
  216. data/ext/pg_query/include/postgres/parser/kwlist.h +498 -0
  217. data/ext/pg_query/include/{parser → postgres/parser}/parse_agg.h +5 -8
  218. data/ext/pg_query/include/{parser → postgres/parser}/parse_coerce.h +6 -1
  219. data/ext/pg_query/include/{parser → postgres/parser}/parse_expr.h +2 -3
  220. data/ext/pg_query/include/{parser → postgres/parser}/parse_func.h +2 -1
  221. data/ext/pg_query/include/{parser → postgres/parser}/parse_node.h +41 -11
  222. data/ext/pg_query/include/{parser → postgres/parser}/parse_oper.h +3 -5
  223. data/ext/pg_query/include/{parser → postgres/parser}/parse_relation.h +11 -5
  224. data/ext/pg_query/include/{parser → postgres/parser}/parse_type.h +4 -3
  225. data/ext/pg_query/include/postgres/parser/parser.h +68 -0
  226. data/ext/pg_query/include/{parser → postgres/parser}/parsetree.h +1 -1
  227. data/ext/pg_query/include/{parser → postgres/parser}/scanner.h +2 -2
  228. data/ext/pg_query/include/{parser → postgres/parser}/scansup.h +2 -5
  229. data/ext/pg_query/include/{partitioning → postgres/partitioning}/partdefs.h +1 -1
  230. data/ext/pg_query/include/{pg_config.h → postgres/pg_config.h} +216 -228
  231. data/ext/pg_query/include/{pg_config_manual.h → postgres/pg_config_manual.h} +80 -58
  232. data/ext/pg_query/include/postgres/pg_config_os.h +8 -0
  233. data/ext/pg_query/include/{pg_getopt.h → postgres/pg_getopt.h} +6 -6
  234. data/ext/pg_query/include/{pg_trace.h → postgres/pg_trace.h} +1 -1
  235. data/ext/pg_query/include/postgres/pgstat.h +778 -0
  236. data/ext/pg_query/include/{pgtime.h → postgres/pgtime.h} +16 -6
  237. data/ext/pg_query/include/{pl_gram.h → postgres/pl_gram.h} +116 -116
  238. data/ext/pg_query/include/{pl_reserved_kwlist.h → postgres/pl_reserved_kwlist.h} +1 -1
  239. data/ext/pg_query/include/{pl_reserved_kwlist_d.h → postgres/pl_reserved_kwlist_d.h} +10 -10
  240. data/ext/pg_query/include/{pl_unreserved_kwlist.h → postgres/pl_unreserved_kwlist.h} +3 -3
  241. data/ext/pg_query/include/{pl_unreserved_kwlist_d.h → postgres/pl_unreserved_kwlist_d.h} +60 -60
  242. data/ext/pg_query/include/{plerrcodes.h → postgres/plerrcodes.h} +9 -1
  243. data/ext/pg_query/include/{plpgsql.h → postgres/plpgsql.h} +79 -86
  244. data/ext/pg_query/include/{port → postgres/port}/atomics/arch-arm.h +9 -3
  245. data/ext/pg_query/include/postgres/port/atomics/arch-hppa.h +17 -0
  246. data/ext/pg_query/include/{port → postgres/port}/atomics/arch-ppc.h +21 -21
  247. data/ext/pg_query/include/{port → postgres/port}/atomics/arch-x86.h +2 -2
  248. data/ext/pg_query/include/{port → postgres/port}/atomics/fallback.h +3 -3
  249. data/ext/pg_query/include/{port → postgres/port}/atomics/generic-gcc.h +3 -3
  250. data/ext/pg_query/include/postgres/port/atomics/generic-msvc.h +101 -0
  251. data/ext/pg_query/include/postgres/port/atomics/generic-sunpro.h +106 -0
  252. data/ext/pg_query/include/{port → postgres/port}/atomics/generic.h +1 -1
  253. data/ext/pg_query/include/{port → postgres/port}/atomics.h +2 -7
  254. data/ext/pg_query/include/{port → postgres/port}/pg_bitutils.h +129 -16
  255. data/ext/pg_query/include/{port → postgres/port}/pg_bswap.h +1 -1
  256. data/ext/pg_query/include/{port → postgres/port}/pg_crc32c.h +1 -1
  257. data/ext/pg_query/include/postgres/port/simd.h +375 -0
  258. data/ext/pg_query/include/postgres/port/win32/arpa/inet.h +3 -0
  259. data/ext/pg_query/include/postgres/port/win32/dlfcn.h +1 -0
  260. data/ext/pg_query/include/postgres/port/win32/grp.h +1 -0
  261. data/ext/pg_query/include/postgres/port/win32/netdb.h +7 -0
  262. data/ext/pg_query/include/postgres/port/win32/netinet/in.h +3 -0
  263. data/ext/pg_query/include/postgres/port/win32/netinet/tcp.h +7 -0
  264. data/ext/pg_query/include/postgres/port/win32/pwd.h +3 -0
  265. data/ext/pg_query/include/postgres/port/win32/sys/resource.h +20 -0
  266. data/ext/pg_query/include/postgres/port/win32/sys/select.h +3 -0
  267. data/ext/pg_query/include/postgres/port/win32/sys/socket.h +26 -0
  268. data/ext/pg_query/include/postgres/port/win32/sys/un.h +17 -0
  269. data/ext/pg_query/include/postgres/port/win32/sys/wait.h +3 -0
  270. data/ext/pg_query/include/postgres/port/win32.h +59 -0
  271. data/ext/pg_query/include/postgres/port/win32_msvc/dirent.h +34 -0
  272. data/ext/pg_query/include/postgres/port/win32_msvc/sys/file.h +1 -0
  273. data/ext/pg_query/include/postgres/port/win32_msvc/sys/param.h +1 -0
  274. data/ext/pg_query/include/postgres/port/win32_msvc/sys/time.h +1 -0
  275. data/ext/pg_query/include/postgres/port/win32_msvc/unistd.h +9 -0
  276. data/ext/pg_query/include/postgres/port/win32_msvc/utime.h +3 -0
  277. data/ext/pg_query/include/postgres/port/win32_port.h +594 -0
  278. data/ext/pg_query/include/{port.h → postgres/port.h} +107 -111
  279. data/ext/pg_query/include/postgres/portability/instr_time.h +197 -0
  280. data/ext/pg_query/include/postgres/postgres.h +579 -0
  281. data/ext/pg_query/include/{postgres_ext.h → postgres/postgres_ext.h} +0 -1
  282. data/ext/pg_query/include/{postmaster → postgres/postmaster}/autovacuum.h +17 -20
  283. data/ext/pg_query/include/{postmaster → postgres/postmaster}/bgworker.h +3 -2
  284. data/ext/pg_query/include/{postmaster → postgres/postmaster}/bgworker_internals.h +2 -2
  285. data/ext/pg_query/include/{postmaster → postgres/postmaster}/bgwriter.h +6 -6
  286. data/ext/pg_query/include/{postmaster → postgres/postmaster}/interrupt.h +1 -1
  287. data/ext/pg_query/include/{postmaster → postgres/postmaster}/pgarch.h +7 -10
  288. data/ext/pg_query/include/{postmaster → postgres/postmaster}/postmaster.h +21 -17
  289. data/ext/pg_query/include/postgres/postmaster/startup.h +41 -0
  290. data/ext/pg_query/include/{postmaster → postgres/postmaster}/syslogger.h +16 -11
  291. data/ext/pg_query/include/{postmaster → postgres/postmaster}/walwriter.h +5 -3
  292. data/ext/pg_query/include/{regex → postgres/regex}/regex.h +27 -22
  293. data/ext/pg_query/include/{replication → postgres/replication}/logicallauncher.h +8 -5
  294. data/ext/pg_query/include/postgres/replication/logicalproto.h +274 -0
  295. data/ext/pg_query/include/postgres/replication/logicalworker.h +32 -0
  296. data/ext/pg_query/include/{replication → postgres/replication}/origin.h +8 -8
  297. data/ext/pg_query/include/postgres/replication/reorderbuffer.h +753 -0
  298. data/ext/pg_query/include/{replication → postgres/replication}/slot.h +42 -12
  299. data/ext/pg_query/include/{replication → postgres/replication}/syncrep.h +6 -12
  300. data/ext/pg_query/include/{replication → postgres/replication}/walreceiver.h +158 -20
  301. data/ext/pg_query/include/{replication → postgres/replication}/walsender.h +20 -20
  302. data/ext/pg_query/include/{rewrite → postgres/rewrite}/prs2lock.h +1 -1
  303. data/ext/pg_query/include/{rewrite → postgres/rewrite}/rewriteHandler.h +1 -6
  304. data/ext/pg_query/include/{rewrite → postgres/rewrite}/rewriteManip.h +11 -2
  305. data/ext/pg_query/include/{rewrite → postgres/rewrite}/rewriteSupport.h +1 -1
  306. data/ext/pg_query/include/{storage → postgres/storage}/backendid.h +3 -3
  307. data/ext/pg_query/include/{storage → postgres/storage}/block.h +24 -37
  308. data/ext/pg_query/include/{storage → postgres/storage}/buf.h +1 -1
  309. data/ext/pg_query/include/{storage → postgres/storage}/bufmgr.h +196 -95
  310. data/ext/pg_query/include/{storage → postgres/storage}/bufpage.h +152 -101
  311. data/ext/pg_query/include/{storage → postgres/storage}/condition_variable.h +14 -3
  312. data/ext/pg_query/include/{storage → postgres/storage}/dsm.h +6 -6
  313. data/ext/pg_query/include/{storage → postgres/storage}/dsm_impl.h +6 -2
  314. data/ext/pg_query/include/{storage → postgres/storage}/fd.h +48 -14
  315. data/ext/pg_query/include/postgres/storage/fileset.h +40 -0
  316. data/ext/pg_query/include/{storage → postgres/storage}/ipc.h +5 -2
  317. data/ext/pg_query/include/{storage → postgres/storage}/item.h +1 -1
  318. data/ext/pg_query/include/{storage → postgres/storage}/itemid.h +1 -1
  319. data/ext/pg_query/include/{storage → postgres/storage}/itemptr.h +96 -57
  320. data/ext/pg_query/include/{storage → postgres/storage}/large_object.h +2 -2
  321. data/ext/pg_query/include/{storage → postgres/storage}/latch.h +17 -13
  322. data/ext/pg_query/include/{storage → postgres/storage}/lmgr.h +7 -1
  323. data/ext/pg_query/include/{storage → postgres/storage}/lock.h +37 -25
  324. data/ext/pg_query/include/{storage → postgres/storage}/lockdefs.h +4 -4
  325. data/ext/pg_query/include/{storage → postgres/storage}/lwlock.h +21 -33
  326. data/ext/pg_query/include/{storage → postgres/storage}/lwlocknames.h +0 -1
  327. data/ext/pg_query/include/{storage → postgres/storage}/off.h +1 -1
  328. data/ext/pg_query/include/{storage → postgres/storage}/pg_sema.h +1 -1
  329. data/ext/pg_query/include/{storage → postgres/storage}/pg_shmem.h +9 -7
  330. data/ext/pg_query/include/{storage → postgres/storage}/pmsignal.h +15 -4
  331. data/ext/pg_query/include/{storage → postgres/storage}/predicate.h +5 -5
  332. data/ext/pg_query/include/{storage → postgres/storage}/proc.h +200 -67
  333. data/ext/pg_query/include/postgres/storage/procarray.h +99 -0
  334. data/ext/pg_query/include/{storage → postgres/storage}/proclist_types.h +1 -1
  335. data/ext/pg_query/include/{storage → postgres/storage}/procsignal.h +5 -7
  336. data/ext/pg_query/include/postgres/storage/relfilelocator.h +99 -0
  337. data/ext/pg_query/include/{storage → postgres/storage}/s_lock.h +118 -298
  338. data/ext/pg_query/include/{storage → postgres/storage}/sharedfileset.h +3 -11
  339. data/ext/pg_query/include/{storage → postgres/storage}/shm_mq.h +5 -4
  340. data/ext/pg_query/include/{storage → postgres/storage}/shm_toc.h +1 -1
  341. data/ext/pg_query/include/{storage → postgres/storage}/shmem.h +1 -23
  342. data/ext/pg_query/include/{storage → postgres/storage}/sinval.h +5 -5
  343. data/ext/pg_query/include/{storage → postgres/storage}/sinvaladt.h +4 -2
  344. data/ext/pg_query/include/{storage → postgres/storage}/smgr.h +21 -17
  345. data/ext/pg_query/include/{storage → postgres/storage}/spin.h +2 -2
  346. data/ext/pg_query/include/{storage → postgres/storage}/standby.h +17 -9
  347. data/ext/pg_query/include/{storage → postgres/storage}/standbydefs.h +2 -2
  348. data/ext/pg_query/include/{storage → postgres/storage}/sync.h +9 -5
  349. data/ext/pg_query/include/{tcop → postgres/tcop}/cmdtag.h +7 -2
  350. data/ext/pg_query/include/{tcop → postgres/tcop}/cmdtaglist.h +3 -2
  351. data/ext/pg_query/include/{tcop → postgres/tcop}/deparse_utility.h +1 -1
  352. data/ext/pg_query/include/{tcop → postgres/tcop}/dest.h +1 -3
  353. data/ext/pg_query/include/{tcop → postgres/tcop}/fastpath.h +1 -2
  354. data/ext/pg_query/include/{tcop → postgres/tcop}/pquery.h +7 -1
  355. data/ext/pg_query/include/{tcop → postgres/tcop}/tcopprot.h +19 -14
  356. data/ext/pg_query/include/{tcop → postgres/tcop}/utility.h +7 -3
  357. data/ext/pg_query/include/{tsearch → postgres/tsearch}/ts_cache.h +3 -5
  358. data/ext/pg_query/include/{utils → postgres/utils}/acl.h +37 -71
  359. data/ext/pg_query/include/{utils → postgres/utils}/aclchk_internal.h +1 -1
  360. data/ext/pg_query/include/{utils → postgres/utils}/array.h +26 -2
  361. data/ext/pg_query/include/postgres/utils/backend_progress.h +45 -0
  362. data/ext/pg_query/include/postgres/utils/backend_status.h +342 -0
  363. data/ext/pg_query/include/{utils → postgres/utils}/builtins.h +20 -11
  364. data/ext/pg_query/include/{utils → postgres/utils}/bytea.h +3 -2
  365. data/ext/pg_query/include/{utils → postgres/utils}/catcache.h +1 -1
  366. data/ext/pg_query/include/{utils → postgres/utils}/date.h +37 -9
  367. data/ext/pg_query/include/{utils → postgres/utils}/datetime.h +48 -27
  368. data/ext/pg_query/include/{utils → postgres/utils}/datum.h +9 -1
  369. data/ext/pg_query/include/{utils → postgres/utils}/dsa.h +5 -1
  370. data/ext/pg_query/include/{utils → postgres/utils}/elog.h +154 -48
  371. data/ext/pg_query/include/{utils → postgres/utils}/errcodes.h +2 -0
  372. data/ext/pg_query/include/{utils → postgres/utils}/expandeddatum.h +14 -3
  373. data/ext/pg_query/include/{utils → postgres/utils}/expandedrecord.h +14 -4
  374. data/ext/pg_query/include/{utils → postgres/utils}/float.h +13 -12
  375. data/ext/pg_query/include/{utils → postgres/utils}/fmgroids.h +1353 -696
  376. data/ext/pg_query/include/{utils → postgres/utils}/fmgrprotos.h +243 -18
  377. data/ext/pg_query/include/{utils → postgres/utils}/fmgrtab.h +6 -5
  378. data/ext/pg_query/include/{utils → postgres/utils}/guc.h +120 -121
  379. data/ext/pg_query/include/postgres/utils/guc_hooks.h +163 -0
  380. data/ext/pg_query/include/{utils → postgres/utils}/guc_tables.h +71 -21
  381. data/ext/pg_query/include/{utils → postgres/utils}/hsearch.h +15 -11
  382. data/ext/pg_query/include/{utils → postgres/utils}/inval.h +7 -3
  383. data/ext/pg_query/include/postgres/utils/logtape.h +77 -0
  384. data/ext/pg_query/include/{utils → postgres/utils}/lsyscache.h +16 -1
  385. data/ext/pg_query/include/{utils → postgres/utils}/memdebug.h +1 -1
  386. data/ext/pg_query/include/{utils → postgres/utils}/memutils.h +14 -53
  387. data/ext/pg_query/include/postgres/utils/memutils_internal.h +136 -0
  388. data/ext/pg_query/include/postgres/utils/memutils_memorychunk.h +237 -0
  389. data/ext/pg_query/include/{utils → postgres/utils}/numeric.h +38 -9
  390. data/ext/pg_query/include/{utils → postgres/utils}/palloc.h +33 -4
  391. data/ext/pg_query/include/{utils → postgres/utils}/partcache.h +3 -2
  392. data/ext/pg_query/include/{utils → postgres/utils}/pg_locale.h +37 -21
  393. data/ext/pg_query/include/postgres/utils/pgstat_internal.h +814 -0
  394. data/ext/pg_query/include/{utils → postgres/utils}/plancache.h +6 -5
  395. data/ext/pg_query/include/{utils → postgres/utils}/portal.h +12 -1
  396. data/ext/pg_query/include/{utils → postgres/utils}/probes.h +59 -59
  397. data/ext/pg_query/include/postgres/utils/ps_status.h +47 -0
  398. data/ext/pg_query/include/{utils → postgres/utils}/queryenvironment.h +1 -1
  399. data/ext/pg_query/include/postgres/utils/regproc.h +39 -0
  400. data/ext/pg_query/include/{utils → postgres/utils}/rel.h +129 -61
  401. data/ext/pg_query/include/{utils → postgres/utils}/relcache.h +21 -14
  402. data/ext/pg_query/include/{utils → postgres/utils}/reltrigger.h +1 -1
  403. data/ext/pg_query/include/{utils → postgres/utils}/resowner.h +1 -1
  404. data/ext/pg_query/include/{utils → postgres/utils}/ruleutils.h +9 -1
  405. data/ext/pg_query/include/{utils → postgres/utils}/sharedtuplestore.h +1 -1
  406. data/ext/pg_query/include/{utils → postgres/utils}/snapmgr.h +38 -15
  407. data/ext/pg_query/include/{utils → postgres/utils}/snapshot.h +14 -1
  408. data/ext/pg_query/include/{utils → postgres/utils}/sortsupport.h +117 -2
  409. data/ext/pg_query/include/{utils → postgres/utils}/syscache.h +9 -1
  410. data/ext/pg_query/include/{utils → postgres/utils}/timeout.h +11 -4
  411. data/ext/pg_query/include/{utils → postgres/utils}/timestamp.h +46 -15
  412. data/ext/pg_query/include/{utils → postgres/utils}/tuplesort.h +209 -41
  413. data/ext/pg_query/include/{utils → postgres/utils}/tuplestore.h +2 -2
  414. data/ext/pg_query/include/{utils → postgres/utils}/typcache.h +24 -17
  415. data/ext/pg_query/include/{utils → postgres/utils}/varlena.h +17 -3
  416. data/ext/pg_query/include/postgres/utils/wait_event.h +294 -0
  417. data/ext/pg_query/include/{utils → postgres/utils}/xml.h +18 -8
  418. data/ext/pg_query/include/{postgres.h → postgres/varatt.h} +65 -471
  419. data/ext/pg_query/include/protobuf/pg_query.pb-c.h +7494 -6382
  420. data/ext/pg_query/include/protobuf/pg_query.pb.h +116922 -84792
  421. data/ext/pg_query/include/protobuf-c/protobuf-c.h +7 -3
  422. data/ext/pg_query/include/protobuf-c.h +7 -3
  423. data/ext/pg_query/pg_query.c +10 -1
  424. data/ext/pg_query/pg_query.pb-c.c +21026 -17002
  425. data/ext/pg_query/pg_query_deparse.c +1 -9896
  426. data/ext/pg_query/pg_query_fingerprint.c +162 -50
  427. data/ext/pg_query/pg_query_fingerprint.h +3 -1
  428. data/ext/pg_query/pg_query_internal.h +1 -1
  429. data/ext/pg_query/pg_query_json_plpgsql.c +56 -12
  430. data/ext/pg_query/pg_query_normalize.c +259 -64
  431. data/ext/pg_query/pg_query_outfuncs.h +1 -0
  432. data/ext/pg_query/pg_query_outfuncs_json.c +71 -16
  433. data/ext/pg_query/pg_query_outfuncs_protobuf.c +73 -12
  434. data/ext/pg_query/pg_query_parse.c +47 -5
  435. data/ext/pg_query/pg_query_parse_plpgsql.c +86 -21
  436. data/ext/pg_query/pg_query_readfuncs_protobuf.c +43 -8
  437. data/ext/pg_query/pg_query_ruby.c +6 -1
  438. data/ext/pg_query/pg_query_ruby_freebsd.sym +2 -0
  439. data/ext/pg_query/pg_query_scan.c +3 -2
  440. data/ext/pg_query/pg_query_split.c +6 -5
  441. data/ext/pg_query/postgres_deparse.c +11067 -0
  442. data/ext/pg_query/postgres_deparse.h +9 -0
  443. data/ext/pg_query/protobuf-c.c +34 -27
  444. data/ext/pg_query/src_backend_catalog_namespace.c +27 -10
  445. data/ext/pg_query/src_backend_catalog_pg_proc.c +4 -1
  446. data/ext/pg_query/src_backend_commands_define.c +11 -1
  447. data/ext/pg_query/src_backend_nodes_bitmapset.c +13 -70
  448. data/ext/pg_query/src_backend_nodes_copyfuncs.c +103 -5894
  449. data/ext/pg_query/src_backend_nodes_equalfuncs.c +102 -3830
  450. data/ext/pg_query/src_backend_nodes_extensible.c +6 -29
  451. data/ext/pg_query/src_backend_nodes_list.c +99 -12
  452. data/ext/pg_query/src_backend_nodes_makefuncs.c +99 -4
  453. data/ext/pg_query/src_backend_nodes_nodeFuncs.c +325 -131
  454. data/ext/pg_query/src_backend_nodes_nodes.c +38 -0
  455. data/ext/pg_query/src_backend_nodes_value.c +28 -19
  456. data/ext/pg_query/src_backend_parser_gram.c +36104 -32074
  457. data/ext/pg_query/src_backend_parser_parser.c +53 -8
  458. data/ext/pg_query/src_backend_parser_scan.c +4893 -3701
  459. data/ext/pg_query/src_backend_parser_scansup.c +4 -28
  460. data/ext/pg_query/src_backend_storage_ipc_ipc.c +13 -4
  461. data/ext/pg_query/src_backend_tcop_postgres.c +133 -105
  462. data/ext/pg_query/src_backend_utils_activity_pgstat_database.c +140 -0
  463. data/ext/pg_query/src_backend_utils_adt_datum.c +17 -7
  464. data/ext/pg_query/src_backend_utils_adt_expandeddatum.c +1 -1
  465. data/ext/pg_query/src_backend_utils_adt_format_type.c +6 -2
  466. data/ext/pg_query/src_backend_utils_adt_numutils.c +489 -0
  467. data/ext/pg_query/src_backend_utils_adt_ruleutils.c +187 -19
  468. data/ext/pg_query/src_backend_utils_error_assert.c +17 -18
  469. data/ext/pg_query/src_backend_utils_error_elog.c +513 -318
  470. data/ext/pg_query/src_backend_utils_fmgr_fmgr.c +44 -17
  471. data/ext/pg_query/src_backend_utils_init_globals.c +9 -6
  472. data/ext/pg_query/src_backend_utils_mb_mbutils.c +74 -131
  473. data/ext/pg_query/src_backend_utils_misc_guc_tables.c +492 -0
  474. data/ext/pg_query/src_backend_utils_mmgr_alignedalloc.c +163 -0
  475. data/ext/pg_query/src_backend_utils_mmgr_aset.c +453 -314
  476. data/ext/pg_query/src_backend_utils_mmgr_generation.c +1039 -0
  477. data/ext/pg_query/src_backend_utils_mmgr_mcxt.c +549 -76
  478. data/ext/pg_query/src_backend_utils_mmgr_slab.c +1021 -0
  479. data/ext/pg_query/src_common_encnames.c +4 -1
  480. data/ext/pg_query/src_common_hashfn.c +420 -0
  481. data/ext/pg_query/src_common_keywords.c +15 -2
  482. data/ext/pg_query/src_common_kwlist_d.h +545 -498
  483. data/ext/pg_query/src_common_kwlookup.c +1 -1
  484. data/ext/pg_query/src_common_psprintf.c +1 -1
  485. data/ext/pg_query/src_common_stringinfo.c +4 -4
  486. data/ext/pg_query/src_common_wchar.c +717 -113
  487. data/ext/pg_query/src_pl_plpgsql_src_pl_comp.c +49 -22
  488. data/ext/pg_query/src_pl_plpgsql_src_pl_funcs.c +3 -18
  489. data/ext/pg_query/src_pl_plpgsql_src_pl_gram.c +1136 -1195
  490. data/ext/pg_query/src_pl_plpgsql_src_pl_handler.c +1 -1
  491. data/ext/pg_query/src_pl_plpgsql_src_pl_reserved_kwlist_d.h +10 -10
  492. data/ext/pg_query/src_pl_plpgsql_src_pl_scanner.c +2 -2
  493. data/ext/pg_query/src_pl_plpgsql_src_pl_unreserved_kwlist_d.h +60 -60
  494. data/ext/pg_query/src_port_pg_bitutils.c +103 -40
  495. data/ext/pg_query/src_port_pgstrcasecmp.c +29 -1
  496. data/ext/pg_query/src_port_qsort.c +12 -224
  497. data/ext/pg_query/src_port_snprintf.c +51 -29
  498. data/ext/pg_query/src_port_strerror.c +9 -19
  499. data/ext/pg_query/src_port_strlcpy.c +79 -0
  500. data/lib/pg_query/deparse.rb +7 -1
  501. data/lib/pg_query/filter_columns.rb +7 -5
  502. data/lib/pg_query/fingerprint.rb +21 -9
  503. data/lib/pg_query/node.rb +18 -13
  504. data/lib/pg_query/param_refs.rb +1 -1
  505. data/lib/pg_query/parse.rb +141 -50
  506. data/lib/pg_query/pg_query_pb.rb +175 -3031
  507. data/lib/pg_query/treewalker.rb +26 -2
  508. data/lib/pg_query/truncate.rb +54 -8
  509. data/lib/pg_query/version.rb +1 -1
  510. data/lib/pg_query.rb +0 -1
  511. metadata +443 -380
  512. data/ext/pg_query/guc-file.c +0 -0
  513. data/ext/pg_query/include/access/rmgr.h +0 -35
  514. data/ext/pg_query/include/access/xloginsert.h +0 -64
  515. data/ext/pg_query/include/bootstrap/bootstrap.h +0 -62
  516. data/ext/pg_query/include/catalog/genbki.h +0 -64
  517. data/ext/pg_query/include/catalog/indexing.h +0 -366
  518. data/ext/pg_query/include/commands/variable.h +0 -38
  519. data/ext/pg_query/include/common/ip.h +0 -37
  520. data/ext/pg_query/include/common/string.h +0 -19
  521. data/ext/pg_query/include/getaddrinfo.h +0 -162
  522. data/ext/pg_query/include/kwlist_d.h +0 -1072
  523. data/ext/pg_query/include/nodes/value.h +0 -61
  524. data/ext/pg_query/include/parser/gram.h +0 -1067
  525. data/ext/pg_query/include/parser/kwlist.h +0 -477
  526. data/ext/pg_query/include/parser/parse_clause.h +0 -54
  527. data/ext/pg_query/include/parser/parse_collate.h +0 -27
  528. data/ext/pg_query/include/parser/parse_target.h +0 -46
  529. data/ext/pg_query/include/parser/parser.h +0 -41
  530. data/ext/pg_query/include/pg_config_os.h +0 -8
  531. data/ext/pg_query/include/pgstat.h +0 -1487
  532. data/ext/pg_query/include/portability/instr_time.h +0 -256
  533. data/ext/pg_query/include/postmaster/fork_process.h +0 -17
  534. data/ext/pg_query/include/replication/logicalproto.h +0 -110
  535. data/ext/pg_query/include/replication/logicalworker.h +0 -19
  536. data/ext/pg_query/include/replication/reorderbuffer.h +0 -467
  537. data/ext/pg_query/include/storage/relfilenode.h +0 -99
  538. data/ext/pg_query/include/utils/dynahash.h +0 -19
  539. data/ext/pg_query/include/utils/pg_lsn.h +0 -29
  540. data/ext/pg_query/include/utils/pidfile.h +0 -56
  541. data/ext/pg_query/include/utils/ps_status.h +0 -25
  542. data/ext/pg_query/include/utils/regproc.h +0 -28
  543. data/ext/pg_query/include/utils/rls.h +0 -50
  544. data/ext/pg_query/include/utils/tzparser.h +0 -39
  545. data/ext/pg_query/src_backend_libpq_pqcomm.c +0 -651
  546. data/ext/pg_query/src_backend_parser_parse_expr.c +0 -313
  547. data/ext/pg_query/src_backend_postmaster_postmaster.c +0 -2230
  548. data/ext/pg_query/src_backend_storage_lmgr_s_lock.c +0 -370
  549. data/ext/pg_query/src_backend_utils_hash_dynahash.c +0 -1086
  550. data/ext/pg_query/src_backend_utils_misc_guc.c +0 -1831
  551. data/ext/pg_query/src_common_string.c +0 -86
  552. data/ext/pg_query/src_port_erand48.c +0 -127
  553. data/ext/pg_query/src_port_pgsleep.c +0 -69
  554. data/ext/pg_query/src_port_random.c +0 -31
  555. data/ext/pg_query/src_port_strnlen.c +0 -39
  556. data/lib/pg_query/json_field_names.rb +0 -1402
  557. /data/ext/pg_query/include/{pg_config_ext.h → postgres/pg_config_ext.h} +0 -0
@@ -3,8 +3,10 @@
3
3
  * pathnodes.h
4
4
  * Definitions for planner's internal data structures, especially Paths.
5
5
  *
6
+ * We don't support copying RelOptInfo, IndexOptInfo, or Path nodes.
7
+ * There are some subsidiary structs that are useful to copy, though.
6
8
  *
7
- * Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group
9
+ * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
8
10
  * Portions Copyright (c) 1994, Regents of the University of California
9
11
  *
10
12
  * src/include/nodes/pathnodes.h
@@ -55,10 +57,6 @@ typedef struct QualCost
55
57
  */
56
58
  typedef struct AggClauseCosts
57
59
  {
58
- int numAggs; /* total number of aggregate functions */
59
- int numOrderedAggs; /* number w/ DISTINCT/ORDER BY/WITHIN GROUP */
60
- bool hasNonPartial; /* does any agg not support partial mode? */
61
- bool hasNonSerial; /* is any partial agg non-serializable? */
62
60
  QualCost transCost; /* total per-input-row execution costs */
63
61
  QualCost finalCost; /* total per-aggregated-row costs */
64
62
  Size transitionSpace; /* space for pass-by-ref transition data */
@@ -75,24 +73,13 @@ typedef enum UpperRelationKind
75
73
  * any */
76
74
  UPPERREL_GROUP_AGG, /* result of grouping/aggregation, if any */
77
75
  UPPERREL_WINDOW, /* result of window functions, if any */
76
+ UPPERREL_PARTIAL_DISTINCT, /* result of partial "SELECT DISTINCT", if any */
78
77
  UPPERREL_DISTINCT, /* result of "SELECT DISTINCT", if any */
79
78
  UPPERREL_ORDERED, /* result of ORDER BY, if any */
80
79
  UPPERREL_FINAL /* result of any remaining top-level actions */
81
80
  /* NB: UPPERREL_FINAL must be last enum entry; it's used to size arrays */
82
81
  } UpperRelationKind;
83
82
 
84
- /*
85
- * This enum identifies which type of relation is being planned through the
86
- * inheritance planner. INHKIND_NONE indicates the inheritance planner
87
- * was not used.
88
- */
89
- typedef enum InheritanceKind
90
- {
91
- INHKIND_NONE,
92
- INHKIND_INHERITED,
93
- INHKIND_PARTITIONED
94
- } InheritanceKind;
95
-
96
83
  /*----------
97
84
  * PlannerGlobal
98
85
  * Global information for planning/optimization
@@ -100,53 +87,79 @@ typedef enum InheritanceKind
100
87
  * PlannerGlobal holds state for an entire planner invocation; this state
101
88
  * is shared across all levels of sub-Queries that exist in the command being
102
89
  * planned.
90
+ *
91
+ * Not all fields are printed. (In some cases, there is no print support for
92
+ * the field type; in others, doing so would lead to infinite recursion.)
103
93
  *----------
104
94
  */
105
95
  typedef struct PlannerGlobal
106
96
  {
97
+ pg_node_attr(no_copy_equal, no_read, no_query_jumble)
98
+
107
99
  NodeTag type;
108
100
 
109
- ParamListInfo boundParams; /* Param values provided to planner() */
101
+ /* Param values provided to planner() */
102
+ ParamListInfo boundParams pg_node_attr(read_write_ignore);
110
103
 
111
- List *subplans; /* Plans for SubPlan nodes */
104
+ /* Plans for SubPlan nodes */
105
+ List *subplans;
112
106
 
113
- List *subroots; /* PlannerInfos for SubPlan nodes */
107
+ /* PlannerInfos for SubPlan nodes */
108
+ List *subroots pg_node_attr(read_write_ignore);
114
109
 
115
- Bitmapset *rewindPlanIDs; /* indices of subplans that require REWIND */
110
+ /* indices of subplans that require REWIND */
111
+ Bitmapset *rewindPlanIDs;
116
112
 
117
- List *finalrtable; /* "flat" rangetable for executor */
113
+ /* "flat" rangetable for executor */
114
+ List *finalrtable;
118
115
 
119
- List *finalrowmarks; /* "flat" list of PlanRowMarks */
116
+ /* "flat" list of RTEPermissionInfos */
117
+ List *finalrteperminfos;
120
118
 
121
- List *resultRelations; /* "flat" list of integer RT indexes */
119
+ /* "flat" list of PlanRowMarks */
120
+ List *finalrowmarks;
122
121
 
123
- List *rootResultRelations; /* "flat" list of integer RT indexes */
122
+ /* "flat" list of integer RT indexes */
123
+ List *resultRelations;
124
124
 
125
- List *appendRelations; /* "flat" list of AppendRelInfos */
125
+ /* "flat" list of AppendRelInfos */
126
+ List *appendRelations;
126
127
 
127
- List *relationOids; /* OIDs of relations the plan depends on */
128
+ /* OIDs of relations the plan depends on */
129
+ List *relationOids;
128
130
 
129
- List *invalItems; /* other dependencies, as PlanInvalItems */
131
+ /* other dependencies, as PlanInvalItems */
132
+ List *invalItems;
130
133
 
131
- List *paramExecTypes; /* type OIDs for PARAM_EXEC Params */
134
+ /* type OIDs for PARAM_EXEC Params */
135
+ List *paramExecTypes;
132
136
 
133
- Index lastPHId; /* highest PlaceHolderVar ID assigned */
137
+ /* highest PlaceHolderVar ID assigned */
138
+ Index lastPHId;
134
139
 
135
- Index lastRowMarkId; /* highest PlanRowMark ID assigned */
140
+ /* highest PlanRowMark ID assigned */
141
+ Index lastRowMarkId;
136
142
 
137
- int lastPlanNodeId; /* highest plan node ID assigned */
143
+ /* highest plan node ID assigned */
144
+ int lastPlanNodeId;
138
145
 
139
- bool transientPlan; /* redo plan when TransactionXmin changes? */
146
+ /* redo plan when TransactionXmin changes? */
147
+ bool transientPlan;
140
148
 
141
- bool dependsOnRole; /* is plan specific to current role? */
149
+ /* is plan specific to current role? */
150
+ bool dependsOnRole;
142
151
 
143
- bool parallelModeOK; /* parallel mode potentially OK? */
152
+ /* parallel mode potentially OK? */
153
+ bool parallelModeOK;
144
154
 
145
- bool parallelModeNeeded; /* parallel mode actually required? */
155
+ /* parallel mode actually required? */
156
+ bool parallelModeNeeded;
146
157
 
147
- char maxParallelHazard; /* worst PROPARALLEL hazard level */
158
+ /* worst PROPARALLEL hazard level */
159
+ char maxParallelHazard;
148
160
 
149
- PartitionDirectory partition_directory; /* partition descriptors */
161
+ /* partition descriptors */
162
+ PartitionDirectory partition_directory pg_node_attr(read_write_ignore);
150
163
  } PlannerGlobal;
151
164
 
152
165
  /* macro for fetching the Plan associated with a SubPlan node */
@@ -165,6 +178,10 @@ typedef struct PlannerGlobal
165
178
  *
166
179
  * For reasons explained in optimizer/optimizer.h, we define the typedef
167
180
  * either here or in that header, whichever is read first.
181
+ *
182
+ * Not all fields are printed. (In some cases, there is no print support for
183
+ * the field type; in others, doing so would lead to infinite recursion or
184
+ * bloat dump output more than seems useful.)
168
185
  *----------
169
186
  */
170
187
  #ifndef HAVE_PLANNERINFO_TYPEDEF
@@ -174,15 +191,21 @@ typedef struct PlannerInfo PlannerInfo;
174
191
 
175
192
  struct PlannerInfo
176
193
  {
194
+ pg_node_attr(no_copy_equal, no_read, no_query_jumble)
195
+
177
196
  NodeTag type;
178
197
 
179
- Query *parse; /* the Query being planned */
198
+ /* the Query being planned */
199
+ Query *parse;
180
200
 
181
- PlannerGlobal *glob; /* global info for current planner run */
201
+ /* global info for current planner run */
202
+ PlannerGlobal *glob;
182
203
 
183
- Index query_level; /* 1 at the outermost Query */
204
+ /* 1 at the outermost Query */
205
+ Index query_level;
184
206
 
185
- PlannerInfo *parent_root; /* NULL at outermost Query */
207
+ /* NULL at outermost Query */
208
+ PlannerInfo *parent_root pg_node_attr(read_write_ignore);
186
209
 
187
210
  /*
188
211
  * plan_params contains the expressions that this query level needs to
@@ -190,7 +213,8 @@ struct PlannerInfo
190
213
  * outer_params contains the paramIds of PARAM_EXEC Params that outer
191
214
  * query levels will make available to this query level.
192
215
  */
193
- List *plan_params; /* list of PlannerParamItems, see below */
216
+ /* list of PlannerParamItems, see below */
217
+ List *plan_params;
194
218
  Bitmapset *outer_params;
195
219
 
196
220
  /*
@@ -200,39 +224,46 @@ struct PlannerInfo
200
224
  * does not correspond to a base relation, such as a join RTE or an
201
225
  * unreferenced view RTE; or if the RelOptInfo hasn't been made yet.
202
226
  */
203
- struct RelOptInfo **simple_rel_array; /* All 1-rel RelOptInfos */
204
- int simple_rel_array_size; /* allocated size of array */
227
+ struct RelOptInfo **simple_rel_array pg_node_attr(array_size(simple_rel_array_size));
228
+ /* allocated size of array */
229
+ int simple_rel_array_size;
205
230
 
206
231
  /*
207
232
  * simple_rte_array is the same length as simple_rel_array and holds
208
233
  * pointers to the associated rangetable entries. Using this is a shade
209
- * faster than using rt_fetch(), mostly due to fewer indirections.
234
+ * faster than using rt_fetch(), mostly due to fewer indirections. (Not
235
+ * printed because it'd be redundant with parse->rtable.)
210
236
  */
211
- RangeTblEntry **simple_rte_array; /* rangetable as an array */
237
+ RangeTblEntry **simple_rte_array pg_node_attr(read_write_ignore);
212
238
 
213
239
  /*
214
240
  * append_rel_array is the same length as the above arrays, and holds
215
241
  * pointers to the corresponding AppendRelInfo entry indexed by
216
242
  * child_relid, or NULL if the rel is not an appendrel child. The array
217
- * itself is not allocated if append_rel_list is empty.
243
+ * itself is not allocated if append_rel_list is empty. (Not printed
244
+ * because it'd be redundant with append_rel_list.)
218
245
  */
219
- struct AppendRelInfo **append_rel_array;
246
+ struct AppendRelInfo **append_rel_array pg_node_attr(read_write_ignore);
220
247
 
221
248
  /*
222
- * all_baserels is a Relids set of all base relids (but not "other"
223
- * relids) in the query; that is, the Relids identifier of the final join
224
- * we need to form. This is computed in make_one_rel, just before we
225
- * start making Paths.
249
+ * all_baserels is a Relids set of all base relids (but not joins or
250
+ * "other" rels) in the query. This is computed in deconstruct_jointree.
226
251
  */
227
252
  Relids all_baserels;
228
253
 
229
254
  /*
230
- * nullable_baserels is a Relids set of base relids that are nullable by
231
- * some outer join in the jointree; these are rels that are potentially
232
- * nullable below the WHERE clause, SELECT targetlist, etc. This is
233
- * computed in deconstruct_jointree.
255
+ * outer_join_rels is a Relids set of all outer-join relids in the query.
256
+ * This is computed in deconstruct_jointree.
257
+ */
258
+ Relids outer_join_rels;
259
+
260
+ /*
261
+ * all_query_rels is a Relids set of all base relids and outer join relids
262
+ * (but not "other" relids) in the query. This is the Relids identifier
263
+ * of the final join we need to form. This is computed in
264
+ * deconstruct_jointree.
234
265
  */
235
- Relids nullable_baserels;
266
+ Relids all_query_rels;
236
267
 
237
268
  /*
238
269
  * join_rel_list is a list of all join-relation RelOptInfos we have
@@ -243,8 +274,8 @@ struct PlannerInfo
243
274
  * even when using the hash table for lookups; this simplifies life for
244
275
  * GEQO.
245
276
  */
246
- List *join_rel_list; /* list of join-relation RelOptInfos */
247
- struct HTAB *join_rel_hash; /* optional hashtable for join relations */
277
+ List *join_rel_list;
278
+ struct HTAB *join_rel_hash pg_node_attr(read_write_ignore);
248
279
 
249
280
  /*
250
281
  * When doing a dynamic-programming-style join search, join_rel_level[k]
@@ -252,113 +283,264 @@ struct PlannerInfo
252
283
  * join_cur_level is the current level. New join-relation RelOptInfos are
253
284
  * automatically added to the join_rel_level[join_cur_level] list.
254
285
  * join_rel_level is NULL if not in use.
286
+ *
287
+ * Note: we've already printed all baserel and joinrel RelOptInfos above,
288
+ * so we don't dump join_rel_level or other lists of RelOptInfos.
255
289
  */
256
- List **join_rel_level; /* lists of join-relation RelOptInfos */
257
- int join_cur_level; /* index of list being extended */
290
+ /* lists of join-relation RelOptInfos */
291
+ List **join_rel_level pg_node_attr(read_write_ignore);
292
+ /* index of list being extended */
293
+ int join_cur_level;
258
294
 
259
- List *init_plans; /* init SubPlans for query */
295
+ /* init SubPlans for query */
296
+ List *init_plans;
260
297
 
261
- List *cte_plan_ids; /* per-CTE-item list of subplan IDs */
298
+ /*
299
+ * per-CTE-item list of subplan IDs (or -1 if no subplan was made for that
300
+ * CTE)
301
+ */
302
+ List *cte_plan_ids;
262
303
 
263
- List *multiexpr_params; /* List of Lists of Params for MULTIEXPR
264
- * subquery outputs */
304
+ /* List of Lists of Params for MULTIEXPR subquery outputs */
305
+ List *multiexpr_params;
265
306
 
266
- List *eq_classes; /* list of active EquivalenceClasses */
307
+ /* list of JoinDomains used in the query (higher ones first) */
308
+ List *join_domains;
267
309
 
268
- bool ec_merging_done; /* set true once ECs are canonical */
310
+ /* list of active EquivalenceClasses */
311
+ List *eq_classes;
269
312
 
270
- List *canon_pathkeys; /* list of "canonical" PathKeys */
313
+ /* set true once ECs are canonical */
314
+ bool ec_merging_done;
271
315
 
272
- List *left_join_clauses; /* list of RestrictInfos for mergejoinable
273
- * outer join clauses w/nonnullable var on
274
- * left */
316
+ /* list of "canonical" PathKeys */
317
+ List *canon_pathkeys;
275
318
 
276
- List *right_join_clauses; /* list of RestrictInfos for mergejoinable
277
- * outer join clauses w/nonnullable var on
278
- * right */
319
+ /*
320
+ * list of OuterJoinClauseInfos for mergejoinable outer join clauses
321
+ * w/nonnullable var on left
322
+ */
323
+ List *left_join_clauses;
279
324
 
280
- List *full_join_clauses; /* list of RestrictInfos for mergejoinable
281
- * full join clauses */
325
+ /*
326
+ * list of OuterJoinClauseInfos for mergejoinable outer join clauses
327
+ * w/nonnullable var on right
328
+ */
329
+ List *right_join_clauses;
282
330
 
283
- List *join_info_list; /* list of SpecialJoinInfos */
331
+ /*
332
+ * list of OuterJoinClauseInfos for mergejoinable full join clauses
333
+ */
334
+ List *full_join_clauses;
335
+
336
+ /* list of SpecialJoinInfos */
337
+ List *join_info_list;
338
+
339
+ /* counter for assigning RestrictInfo serial numbers */
340
+ int last_rinfo_serial;
341
+
342
+ /*
343
+ * all_result_relids is empty for SELECT, otherwise it contains at least
344
+ * parse->resultRelation. For UPDATE/DELETE/MERGE across an inheritance
345
+ * or partitioning tree, the result rel's child relids are added. When
346
+ * using multi-level partitioning, intermediate partitioned rels are
347
+ * included. leaf_result_relids is similar except that only actual result
348
+ * tables, not partitioned tables, are included in it.
349
+ */
350
+ /* set of all result relids */
351
+ Relids all_result_relids;
352
+ /* set of all leaf relids */
353
+ Relids leaf_result_relids;
284
354
 
285
355
  /*
356
+ * list of AppendRelInfos
357
+ *
286
358
  * Note: for AppendRelInfos describing partitions of a partitioned table,
287
359
  * we guarantee that partitions that come earlier in the partitioned
288
360
  * table's PartitionDesc will appear earlier in append_rel_list.
289
361
  */
290
- List *append_rel_list; /* list of AppendRelInfos */
362
+ List *append_rel_list;
363
+
364
+ /* list of RowIdentityVarInfos */
365
+ List *row_identity_vars;
366
+
367
+ /* list of PlanRowMarks */
368
+ List *rowMarks;
291
369
 
292
- List *rowMarks; /* list of PlanRowMarks */
370
+ /* list of PlaceHolderInfos */
371
+ List *placeholder_list;
293
372
 
294
- List *placeholder_list; /* list of PlaceHolderInfos */
373
+ /* array of PlaceHolderInfos indexed by phid */
374
+ struct PlaceHolderInfo **placeholder_array pg_node_attr(read_write_ignore, array_size(placeholder_array_size));
375
+ /* allocated size of array */
376
+ int placeholder_array_size pg_node_attr(read_write_ignore);
295
377
 
296
- List *fkey_list; /* list of ForeignKeyOptInfos */
378
+ /* list of ForeignKeyOptInfos */
379
+ List *fkey_list;
297
380
 
298
- List *query_pathkeys; /* desired pathkeys for query_planner() */
381
+ /* desired pathkeys for query_planner() */
382
+ List *query_pathkeys;
299
383
 
300
- List *group_pathkeys; /* groupClause pathkeys, if any */
301
- List *window_pathkeys; /* pathkeys of bottom window, if any */
302
- List *distinct_pathkeys; /* distinctClause pathkeys, if any */
303
- List *sort_pathkeys; /* sortClause pathkeys, if any */
384
+ /* groupClause pathkeys, if any */
385
+ List *group_pathkeys;
304
386
 
305
- List *part_schemes; /* Canonicalised partition schemes used in the
306
- * query. */
387
+ /*
388
+ * The number of elements in the group_pathkeys list which belong to the
389
+ * GROUP BY clause. Additional ones belong to ORDER BY / DISTINCT
390
+ * aggregates.
391
+ */
392
+ int num_groupby_pathkeys;
307
393
 
308
- List *initial_rels; /* RelOptInfos we are now trying to join */
394
+ /* pathkeys of bottom window, if any */
395
+ List *window_pathkeys;
396
+ /* distinctClause pathkeys, if any */
397
+ List *distinct_pathkeys;
398
+ /* sortClause pathkeys, if any */
399
+ List *sort_pathkeys;
309
400
 
310
- /* Use fetch_upper_rel() to get any particular upper rel */
311
- List *upper_rels[UPPERREL_FINAL + 1]; /* upper-rel RelOptInfos */
401
+ /* Canonicalised partition schemes used in the query. */
402
+ List *part_schemes pg_node_attr(read_write_ignore);
403
+
404
+ /* RelOptInfos we are now trying to join */
405
+ List *initial_rels pg_node_attr(read_write_ignore);
406
+
407
+ /*
408
+ * Upper-rel RelOptInfos. Use fetch_upper_rel() to get any particular
409
+ * upper rel.
410
+ */
411
+ List *upper_rels[UPPERREL_FINAL + 1] pg_node_attr(read_write_ignore);
312
412
 
313
413
  /* Result tlists chosen by grouping_planner for upper-stage processing */
314
- struct PathTarget *upper_targets[UPPERREL_FINAL + 1];
414
+ struct PathTarget *upper_targets[UPPERREL_FINAL + 1] pg_node_attr(read_write_ignore);
415
+
416
+ /*
417
+ * The fully-processed groupClause is kept here. It differs from
418
+ * parse->groupClause in that we remove any items that we can prove
419
+ * redundant, so that only the columns named here actually need to be
420
+ * compared to determine grouping. Note that it's possible for *all* the
421
+ * items to be proven redundant, implying that there is only one group
422
+ * containing all the query's rows. Hence, if you want to check whether
423
+ * GROUP BY was specified, test for nonempty parse->groupClause, not for
424
+ * nonempty processed_groupClause.
425
+ *
426
+ * Currently, when grouping sets are specified we do not attempt to
427
+ * optimize the groupClause, so that processed_groupClause will be
428
+ * identical to parse->groupClause.
429
+ */
430
+ List *processed_groupClause;
431
+
432
+ /*
433
+ * The fully-processed distinctClause is kept here. It differs from
434
+ * parse->distinctClause in that we remove any items that we can prove
435
+ * redundant, so that only the columns named here actually need to be
436
+ * compared to determine uniqueness. Note that it's possible for *all*
437
+ * the items to be proven redundant, implying that there should be only
438
+ * one output row. Hence, if you want to check whether DISTINCT was
439
+ * specified, test for nonempty parse->distinctClause, not for nonempty
440
+ * processed_distinctClause.
441
+ */
442
+ List *processed_distinctClause;
315
443
 
316
444
  /*
317
445
  * The fully-processed targetlist is kept here. It differs from
318
- * parse->targetList in that (for INSERT and UPDATE) it's been reordered
319
- * to match the target table, and defaults have been filled in. Also,
320
- * additional resjunk targets may be present. preprocess_targetlist()
321
- * does most of this work, but note that more resjunk targets can get
322
- * added during appendrel expansion. (Hence, upper_targets mustn't get
323
- * set up till after that.)
446
+ * parse->targetList in that (for INSERT) it's been reordered to match the
447
+ * target table, and defaults have been filled in. Also, additional
448
+ * resjunk targets may be present. preprocess_targetlist() does most of
449
+ * that work, but note that more resjunk targets can get added during
450
+ * appendrel expansion. (Hence, upper_targets mustn't get set up till
451
+ * after that.)
324
452
  */
325
453
  List *processed_tlist;
326
454
 
327
- /* Fields filled during create_plan() for use in setrefs.c */
328
- AttrNumber *grouping_map; /* for GroupingFunc fixup */
329
- List *minmax_aggs; /* List of MinMaxAggInfos */
455
+ /*
456
+ * For UPDATE, this list contains the target table's attribute numbers to
457
+ * which the first N entries of processed_tlist are to be assigned. (Any
458
+ * additional entries in processed_tlist must be resjunk.) DO NOT use the
459
+ * resnos in processed_tlist to identify the UPDATE target columns.
460
+ */
461
+ List *update_colnos;
462
+
463
+ /*
464
+ * Fields filled during create_plan() for use in setrefs.c
465
+ */
466
+ /* for GroupingFunc fixup (can't print: array length not known here) */
467
+ AttrNumber *grouping_map pg_node_attr(read_write_ignore);
468
+ /* List of MinMaxAggInfos */
469
+ List *minmax_aggs;
470
+
471
+ /* context holding PlannerInfo */
472
+ MemoryContext planner_cxt pg_node_attr(read_write_ignore);
330
473
 
331
- MemoryContext planner_cxt; /* context holding PlannerInfo */
474
+ /* # of pages in all non-dummy tables of query */
475
+ Cardinality total_table_pages;
332
476
 
333
- double total_table_pages; /* # of pages in all non-dummy tables of
334
- * query */
477
+ /* tuple_fraction passed to query_planner */
478
+ Selectivity tuple_fraction;
479
+ /* limit_tuples passed to query_planner */
480
+ Cardinality limit_tuples;
335
481
 
336
- double tuple_fraction; /* tuple_fraction passed to query_planner */
337
- double limit_tuples; /* limit_tuples passed to query_planner */
482
+ /*
483
+ * Minimum security_level for quals. Note: qual_security_level is zero if
484
+ * there are no securityQuals.
485
+ */
486
+ Index qual_security_level;
487
+
488
+ /* true if any RTEs are RTE_JOIN kind */
489
+ bool hasJoinRTEs;
490
+ /* true if any RTEs are marked LATERAL */
491
+ bool hasLateralRTEs;
492
+ /* true if havingQual was non-null */
493
+ bool hasHavingQual;
494
+ /* true if any RestrictInfo has pseudoconstant = true */
495
+ bool hasPseudoConstantQuals;
496
+ /* true if we've made any of those */
497
+ bool hasAlternativeSubPlans;
498
+ /* true once we're no longer allowed to add PlaceHolderInfos */
499
+ bool placeholdersFrozen;
500
+ /* true if planning a recursive WITH item */
501
+ bool hasRecursion;
338
502
 
339
- Index qual_security_level; /* minimum security_level for quals */
340
- /* Note: qual_security_level is zero if there are no securityQuals */
503
+ /*
504
+ * Information about aggregates. Filled by preprocess_aggrefs().
505
+ */
506
+ /* AggInfo structs */
507
+ List *agginfos;
508
+ /* AggTransInfo structs */
509
+ List *aggtransinfos;
510
+ /* number of aggs with DISTINCT/ORDER BY/WITHIN GROUP */
511
+ int numOrderedAggs;
512
+ /* does any agg not support partial mode? */
513
+ bool hasNonPartialAggs;
514
+ /* is any partial agg non-serializable? */
515
+ bool hasNonSerialAggs;
341
516
 
342
- InheritanceKind inhTargetKind; /* indicates if the target relation is an
343
- * inheritance child or partition or a
344
- * partitioned table */
345
- bool hasJoinRTEs; /* true if any RTEs are RTE_JOIN kind */
346
- bool hasLateralRTEs; /* true if any RTEs are marked LATERAL */
347
- bool hasHavingQual; /* true if havingQual was non-null */
348
- bool hasPseudoConstantQuals; /* true if any RestrictInfo has
349
- * pseudoconstant = true */
350
- bool hasRecursion; /* true if planning a recursive WITH item */
517
+ /*
518
+ * These fields are used only when hasRecursion is true:
519
+ */
520
+ /* PARAM_EXEC ID for the work table */
521
+ int wt_param_id;
522
+ /* a path for non-recursive term */
523
+ struct Path *non_recursive_path;
351
524
 
352
- /* These fields are used only when hasRecursion is true: */
353
- int wt_param_id; /* PARAM_EXEC ID for the work table */
354
- struct Path *non_recursive_path; /* a path for non-recursive term */
525
+ /*
526
+ * These fields are workspace for createplan.c
527
+ */
528
+ /* outer rels above current node */
529
+ Relids curOuterRels;
530
+ /* not-yet-assigned NestLoopParams */
531
+ List *curOuterParams;
355
532
 
356
- /* These fields are workspace for createplan.c */
357
- Relids curOuterRels; /* outer rels above current node */
358
- List *curOuterParams; /* not-yet-assigned NestLoopParams */
533
+ /*
534
+ * These fields are workspace for setrefs.c. Each is an array
535
+ * corresponding to glob->subplans. (We could probably teach
536
+ * gen_node_support.pl how to determine the array length, but it doesn't
537
+ * seem worth the trouble, so just mark them read_write_ignore.)
538
+ */
539
+ bool *isAltSubplan pg_node_attr(read_write_ignore);
540
+ bool *isUsedSubplan pg_node_attr(read_write_ignore);
359
541
 
360
542
  /* optional private data for join_search_hook, e.g., GEQO */
361
- void *join_search_private;
543
+ void *join_search_private pg_node_attr(read_write_ignore);
362
544
 
363
545
  /* Does this query modify any partition key columns? */
364
546
  bool partColsUpdated;
@@ -414,9 +596,10 @@ typedef struct PartitionSchemeData *PartitionScheme;
414
596
  * or the output of a sub-SELECT or function that appears in the range table.
415
597
  * In either case it is uniquely identified by an RT index. A "joinrel"
416
598
  * is the joining of two or more base rels. A joinrel is identified by
417
- * the set of RT indexes for its component baserels. We create RelOptInfo
418
- * nodes for each baserel and joinrel, and store them in the PlannerInfo's
419
- * simple_rel_array and join_rel_list respectively.
599
+ * the set of RT indexes for its component baserels, along with RT indexes
600
+ * for any outer joins it has computed. We create RelOptInfo nodes for each
601
+ * baserel and joinrel, and store them in the PlannerInfo's simple_rel_array
602
+ * and join_rel_list respectively.
420
603
  *
421
604
  * Note that there is only one joinrel for any given set of component
422
605
  * baserels, no matter what order we assemble them in; so an unordered
@@ -449,14 +632,13 @@ typedef struct PartitionSchemeData *PartitionScheme;
449
632
  * Many of the fields in these RelOptInfos are meaningless, but their Path
450
633
  * fields always hold Paths showing ways to do that processing step.
451
634
  *
452
- * Lastly, there is a RelOptKind for "dead" relations, which are base rels
453
- * that we have proven we don't need to join after all.
454
- *
455
635
  * Parts of this data structure are specific to various scan and join
456
636
  * mechanisms. It didn't seem worth creating new node types for them.
457
637
  *
458
- * relids - Set of base-relation identifiers; it is a base relation
459
- * if there is just one, a join relation if more than one
638
+ * relids - Set of relation identifiers (RT indexes). This is a base
639
+ * relation if there is just one, a join relation if more;
640
+ * in the join case, RT indexes of any outer joins formed
641
+ * at or below this join are included along with baserels
460
642
  * rows - estimated number of tuples in the relation after restriction
461
643
  * clauses have been applied (ie, output rows of a plan for it)
462
644
  * consider_startup - true if there is any value in keeping plain paths for
@@ -498,12 +680,13 @@ typedef struct PartitionSchemeData *PartitionScheme;
498
680
  * the attribute is needed as part of final targetlist
499
681
  * attr_widths - cache space for per-attribute width estimates;
500
682
  * zero means not computed yet
683
+ * nulling_relids - relids of outer joins that can null this rel
501
684
  * lateral_vars - lateral cross-references of rel, if any (list of
502
685
  * Vars and PlaceHolderVars)
503
686
  * lateral_referencers - relids of rels that reference this one laterally
504
687
  * (includes both direct and indirect lateral references)
505
688
  * indexlist - list of IndexOptInfo nodes for relation's indexes
506
- * (always NIL if it's not a table)
689
+ * (always NIL if it's not a table or partitioned table)
507
690
  * pages - number of disk pages in relation (zero if not a table)
508
691
  * tuples - number of tuples in relation (not considering restrictions)
509
692
  * allvisfrac - fraction of disk pages that are marked all-visible
@@ -602,9 +785,6 @@ typedef struct PartitionSchemeData *PartitionScheme;
602
785
  * part_rels - RelOptInfos for each partition
603
786
  * all_partrels - Relids set of all partition relids
604
787
  * partexprs, nullable_partexprs - Partition key expressions
605
- * partitioned_child_rels - RT indexes of unpruned partitions of
606
- * this relation that are partitioned tables
607
- * themselves, in hierarchical order
608
788
  *
609
789
  * The partexprs and nullable_partexprs arrays each contain
610
790
  * part_scheme->partnatts elements. Each of the elements is a list of
@@ -618,8 +798,15 @@ typedef struct PartitionSchemeData *PartitionScheme;
618
798
  * Furthermore, FULL JOINs add extra nullable_partexprs expressions
619
799
  * corresponding to COALESCE expressions of the left and right join columns,
620
800
  * to simplify matching join clauses to those lists.
801
+ *
802
+ * Not all fields are printed. (In some cases, there is no print support for
803
+ * the field type.)
621
804
  *----------
622
805
  */
806
+
807
+ /* Bitmask of flags supported by table AMs */
808
+ #define AMFLAG_HAS_TID_RANGE (1 << 0)
809
+
623
810
  typedef enum RelOptKind
624
811
  {
625
812
  RELOPT_BASEREL,
@@ -627,8 +814,7 @@ typedef enum RelOptKind
627
814
  RELOPT_OTHER_MEMBER_REL,
628
815
  RELOPT_OTHER_JOINREL,
629
816
  RELOPT_UPPER_REL,
630
- RELOPT_OTHER_UPPER_REL,
631
- RELOPT_DEADREL
817
+ RELOPT_OTHER_UPPER_REL
632
818
  } RelOptKind;
633
819
 
634
820
  /*
@@ -657,25 +843,43 @@ typedef enum RelOptKind
657
843
 
658
844
  typedef struct RelOptInfo
659
845
  {
846
+ pg_node_attr(no_copy_equal, no_read, no_query_jumble)
847
+
660
848
  NodeTag type;
661
849
 
662
850
  RelOptKind reloptkind;
663
851
 
664
- /* all relations included in this RelOptInfo */
665
- Relids relids; /* set of base relids (rangetable indexes) */
852
+ /*
853
+ * all relations included in this RelOptInfo; set of base + OJ relids
854
+ * (rangetable indexes)
855
+ */
856
+ Relids relids;
666
857
 
667
- /* size estimates generated by planner */
668
- double rows; /* estimated number of result tuples */
858
+ /*
859
+ * size estimates generated by planner
860
+ */
861
+ /* estimated number of result tuples */
862
+ Cardinality rows;
669
863
 
670
- /* per-relation planner control flags */
671
- bool consider_startup; /* keep cheap-startup-cost paths? */
672
- bool consider_param_startup; /* ditto, for parameterized paths? */
673
- bool consider_parallel; /* consider parallel paths? */
864
+ /*
865
+ * per-relation planner control flags
866
+ */
867
+ /* keep cheap-startup-cost paths? */
868
+ bool consider_startup;
869
+ /* ditto, for parameterized paths? */
870
+ bool consider_param_startup;
871
+ /* consider parallel paths? */
872
+ bool consider_parallel;
674
873
 
675
- /* default result targetlist for Paths scanning this relation */
676
- struct PathTarget *reltarget; /* list of Vars/Exprs, cost, width */
874
+ /*
875
+ * default result targetlist for Paths scanning this relation; list of
876
+ * Vars/Exprs, cost, width
877
+ */
878
+ struct PathTarget *reltarget;
677
879
 
678
- /* materialization information */
880
+ /*
881
+ * materialization information
882
+ */
679
883
  List *pathlist; /* Path structures */
680
884
  List *ppilist; /* ParamPathInfos used in pathlist */
681
885
  List *partial_pathlist; /* partial Paths */
@@ -684,75 +888,146 @@ typedef struct RelOptInfo
684
888
  struct Path *cheapest_unique_path;
685
889
  List *cheapest_parameterized_paths;
686
890
 
687
- /* parameterization information needed for both base rels and join rels */
688
- /* (see also lateral_vars and lateral_referencers) */
689
- Relids direct_lateral_relids; /* rels directly laterally referenced */
690
- Relids lateral_relids; /* minimum parameterization of rel */
891
+ /*
892
+ * parameterization information needed for both base rels and join rels
893
+ * (see also lateral_vars and lateral_referencers)
894
+ */
895
+ /* rels directly laterally referenced */
896
+ Relids direct_lateral_relids;
897
+ /* minimum parameterization of rel */
898
+ Relids lateral_relids;
691
899
 
692
- /* information about a base rel (not set for join rels!) */
900
+ /*
901
+ * information about a base rel (not set for join rels!)
902
+ */
693
903
  Index relid;
694
- Oid reltablespace; /* containing tablespace */
695
- RTEKind rtekind; /* RELATION, SUBQUERY, FUNCTION, etc */
696
- AttrNumber min_attr; /* smallest attrno of rel (often <0) */
697
- AttrNumber max_attr; /* largest attrno of rel */
698
- Relids *attr_needed; /* array indexed [min_attr .. max_attr] */
699
- int32 *attr_widths; /* array indexed [min_attr .. max_attr] */
700
- List *lateral_vars; /* LATERAL Vars and PHVs referenced by rel */
701
- Relids lateral_referencers; /* rels that reference me laterally */
702
- List *indexlist; /* list of IndexOptInfo */
703
- List *statlist; /* list of StatisticExtInfo */
704
- BlockNumber pages; /* size estimates derived from pg_class */
705
- double tuples;
904
+ /* containing tablespace */
905
+ Oid reltablespace;
906
+ /* RELATION, SUBQUERY, FUNCTION, etc */
907
+ RTEKind rtekind;
908
+ /* smallest attrno of rel (often <0) */
909
+ AttrNumber min_attr;
910
+ /* largest attrno of rel */
911
+ AttrNumber max_attr;
912
+ /* array indexed [min_attr .. max_attr] */
913
+ Relids *attr_needed pg_node_attr(read_write_ignore);
914
+ /* array indexed [min_attr .. max_attr] */
915
+ int32 *attr_widths pg_node_attr(read_write_ignore);
916
+ /* relids of outer joins that can null this baserel */
917
+ Relids nulling_relids;
918
+ /* LATERAL Vars and PHVs referenced by rel */
919
+ List *lateral_vars;
920
+ /* rels that reference this baserel laterally */
921
+ Relids lateral_referencers;
922
+ /* list of IndexOptInfo */
923
+ List *indexlist;
924
+ /* list of StatisticExtInfo */
925
+ List *statlist;
926
+ /* size estimates derived from pg_class */
927
+ BlockNumber pages;
928
+ Cardinality tuples;
706
929
  double allvisfrac;
707
- Bitmapset *eclass_indexes; /* Indexes in PlannerInfo's eq_classes list of
708
- * ECs that mention this rel */
930
+ /* indexes in PlannerInfo's eq_classes list of ECs that mention this rel */
931
+ Bitmapset *eclass_indexes;
709
932
  PlannerInfo *subroot; /* if subquery */
710
933
  List *subplan_params; /* if subquery */
711
- int rel_parallel_workers; /* wanted number of parallel workers */
934
+ /* wanted number of parallel workers */
935
+ int rel_parallel_workers;
936
+ /* Bitmask of optional features supported by the table AM */
937
+ uint32 amflags;
712
938
 
713
- /* Information about foreign tables and foreign joins */
714
- Oid serverid; /* identifies server for the table or join */
715
- Oid userid; /* identifies user to check access as */
716
- bool useridiscurrent; /* join is only valid for current user */
939
+ /*
940
+ * Information about foreign tables and foreign joins
941
+ */
942
+ /* identifies server for the table or join */
943
+ Oid serverid;
944
+ /* identifies user to check access as; 0 means to check as current user */
945
+ Oid userid;
946
+ /* join is only valid for current user */
947
+ bool useridiscurrent;
717
948
  /* use "struct FdwRoutine" to avoid including fdwapi.h here */
718
- struct FdwRoutine *fdwroutine;
719
- void *fdw_private;
720
-
721
- /* cache space for remembering if we have proven this relation unique */
722
- List *unique_for_rels; /* known unique for these other relid
723
- * set(s) */
724
- List *non_unique_for_rels; /* known not unique for these set(s) */
725
-
726
- /* used by various scans and joins: */
727
- List *baserestrictinfo; /* RestrictInfo structures (if base rel) */
728
- QualCost baserestrictcost; /* cost of evaluating the above */
729
- Index baserestrict_min_security; /* min security_level found in
730
- * baserestrictinfo */
731
- List *joininfo; /* RestrictInfo structures for join clauses
732
- * involving this rel */
733
- bool has_eclass_joins; /* T means joininfo is incomplete */
734
-
735
- /* used by partitionwise joins: */
736
- bool consider_partitionwise_join; /* consider partitionwise join
737
- * paths? (if partitioned rel) */
738
- Relids top_parent_relids; /* Relids of topmost parents (if "other"
739
- * rel) */
740
-
741
- /* used for partitioned relations: */
742
- PartitionScheme part_scheme; /* Partitioning scheme */
743
- int nparts; /* Number of partitions; -1 if not yet set; in
744
- * case of a join relation 0 means it's
745
- * considered unpartitioned */
746
- struct PartitionBoundInfoData *boundinfo; /* Partition bounds */
747
- bool partbounds_merged; /* True if partition bounds were created
748
- * by partition_bounds_merge() */
749
- List *partition_qual; /* Partition constraint, if not the root */
750
- struct RelOptInfo **part_rels; /* Array of RelOptInfos of partitions,
751
- * stored in the same order as bounds */
752
- Relids all_partrels; /* Relids set of all partition relids */
753
- List **partexprs; /* Non-nullable partition key expressions */
754
- List **nullable_partexprs; /* Nullable partition key expressions */
755
- List *partitioned_child_rels; /* List of RT indexes */
949
+ struct FdwRoutine *fdwroutine pg_node_attr(read_write_ignore);
950
+ void *fdw_private pg_node_attr(read_write_ignore);
951
+
952
+ /*
953
+ * cache space for remembering if we have proven this relation unique
954
+ */
955
+ /* known unique for these other relid set(s) */
956
+ List *unique_for_rels;
957
+ /* known not unique for these set(s) */
958
+ List *non_unique_for_rels;
959
+
960
+ /*
961
+ * used by various scans and joins:
962
+ */
963
+ /* RestrictInfo structures (if base rel) */
964
+ List *baserestrictinfo;
965
+ /* cost of evaluating the above */
966
+ QualCost baserestrictcost;
967
+ /* min security_level found in baserestrictinfo */
968
+ Index baserestrict_min_security;
969
+ /* RestrictInfo structures for join clauses involving this rel */
970
+ List *joininfo;
971
+ /* T means joininfo is incomplete */
972
+ bool has_eclass_joins;
973
+
974
+ /*
975
+ * used by partitionwise joins:
976
+ */
977
+ /* consider partitionwise join paths? (if partitioned rel) */
978
+ bool consider_partitionwise_join;
979
+
980
+ /*
981
+ * inheritance links, if this is an otherrel (otherwise NULL):
982
+ */
983
+ /* Immediate parent relation (dumping it would be too verbose) */
984
+ struct RelOptInfo *parent pg_node_attr(read_write_ignore);
985
+ /* Topmost parent relation (dumping it would be too verbose) */
986
+ struct RelOptInfo *top_parent pg_node_attr(read_write_ignore);
987
+ /* Relids of topmost parent (redundant, but handy) */
988
+ Relids top_parent_relids;
989
+
990
+ /*
991
+ * used for partitioned relations:
992
+ */
993
+ /* Partitioning scheme */
994
+ PartitionScheme part_scheme pg_node_attr(read_write_ignore);
995
+
996
+ /*
997
+ * Number of partitions; -1 if not yet set; in case of a join relation 0
998
+ * means it's considered unpartitioned
999
+ */
1000
+ int nparts;
1001
+ /* Partition bounds */
1002
+ struct PartitionBoundInfoData *boundinfo pg_node_attr(read_write_ignore);
1003
+ /* True if partition bounds were created by partition_bounds_merge() */
1004
+ bool partbounds_merged;
1005
+ /* Partition constraint, if not the root */
1006
+ List *partition_qual;
1007
+
1008
+ /*
1009
+ * Array of RelOptInfos of partitions, stored in the same order as bounds
1010
+ * (don't print, too bulky and duplicative)
1011
+ */
1012
+ struct RelOptInfo **part_rels pg_node_attr(read_write_ignore);
1013
+
1014
+ /*
1015
+ * Bitmap with members acting as indexes into the part_rels[] array to
1016
+ * indicate which partitions survived partition pruning.
1017
+ */
1018
+ Bitmapset *live_parts;
1019
+ /* Relids set of all partition relids */
1020
+ Relids all_partrels;
1021
+
1022
+ /*
1023
+ * These arrays are of length partkey->partnatts, which we don't have at
1024
+ * hand, so don't try to print
1025
+ */
1026
+
1027
+ /* Non-nullable partition key expressions */
1028
+ List **partexprs pg_node_attr(read_write_ignore);
1029
+ /* Nullable partition key expressions */
1030
+ List **nullable_partexprs pg_node_attr(read_write_ignore);
756
1031
  } RelOptInfo;
757
1032
 
758
1033
  /*
@@ -813,60 +1088,104 @@ typedef struct IndexOptInfo IndexOptInfo;
813
1088
 
814
1089
  struct IndexOptInfo
815
1090
  {
1091
+ pg_node_attr(no_copy_equal, no_read, no_query_jumble)
1092
+
816
1093
  NodeTag type;
817
1094
 
818
- Oid indexoid; /* OID of the index relation */
819
- Oid reltablespace; /* tablespace of index (not table) */
820
- RelOptInfo *rel; /* back-link to index's table */
821
-
822
- /* index-size statistics (from pg_class and elsewhere) */
823
- BlockNumber pages; /* number of disk pages in index */
824
- double tuples; /* number of index tuples in index */
825
- int tree_height; /* index tree height, or -1 if unknown */
826
-
827
- /* index descriptor information */
828
- int ncolumns; /* number of columns in index */
829
- int nkeycolumns; /* number of key columns in index */
830
- int *indexkeys; /* column numbers of index's attributes both
831
- * key and included columns, or 0 */
832
- Oid *indexcollations; /* OIDs of collations of index columns */
833
- Oid *opfamily; /* OIDs of operator families for columns */
834
- Oid *opcintype; /* OIDs of opclass declared input data types */
835
- Oid *sortopfamily; /* OIDs of btree opfamilies, if orderable */
836
- bool *reverse_sort; /* is sort order descending? */
837
- bool *nulls_first; /* do NULLs come first in the sort order? */
838
- bytea **opclassoptions; /* opclass-specific options for columns */
839
- bool *canreturn; /* which index cols can be returned in an
840
- * index-only scan? */
841
- Oid relam; /* OID of the access method (in pg_am) */
842
-
843
- List *indexprs; /* expressions for non-simple index columns */
844
- List *indpred; /* predicate if a partial index, else NIL */
845
-
846
- List *indextlist; /* targetlist representing index columns */
847
-
848
- List *indrestrictinfo; /* parent relation's baserestrictinfo
849
- * list, less any conditions implied by
850
- * the index's predicate (unless it's a
851
- * target rel, see comments in
852
- * check_index_predicates()) */
853
-
854
- bool predOK; /* true if index predicate matches query */
855
- bool unique; /* true if a unique index */
856
- bool immediate; /* is uniqueness enforced immediately? */
857
- bool hypothetical; /* true if index doesn't really exist */
858
-
859
- /* Remaining fields are copied from the index AM's API struct: */
860
- bool amcanorderbyop; /* does AM support order by operator result? */
861
- bool amoptionalkey; /* can query omit key for the first column? */
862
- bool amsearcharray; /* can AM handle ScalarArrayOpExpr quals? */
863
- bool amsearchnulls; /* can AM search for NULL/NOT NULL entries? */
864
- bool amhasgettuple; /* does AM have amgettuple interface? */
865
- bool amhasgetbitmap; /* does AM have amgetbitmap interface? */
866
- bool amcanparallel; /* does AM support parallel scan? */
867
- bool amcanmarkpos; /* does AM support mark/restore? */
1095
+ /* OID of the index relation */
1096
+ Oid indexoid;
1097
+ /* tablespace of index (not table) */
1098
+ Oid reltablespace;
1099
+ /* back-link to index's table; don't print, else infinite recursion */
1100
+ RelOptInfo *rel pg_node_attr(read_write_ignore);
1101
+
1102
+ /*
1103
+ * index-size statistics (from pg_class and elsewhere)
1104
+ */
1105
+ /* number of disk pages in index */
1106
+ BlockNumber pages;
1107
+ /* number of index tuples in index */
1108
+ Cardinality tuples;
1109
+ /* index tree height, or -1 if unknown */
1110
+ int tree_height;
1111
+
1112
+ /*
1113
+ * index descriptor information
1114
+ */
1115
+ /* number of columns in index */
1116
+ int ncolumns;
1117
+ /* number of key columns in index */
1118
+ int nkeycolumns;
1119
+
1120
+ /*
1121
+ * table column numbers of index's columns (both key and included
1122
+ * columns), or 0 for expression columns
1123
+ */
1124
+ int *indexkeys pg_node_attr(array_size(ncolumns));
1125
+ /* OIDs of collations of index columns */
1126
+ Oid *indexcollations pg_node_attr(array_size(nkeycolumns));
1127
+ /* OIDs of operator families for columns */
1128
+ Oid *opfamily pg_node_attr(array_size(nkeycolumns));
1129
+ /* OIDs of opclass declared input data types */
1130
+ Oid *opcintype pg_node_attr(array_size(nkeycolumns));
1131
+ /* OIDs of btree opfamilies, if orderable. NULL if partitioned index */
1132
+ Oid *sortopfamily pg_node_attr(array_size(nkeycolumns));
1133
+ /* is sort order descending? or NULL if partitioned index */
1134
+ bool *reverse_sort pg_node_attr(array_size(nkeycolumns));
1135
+ /* do NULLs come first in the sort order? or NULL if partitioned index */
1136
+ bool *nulls_first pg_node_attr(array_size(nkeycolumns));
1137
+ /* opclass-specific options for columns */
1138
+ bytea **opclassoptions pg_node_attr(read_write_ignore);
1139
+ /* which index cols can be returned in an index-only scan? */
1140
+ bool *canreturn pg_node_attr(array_size(ncolumns));
1141
+ /* OID of the access method (in pg_am) */
1142
+ Oid relam;
1143
+
1144
+ /*
1145
+ * expressions for non-simple index columns; redundant to print since we
1146
+ * print indextlist
1147
+ */
1148
+ List *indexprs pg_node_attr(read_write_ignore);
1149
+ /* predicate if a partial index, else NIL */
1150
+ List *indpred;
1151
+
1152
+ /* targetlist representing index columns */
1153
+ List *indextlist;
1154
+
1155
+ /*
1156
+ * parent relation's baserestrictinfo list, less any conditions implied by
1157
+ * the index's predicate (unless it's a target rel, see comments in
1158
+ * check_index_predicates())
1159
+ */
1160
+ List *indrestrictinfo;
1161
+
1162
+ /* true if index predicate matches query */
1163
+ bool predOK;
1164
+ /* true if a unique index */
1165
+ bool unique;
1166
+ /* is uniqueness enforced immediately? */
1167
+ bool immediate;
1168
+ /* true if index doesn't really exist */
1169
+ bool hypothetical;
1170
+
1171
+ /*
1172
+ * Remaining fields are copied from the index AM's API struct
1173
+ * (IndexAmRoutine). These fields are not set for partitioned indexes.
1174
+ */
1175
+ bool amcanorderbyop;
1176
+ bool amoptionalkey;
1177
+ bool amsearcharray;
1178
+ bool amsearchnulls;
1179
+ /* does AM have amgettuple interface? */
1180
+ bool amhasgettuple;
1181
+ /* does AM have amgetbitmap interface? */
1182
+ bool amhasgetbitmap;
1183
+ bool amcanparallel;
1184
+ /* does AM have ammarkpos interface? */
1185
+ bool amcanmarkpos;
1186
+ /* AM's cost estimator */
868
1187
  /* Rather than include amapi.h here, we declare amcostestimate like this */
869
- void (*amcostestimate) (); /* AM's cost estimator */
1188
+ void (*amcostestimate) () pg_node_attr(read_write_ignore);
870
1189
  };
871
1190
 
872
1191
  /*
@@ -879,22 +1198,43 @@ struct IndexOptInfo
879
1198
  */
880
1199
  typedef struct ForeignKeyOptInfo
881
1200
  {
1201
+ pg_node_attr(custom_read_write, no_copy_equal, no_read, no_query_jumble)
1202
+
882
1203
  NodeTag type;
883
1204
 
884
- /* Basic data about the foreign key (fetched from catalogs): */
885
- Index con_relid; /* RT index of the referencing table */
886
- Index ref_relid; /* RT index of the referenced table */
887
- int nkeys; /* number of columns in the foreign key */
888
- AttrNumber conkey[INDEX_MAX_KEYS]; /* cols in referencing table */
889
- AttrNumber confkey[INDEX_MAX_KEYS]; /* cols in referenced table */
890
- Oid conpfeqop[INDEX_MAX_KEYS]; /* PK = FK operator OIDs */
891
-
892
- /* Derived info about whether FK's equality conditions match the query: */
893
- int nmatched_ec; /* # of FK cols matched by ECs */
894
- int nmatched_rcols; /* # of FK cols matched by non-EC rinfos */
895
- int nmatched_ri; /* total # of non-EC rinfos matched to FK */
1205
+ /*
1206
+ * Basic data about the foreign key (fetched from catalogs):
1207
+ */
1208
+
1209
+ /* RT index of the referencing table */
1210
+ Index con_relid;
1211
+ /* RT index of the referenced table */
1212
+ Index ref_relid;
1213
+ /* number of columns in the foreign key */
1214
+ int nkeys;
1215
+ /* cols in referencing table */
1216
+ AttrNumber conkey[INDEX_MAX_KEYS] pg_node_attr(array_size(nkeys));
1217
+ /* cols in referenced table */
1218
+ AttrNumber confkey[INDEX_MAX_KEYS] pg_node_attr(array_size(nkeys));
1219
+ /* PK = FK operator OIDs */
1220
+ Oid conpfeqop[INDEX_MAX_KEYS] pg_node_attr(array_size(nkeys));
1221
+
1222
+ /*
1223
+ * Derived info about whether FK's equality conditions match the query:
1224
+ */
1225
+
1226
+ /* # of FK cols matched by ECs */
1227
+ int nmatched_ec;
1228
+ /* # of these ECs that are ec_has_const */
1229
+ int nconst_ec;
1230
+ /* # of FK cols matched by non-EC rinfos */
1231
+ int nmatched_rcols;
1232
+ /* total # of non-EC rinfos matched to FK */
1233
+ int nmatched_ri;
896
1234
  /* Pointer to eclass matching each column's condition, if there is one */
897
1235
  struct EquivalenceClass *eclass[INDEX_MAX_KEYS];
1236
+ /* Pointer to eclass member for the referencing Var, if there is one */
1237
+ struct EquivalenceMember *fk_eclass_member[INDEX_MAX_KEYS];
898
1238
  /* List of non-EC RestrictInfos matching each column's condition */
899
1239
  List *rinfos[INDEX_MAX_KEYS];
900
1240
  } ForeignKeyOptInfo;
@@ -908,19 +1248,69 @@ typedef struct ForeignKeyOptInfo
908
1248
  */
909
1249
  typedef struct StatisticExtInfo
910
1250
  {
1251
+ pg_node_attr(no_copy_equal, no_read, no_query_jumble)
1252
+
911
1253
  NodeTag type;
912
1254
 
913
- Oid statOid; /* OID of the statistics row */
914
- RelOptInfo *rel; /* back-link to statistic's table */
915
- char kind; /* statistic kind of this entry */
916
- Bitmapset *keys; /* attnums of the columns covered */
1255
+ /* OID of the statistics row */
1256
+ Oid statOid;
1257
+
1258
+ /* includes child relations */
1259
+ bool inherit;
1260
+
1261
+ /* back-link to statistic's table; don't print, else infinite recursion */
1262
+ RelOptInfo *rel pg_node_attr(read_write_ignore);
1263
+
1264
+ /* statistics kind of this entry */
1265
+ char kind;
1266
+
1267
+ /* attnums of the columns covered */
1268
+ Bitmapset *keys;
1269
+
1270
+ /* expressions */
1271
+ List *exprs;
917
1272
  } StatisticExtInfo;
918
1273
 
1274
+ /*
1275
+ * JoinDomains
1276
+ *
1277
+ * A "join domain" defines the scope of applicability of deductions made via
1278
+ * the EquivalenceClass mechanism. Roughly speaking, a join domain is a set
1279
+ * of base+OJ relations that are inner-joined together. More precisely, it is
1280
+ * the set of relations at which equalities deduced from an EquivalenceClass
1281
+ * can be enforced or should be expected to hold. The topmost JoinDomain
1282
+ * covers the whole query (so its jd_relids should equal all_query_rels).
1283
+ * An outer join creates a new JoinDomain that includes all base+OJ relids
1284
+ * within its nullable side, but (by convention) not the OJ's own relid.
1285
+ * A FULL join creates two new JoinDomains, one for each side.
1286
+ *
1287
+ * Notice that a rel that is below outer join(s) will thus appear to belong
1288
+ * to multiple join domains. However, any of its Vars that appear in
1289
+ * EquivalenceClasses belonging to higher join domains will have nullingrel
1290
+ * bits preventing them from being evaluated at the rel's scan level, so that
1291
+ * we will not be able to derive enforceable-at-the-rel-scan-level clauses
1292
+ * from such ECs. We define the join domain relid sets this way so that
1293
+ * domains can be said to be "higher" or "lower" when one domain relid set
1294
+ * includes another.
1295
+ *
1296
+ * The JoinDomains for a query are computed in deconstruct_jointree.
1297
+ * We do not copy JoinDomain structs once made, so they can be compared
1298
+ * for equality by simple pointer equality.
1299
+ */
1300
+ typedef struct JoinDomain
1301
+ {
1302
+ pg_node_attr(no_copy_equal, no_read, no_query_jumble)
1303
+
1304
+ NodeTag type;
1305
+
1306
+ Relids jd_relids; /* all relids contained within the domain */
1307
+ } JoinDomain;
1308
+
919
1309
  /*
920
1310
  * EquivalenceClasses
921
1311
  *
922
- * Whenever we can determine that a mergejoinable equality clause A = B is
923
- * not delayed by any outer join, we create an EquivalenceClass containing
1312
+ * Whenever we identify a mergejoinable equality clause A = B that is
1313
+ * not an outer-join clause, we create an EquivalenceClass containing
924
1314
  * the expressions A and B to record this knowledge. If we later find another
925
1315
  * equivalence B = C, we add C to the existing EquivalenceClass; this may
926
1316
  * require merging two existing EquivalenceClasses. At the end of the qual
@@ -934,6 +1324,18 @@ typedef struct StatisticExtInfo
934
1324
  * that all or none of the input datatypes are collatable, so that a single
935
1325
  * collation value is sufficient.)
936
1326
  *
1327
+ * Strictly speaking, deductions from an EquivalenceClass hold only within
1328
+ * a "join domain", that is a set of relations that are innerjoined together
1329
+ * (see JoinDomain above). For the most part we don't need to account for
1330
+ * this explicitly, because equality clauses from different join domains
1331
+ * will contain Vars that are not equal() because they have different
1332
+ * nullingrel sets, and thus we will never falsely merge ECs from different
1333
+ * join domains. But Var-free (pseudoconstant) expressions lack that safety
1334
+ * feature. We handle that by marking "const" EC members with the JoinDomain
1335
+ * of the clause they came from; two nominally-equal const members will be
1336
+ * considered different if they came from different JoinDomains. This ensures
1337
+ * no false EquivalenceClass merges will occur.
1338
+ *
937
1339
  * We also use EquivalenceClasses as the base structure for PathKeys, letting
938
1340
  * us represent knowledge about different sort orderings being equivalent.
939
1341
  * Since every PathKey must reference an EquivalenceClass, we will end up
@@ -948,16 +1350,19 @@ typedef struct StatisticExtInfo
948
1350
  * entry: consider SELECT random() AS a, random() AS b ... ORDER BY b,a.
949
1351
  * So we record the SortGroupRef of the originating sort clause.
950
1352
  *
951
- * We allow equality clauses appearing below the nullable side of an outer join
952
- * to form EquivalenceClasses, but these have a slightly different meaning:
953
- * the included values might be all NULL rather than all the same non-null
954
- * values. See src/backend/optimizer/README for more on that point.
955
- *
956
1353
  * NB: if ec_merged isn't NULL, this class has been merged into another, and
957
1354
  * should be ignored in favor of using the pointed-to class.
1355
+ *
1356
+ * NB: EquivalenceClasses are never copied after creation. Therefore,
1357
+ * copyObject() copies pointers to them as pointers, and equal() compares
1358
+ * pointers to EquivalenceClasses via pointer equality. This is implemented
1359
+ * by putting copy_as_scalar and equal_as_scalar attributes on fields that
1360
+ * are pointers to EquivalenceClasses. The same goes for EquivalenceMembers.
958
1361
  */
959
1362
  typedef struct EquivalenceClass
960
1363
  {
1364
+ pg_node_attr(custom_read_write, no_copy_equal, no_read, no_query_jumble)
1365
+
961
1366
  NodeTag type;
962
1367
 
963
1368
  List *ec_opfamilies; /* btree operator family OIDs */
@@ -969,7 +1374,6 @@ typedef struct EquivalenceClass
969
1374
  * for child members (see below) */
970
1375
  bool ec_has_const; /* any pseudoconstants in ec_members? */
971
1376
  bool ec_has_volatile; /* the (sole) member is a volatile expr */
972
- bool ec_below_outer_join; /* equivalence applies below an OJ */
973
1377
  bool ec_broken; /* failed to generate needed clauses? */
974
1378
  Index ec_sortref; /* originating sortclause label, or 0 */
975
1379
  Index ec_min_security; /* minimum security_level in ec_sources */
@@ -978,11 +1382,11 @@ typedef struct EquivalenceClass
978
1382
  } EquivalenceClass;
979
1383
 
980
1384
  /*
981
- * If an EC contains a const and isn't below-outer-join, any PathKey depending
982
- * on it must be redundant, since there's only one possible value of the key.
1385
+ * If an EC contains a constant, any PathKey depending on it must be
1386
+ * redundant, since there's only one possible value of the key.
983
1387
  */
984
1388
  #define EC_MUST_BE_REDUNDANT(eclass) \
985
- ((eclass)->ec_has_const && !(eclass)->ec_below_outer_join)
1389
+ ((eclass)->ec_has_const)
986
1390
 
987
1391
  /*
988
1392
  * EquivalenceMember - one member expression of an EquivalenceClass
@@ -1008,14 +1412,18 @@ typedef struct EquivalenceClass
1008
1412
  */
1009
1413
  typedef struct EquivalenceMember
1010
1414
  {
1415
+ pg_node_attr(no_copy_equal, no_read, no_query_jumble)
1416
+
1011
1417
  NodeTag type;
1012
1418
 
1013
1419
  Expr *em_expr; /* the expression represented */
1014
1420
  Relids em_relids; /* all relids appearing in em_expr */
1015
- Relids em_nullable_relids; /* nullable by lower outer joins */
1016
1421
  bool em_is_const; /* expression is pseudoconstant? */
1017
1422
  bool em_is_child; /* derived version for a child relation? */
1018
1423
  Oid em_datatype; /* the "nominal type" used by the opfamily */
1424
+ JoinDomain *em_jdomain; /* join domain containing the source clause */
1425
+ /* if em_is_child is true, this links to corresponding EM for top parent */
1426
+ struct EquivalenceMember *em_parent pg_node_attr(read_write_ignore);
1019
1427
  } EquivalenceMember;
1020
1428
 
1021
1429
  /*
@@ -1037,14 +1445,28 @@ typedef struct EquivalenceMember
1037
1445
  */
1038
1446
  typedef struct PathKey
1039
1447
  {
1448
+ pg_node_attr(no_read, no_query_jumble)
1449
+
1040
1450
  NodeTag type;
1041
1451
 
1042
- EquivalenceClass *pk_eclass; /* the value that is ordered */
1452
+ /* the value that is ordered */
1453
+ EquivalenceClass *pk_eclass pg_node_attr(copy_as_scalar, equal_as_scalar);
1043
1454
  Oid pk_opfamily; /* btree opfamily defining the ordering */
1044
1455
  int pk_strategy; /* sort direction (ASC or DESC) */
1045
1456
  bool pk_nulls_first; /* do NULLs come before normal values? */
1046
1457
  } PathKey;
1047
1458
 
1459
+ /*
1460
+ * VolatileFunctionStatus -- allows nodes to cache their
1461
+ * contain_volatile_functions properties. VOLATILITY_UNKNOWN means not yet
1462
+ * determined.
1463
+ */
1464
+ typedef enum VolatileFunctionStatus
1465
+ {
1466
+ VOLATILITY_UNKNOWN = 0,
1467
+ VOLATILITY_VOLATILE,
1468
+ VOLATILITY_NOVOLATILE
1469
+ } VolatileFunctionStatus;
1048
1470
 
1049
1471
  /*
1050
1472
  * PathTarget
@@ -1071,11 +1493,24 @@ typedef struct PathKey
1071
1493
  */
1072
1494
  typedef struct PathTarget
1073
1495
  {
1496
+ pg_node_attr(no_copy_equal, no_read, no_query_jumble)
1497
+
1074
1498
  NodeTag type;
1075
- List *exprs; /* list of expressions to be computed */
1076
- Index *sortgrouprefs; /* corresponding sort/group refnos, or 0 */
1077
- QualCost cost; /* cost of evaluating the expressions */
1078
- int width; /* estimated avg width of result tuples */
1499
+
1500
+ /* list of expressions to be computed */
1501
+ List *exprs;
1502
+
1503
+ /* corresponding sort/group refnos, or 0 */
1504
+ Index *sortgrouprefs pg_node_attr(array_size(exprs));
1505
+
1506
+ /* cost of evaluating the expressions */
1507
+ QualCost cost;
1508
+
1509
+ /* estimated avg width of result tuples */
1510
+ int width;
1511
+
1512
+ /* indicates if exprs contain any volatile functions */
1513
+ VolatileFunctionStatus has_volatile_expr;
1079
1514
  } PathTarget;
1080
1515
 
1081
1516
  /* Convenience macro to get a sort/group refno from a PathTarget */
@@ -1095,15 +1530,24 @@ typedef struct PathTarget
1095
1530
  * Note: ppi_clauses is only used in ParamPathInfos for base relation paths;
1096
1531
  * in join cases it's NIL because the set of relevant clauses varies depending
1097
1532
  * on how the join is formed. The relevant clauses will appear in each
1098
- * parameterized join path's joinrestrictinfo list, instead.
1533
+ * parameterized join path's joinrestrictinfo list, instead. ParamPathInfos
1534
+ * for append relations don't bother with this, either.
1535
+ *
1536
+ * ppi_serials is the set of rinfo_serial numbers for quals that are enforced
1537
+ * by this path. As with ppi_clauses, it's only maintained for baserels.
1538
+ * (We could construct it on-the-fly from ppi_clauses, but it seems better
1539
+ * to materialize a copy.)
1099
1540
  */
1100
1541
  typedef struct ParamPathInfo
1101
1542
  {
1543
+ pg_node_attr(no_copy_equal, no_read, no_query_jumble)
1544
+
1102
1545
  NodeTag type;
1103
1546
 
1104
1547
  Relids ppi_req_outer; /* rels supplying parameters used by path */
1105
- double ppi_rows; /* estimated number of result tuples */
1548
+ Cardinality ppi_rows; /* estimated number of result tuples */
1106
1549
  List *ppi_clauses; /* join clauses available from outer rels */
1550
+ Bitmapset *ppi_serials; /* set of rinfo_serial for enforced quals */
1107
1551
  } ParamPathInfo;
1108
1552
 
1109
1553
 
@@ -1135,29 +1579,58 @@ typedef struct ParamPathInfo
1135
1579
  *
1136
1580
  * "pathkeys" is a List of PathKey nodes (see above), describing the sort
1137
1581
  * ordering of the path's output rows.
1582
+ *
1583
+ * We do not support copying Path trees, mainly because the circular linkages
1584
+ * between RelOptInfo and Path nodes can't be handled easily in a simple
1585
+ * depth-first traversal. We also don't have read support at the moment.
1138
1586
  */
1139
1587
  typedef struct Path
1140
1588
  {
1589
+ pg_node_attr(no_copy_equal, no_read, no_query_jumble)
1590
+
1141
1591
  NodeTag type;
1142
1592
 
1143
- NodeTag pathtype; /* tag identifying scan/join method */
1593
+ /* tag identifying scan/join method */
1594
+ NodeTag pathtype;
1144
1595
 
1145
- RelOptInfo *parent; /* the relation this path can build */
1146
- PathTarget *pathtarget; /* list of Vars/Exprs, cost, width */
1596
+ /*
1597
+ * the relation this path can build
1598
+ *
1599
+ * We do NOT print the parent, else we'd be in infinite recursion. We can
1600
+ * print the parent's relids for identification purposes, though.
1601
+ */
1602
+ RelOptInfo *parent pg_node_attr(write_only_relids);
1147
1603
 
1148
- ParamPathInfo *param_info; /* parameterization info, or NULL if none */
1604
+ /*
1605
+ * list of Vars/Exprs, cost, width
1606
+ *
1607
+ * We print the pathtarget only if it's not the default one for the rel.
1608
+ */
1609
+ PathTarget *pathtarget pg_node_attr(write_only_nondefault_pathtarget);
1149
1610
 
1150
- bool parallel_aware; /* engage parallel-aware logic? */
1151
- bool parallel_safe; /* OK to use as part of parallel plan? */
1152
- int parallel_workers; /* desired # of workers; 0 = not parallel */
1611
+ /*
1612
+ * parameterization info, or NULL if none
1613
+ *
1614
+ * We do not print the whole of param_info, since it's printed via
1615
+ * RelOptInfo; it's sufficient and less cluttering to print just the
1616
+ * required outer relids.
1617
+ */
1618
+ ParamPathInfo *param_info pg_node_attr(write_only_req_outer);
1619
+
1620
+ /* engage parallel-aware logic? */
1621
+ bool parallel_aware;
1622
+ /* OK to use as part of parallel plan? */
1623
+ bool parallel_safe;
1624
+ /* desired # of workers; 0 = not parallel */
1625
+ int parallel_workers;
1153
1626
 
1154
1627
  /* estimated size/costs for path (see costsize.c for more info) */
1155
- double rows; /* estimated number of result tuples */
1628
+ Cardinality rows; /* estimated number of result tuples */
1156
1629
  Cost startup_cost; /* cost expended before fetching any tuples */
1157
1630
  Cost total_cost; /* total cost (assuming all tuples fetched) */
1158
1631
 
1159
- List *pathkeys; /* sort ordering of path's output */
1160
- /* pathkeys is a List of PathKey nodes; see above */
1632
+ /* sort ordering of path's output; a List of PathKey nodes; see above */
1633
+ List *pathkeys;
1161
1634
  } Path;
1162
1635
 
1163
1636
  /* Macro for extracting a path's parameterization relids; beware double eval */
@@ -1189,12 +1662,9 @@ typedef struct Path
1189
1662
  * on which index column each ORDER BY can be used with.)
1190
1663
  *
1191
1664
  * 'indexscandir' is one of:
1192
- * ForwardScanDirection: forward scan of an ordered index
1665
+ * ForwardScanDirection: forward scan of an index
1193
1666
  * BackwardScanDirection: backward scan of an ordered index
1194
- * NoMovementScanDirection: scan of an unordered index, or don't care
1195
- * (The executor doesn't care whether it gets ForwardScanDirection or
1196
- * NoMovementScanDirection for an indexscan, but the planner wants to
1197
- * distinguish ordered from unordered indexes for building pathkeys.)
1667
+ * Unordered indexes will always have an indexscandir of ForwardScanDirection.
1198
1668
  *
1199
1669
  * 'indextotalcost' and 'indexselectivity' are saved in the IndexPath so that
1200
1670
  * we need not recompute them when considering using the same index in a
@@ -1250,6 +1720,8 @@ typedef struct IndexPath
1250
1720
  */
1251
1721
  typedef struct IndexClause
1252
1722
  {
1723
+ pg_node_attr(no_copy_equal, no_read, no_query_jumble)
1724
+
1253
1725
  NodeTag type;
1254
1726
  struct RestrictInfo *rinfo; /* original restriction or join clause */
1255
1727
  List *indexquals; /* indexqual(s) derived from it */
@@ -1320,6 +1792,18 @@ typedef struct TidPath
1320
1792
  List *tidquals; /* qual(s) involving CTID = something */
1321
1793
  } TidPath;
1322
1794
 
1795
+ /*
1796
+ * TidRangePath represents a scan by a contiguous range of TIDs
1797
+ *
1798
+ * tidrangequals is an implicitly AND'ed list of qual expressions of the form
1799
+ * "CTID relop pseudoconstant", where relop is one of >,>=,<,<=.
1800
+ */
1801
+ typedef struct TidRangePath
1802
+ {
1803
+ Path path;
1804
+ List *tidrangequals;
1805
+ } TidRangePath;
1806
+
1323
1807
  /*
1324
1808
  * SubqueryScanPath represents a scan of an unflattened subquery-in-FROM
1325
1809
  *
@@ -1352,15 +1836,18 @@ typedef struct ForeignPath
1352
1836
  } ForeignPath;
1353
1837
 
1354
1838
  /*
1355
- * CustomPath represents a table scan done by some out-of-core extension.
1839
+ * CustomPath represents a table scan or a table join done by some out-of-core
1840
+ * extension.
1356
1841
  *
1357
1842
  * We provide a set of hooks here - which the provider must take care to set
1358
1843
  * up correctly - to allow extensions to supply their own methods of scanning
1359
- * a relation. For example, a provider might provide GPU acceleration, a
1360
- * cache-based scan, or some other kind of logic we haven't dreamed up yet.
1844
+ * a relation or joing relations. For example, a provider might provide GPU
1845
+ * acceleration, a cache-based scan, or some other kind of logic we haven't
1846
+ * dreamed up yet.
1361
1847
  *
1362
- * CustomPaths can be injected into the planning process for a relation by
1363
- * set_rel_pathlist_hook functions.
1848
+ * CustomPaths can be injected into the planning process for a base or join
1849
+ * relation by set_rel_pathlist_hook or set_join_pathlist_hook functions,
1850
+ * respectively.
1364
1851
  *
1365
1852
  * Core code must avoid assuming that the CustomPath is only as large as
1366
1853
  * the structure declared here; providers are allowed to make it the first
@@ -1400,12 +1887,10 @@ typedef struct CustomPath
1400
1887
  typedef struct AppendPath
1401
1888
  {
1402
1889
  Path path;
1403
- /* RT indexes of non-leaf tables in a partition tree */
1404
- List *partitioned_rels;
1405
1890
  List *subpaths; /* list of component Paths */
1406
1891
  /* Index of first partial path in subpaths; list_length(subpaths) if none */
1407
1892
  int first_partial_path;
1408
- double limit_tuples; /* hard limit on output tuples, or -1 */
1893
+ Cardinality limit_tuples; /* hard limit on output tuples, or -1 */
1409
1894
  } AppendPath;
1410
1895
 
1411
1896
  #define IS_DUMMY_APPEND(p) \
@@ -1426,10 +1911,8 @@ extern bool is_dummy_rel(RelOptInfo *rel);
1426
1911
  typedef struct MergeAppendPath
1427
1912
  {
1428
1913
  Path path;
1429
- /* RT indexes of non-leaf tables in a partition tree */
1430
- List *partitioned_rels;
1431
1914
  List *subpaths; /* list of component Paths */
1432
- double limit_tuples; /* hard limit on output tuples, or -1 */
1915
+ Cardinality limit_tuples; /* hard limit on output tuples, or -1 */
1433
1916
  } MergeAppendPath;
1434
1917
 
1435
1918
  /*
@@ -1457,6 +1940,27 @@ typedef struct MaterialPath
1457
1940
  Path *subpath;
1458
1941
  } MaterialPath;
1459
1942
 
1943
+ /*
1944
+ * MemoizePath represents a Memoize plan node, i.e., a cache that caches
1945
+ * tuples from parameterized paths to save the underlying node from having to
1946
+ * be rescanned for parameter values which are already cached.
1947
+ */
1948
+ typedef struct MemoizePath
1949
+ {
1950
+ Path path;
1951
+ Path *subpath; /* outerpath to cache tuples from */
1952
+ List *hash_operators; /* OIDs of hash equality ops for cache keys */
1953
+ List *param_exprs; /* expressions that are cache keys */
1954
+ bool singlerow; /* true if the cache entry is to be marked as
1955
+ * complete after caching the first record. */
1956
+ bool binary_mode; /* true when cache key should be compared bit
1957
+ * by bit, false when using hash equality ops */
1958
+ Cardinality calls; /* expected number of rescans */
1959
+ uint32 est_entries; /* The maximum number of entries that the
1960
+ * planner expects will fit in the cache, or 0
1961
+ * if unknown */
1962
+ } MemoizePath;
1963
+
1460
1964
  /*
1461
1965
  * UniquePath represents elimination of distinct rows from the output of
1462
1966
  * its subpath.
@@ -1469,7 +1973,7 @@ typedef struct MaterialPath
1469
1973
  * it's convenient to have a UniquePath in the path tree to signal upper-level
1470
1974
  * routines that the input is known distinct.)
1471
1975
  */
1472
- typedef enum
1976
+ typedef enum UniquePathMethod
1473
1977
  {
1474
1978
  UNIQUE_PATH_NOOP, /* input is known unique already */
1475
1979
  UNIQUE_PATH_HASH, /* use hashing */
@@ -1516,6 +2020,8 @@ typedef struct GatherMergePath
1516
2020
 
1517
2021
  typedef struct JoinPath
1518
2022
  {
2023
+ pg_node_attr(abstract)
2024
+
1519
2025
  Path path;
1520
2026
 
1521
2027
  JoinType jointype;
@@ -1539,7 +2045,10 @@ typedef struct JoinPath
1539
2045
  * A nested-loop path needs no special fields.
1540
2046
  */
1541
2047
 
1542
- typedef JoinPath NestPath;
2048
+ typedef struct NestPath
2049
+ {
2050
+ JoinPath jpath;
2051
+ } NestPath;
1543
2052
 
1544
2053
  /*
1545
2054
  * A mergejoin path has these fields.
@@ -1600,7 +2109,7 @@ typedef struct HashPath
1600
2109
  JoinPath jpath;
1601
2110
  List *path_hashclauses; /* join clauses used for hashing */
1602
2111
  int num_batches; /* number of batches expected */
1603
- double inner_rows_total; /* total inner rows expected */
2112
+ Cardinality inner_rows_total; /* total inner rows expected */
1604
2113
  } HashPath;
1605
2114
 
1606
2115
  /*
@@ -1703,7 +2212,7 @@ typedef struct AggPath
1703
2212
  Path *subpath; /* path representing input source */
1704
2213
  AggStrategy aggstrategy; /* basic strategy, see nodes.h */
1705
2214
  AggSplit aggsplit; /* agg-splitting mode, see nodes.h */
1706
- double numGroups; /* estimated number of groups in input */
2215
+ Cardinality numGroups; /* estimated number of groups in input */
1707
2216
  uint64 transitionSpace; /* for pass-by-ref transition data */
1708
2217
  List *groupClause; /* a list of SortGroupClause's */
1709
2218
  List *qual; /* quals (HAVING quals), if any */
@@ -1715,18 +2224,22 @@ typedef struct AggPath
1715
2224
 
1716
2225
  typedef struct GroupingSetData
1717
2226
  {
2227
+ pg_node_attr(no_copy_equal, no_read, no_query_jumble)
2228
+
1718
2229
  NodeTag type;
1719
2230
  List *set; /* grouping set as list of sortgrouprefs */
1720
- double numGroups; /* est. number of result groups */
2231
+ Cardinality numGroups; /* est. number of result groups */
1721
2232
  } GroupingSetData;
1722
2233
 
1723
2234
  typedef struct RollupData
1724
2235
  {
2236
+ pg_node_attr(no_copy_equal, no_read, no_query_jumble)
2237
+
1725
2238
  NodeTag type;
1726
2239
  List *groupClause; /* applicable subset of parse->groupClause */
1727
2240
  List *gsets; /* lists of integer indexes into groupClause */
1728
2241
  List *gsets_data; /* list of GroupingSetData */
1729
- double numGroups; /* est. number of result groups */
2242
+ Cardinality numGroups; /* est. number of result groups */
1730
2243
  bool hashable; /* can be hashed */
1731
2244
  bool is_hashed; /* to be implemented as a hashagg */
1732
2245
  } RollupData;
@@ -1763,6 +2276,9 @@ typedef struct WindowAggPath
1763
2276
  Path path;
1764
2277
  Path *subpath; /* path representing input source */
1765
2278
  WindowClause *winclause; /* WindowClause we'll be using */
2279
+ List *qual; /* lower-level WindowAgg runconditions */
2280
+ bool topwindow; /* false for all apart from the WindowAgg
2281
+ * that's closest to the root of the plan */
1766
2282
  } WindowAggPath;
1767
2283
 
1768
2284
  /*
@@ -1777,7 +2293,7 @@ typedef struct SetOpPath
1777
2293
  List *distinctList; /* SortGroupClauses identifying target cols */
1778
2294
  AttrNumber flagColIdx; /* where is the flag column, if any */
1779
2295
  int firstFlag; /* flag value for first input relation */
1780
- double numGroups; /* estimated number of groups in input */
2296
+ Cardinality numGroups; /* estimated number of groups in input */
1781
2297
  } SetOpPath;
1782
2298
 
1783
2299
  /*
@@ -1790,7 +2306,7 @@ typedef struct RecursiveUnionPath
1790
2306
  Path *rightpath;
1791
2307
  List *distinctList; /* SortGroupClauses identifying target cols */
1792
2308
  int wtParam; /* ID of Param representing work table */
1793
- double numGroups; /* estimated number of groups in input */
2309
+ Cardinality numGroups; /* estimated number of groups in input */
1794
2310
  } RecursiveUnionPath;
1795
2311
 
1796
2312
  /*
@@ -1805,28 +2321,30 @@ typedef struct LockRowsPath
1805
2321
  } LockRowsPath;
1806
2322
 
1807
2323
  /*
1808
- * ModifyTablePath represents performing INSERT/UPDATE/DELETE modifications
2324
+ * ModifyTablePath represents performing INSERT/UPDATE/DELETE/MERGE
1809
2325
  *
1810
2326
  * We represent most things that will be in the ModifyTable plan node
1811
- * literally, except we have child Path(s) not Plan(s). But analysis of the
2327
+ * literally, except we have a child Path not Plan. But analysis of the
1812
2328
  * OnConflictExpr is deferred to createplan.c, as is collection of FDW data.
1813
2329
  */
1814
2330
  typedef struct ModifyTablePath
1815
2331
  {
1816
2332
  Path path;
1817
- CmdType operation; /* INSERT, UPDATE, or DELETE */
2333
+ Path *subpath; /* Path producing source data */
2334
+ CmdType operation; /* INSERT, UPDATE, DELETE, or MERGE */
1818
2335
  bool canSetTag; /* do we set the command tag/es_processed? */
1819
2336
  Index nominalRelation; /* Parent RT index for use of EXPLAIN */
1820
- Index rootRelation; /* Root RT index, if target is partitioned */
1821
- bool partColsUpdated; /* some part key in hierarchy updated */
2337
+ Index rootRelation; /* Root RT index, if partitioned/inherited */
2338
+ bool partColsUpdated; /* some part key in hierarchy updated? */
1822
2339
  List *resultRelations; /* integer list of RT indexes */
1823
- List *subpaths; /* Path(s) producing source data */
1824
- List *subroots; /* per-target-table PlannerInfos */
2340
+ List *updateColnosLists; /* per-target-table update_colnos lists */
1825
2341
  List *withCheckOptionLists; /* per-target-table WCO lists */
1826
2342
  List *returningLists; /* per-target-table RETURNING tlists */
1827
2343
  List *rowMarks; /* PlanRowMarks (non-locking only) */
1828
2344
  OnConflictExpr *onconflict; /* ON CONFLICT clause, or NULL */
1829
2345
  int epqParam; /* ID of Param for EvalPlanQual re-eval */
2346
+ List *mergeActionLists; /* per-target-table lists of actions for
2347
+ * MERGE */
1830
2348
  } ModifyTablePath;
1831
2349
 
1832
2350
  /*
@@ -1854,17 +2372,17 @@ typedef struct LimitPath
1854
2372
  * If a restriction clause references a single base relation, it will appear
1855
2373
  * in the baserestrictinfo list of the RelOptInfo for that base rel.
1856
2374
  *
1857
- * If a restriction clause references more than one base rel, it will
2375
+ * If a restriction clause references more than one base+OJ relation, it will
1858
2376
  * appear in the joininfo list of every RelOptInfo that describes a strict
1859
- * subset of the base rels mentioned in the clause. The joininfo lists are
2377
+ * subset of the relations mentioned in the clause. The joininfo lists are
1860
2378
  * used to drive join tree building by selecting plausible join candidates.
1861
2379
  * The clause cannot actually be applied until we have built a join rel
1862
- * containing all the base rels it references, however.
2380
+ * containing all the relations it references, however.
1863
2381
  *
1864
- * When we construct a join rel that includes all the base rels referenced
2382
+ * When we construct a join rel that includes all the relations referenced
1865
2383
  * in a multi-relation restriction clause, we place that clause into the
1866
2384
  * joinrestrictinfo lists of paths for the join rel, if neither left nor
1867
- * right sub-path includes all base rels referenced in the clause. The clause
2385
+ * right sub-path includes all relations referenced in the clause. The clause
1868
2386
  * will be applied at that join level, and will not propagate any further up
1869
2387
  * the join tree. (Note: the "predicate migration" code was once intended to
1870
2388
  * push restriction clauses up and down the plan tree based on evaluation
@@ -1885,12 +2403,14 @@ typedef struct LimitPath
1885
2403
  * or join to enforce that all members of each EquivalenceClass are in fact
1886
2404
  * equal in all rows emitted by the scan or join.
1887
2405
  *
1888
- * When dealing with outer joins we have to be very careful about pushing qual
1889
- * clauses up and down the tree. An outer join's own JOIN/ON conditions must
1890
- * be evaluated exactly at that join node, unless they are "degenerate"
1891
- * conditions that reference only Vars from the nullable side of the join.
1892
- * Quals appearing in WHERE or in a JOIN above the outer join cannot be pushed
1893
- * down below the outer join, if they reference any nullable Vars.
2406
+ * The clause_relids field lists the base plus outer-join RT indexes that
2407
+ * actually appear in the clause. required_relids lists the minimum set of
2408
+ * relids needed to evaluate the clause; while this is often equal to
2409
+ * clause_relids, it can be more. We will add relids to required_relids when
2410
+ * we need to force an outer join ON clause to be evaluated exactly at the
2411
+ * level of the outer join, which is true except when it is a "degenerate"
2412
+ * condition that references only Vars from the nullable side of the join.
2413
+ *
1894
2414
  * RestrictInfo nodes contain a flag to indicate whether a qual has been
1895
2415
  * pushed down to a lower level than its original syntactic placement in the
1896
2416
  * join tree would suggest. If an outer join prevents us from pushing a qual
@@ -1913,10 +2433,14 @@ typedef struct LimitPath
1913
2433
  * conditions. Possibly we should rename it to reflect that meaning? But
1914
2434
  * see also the comments for RINFO_IS_PUSHED_DOWN, below.)
1915
2435
  *
1916
- * RestrictInfo nodes also contain an outerjoin_delayed flag, which is true
1917
- * if the clause's applicability must be delayed due to any outer joins
1918
- * appearing below it (ie, it has to be postponed to some join level higher
1919
- * than the set of relations it actually references).
2436
+ * There is also an incompatible_relids field, which is a set of outer-join
2437
+ * relids above which we cannot evaluate the clause (because they might null
2438
+ * Vars it uses that should not be nulled yet). In principle this could be
2439
+ * filled in any RestrictInfo as the set of OJ relids that appear above the
2440
+ * clause and null Vars that it uses. In practice we only bother to populate
2441
+ * it for "clone" clauses, as it's currently only needed to prevent multiple
2442
+ * clones of the same clause from being accepted for evaluation at the same
2443
+ * join level.
1920
2444
  *
1921
2445
  * There is also an outer_relids field, which is NULL except for outer join
1922
2446
  * clauses; for those, it is the set of relids on the outer side of the
@@ -1924,15 +2448,6 @@ typedef struct LimitPath
1924
2448
  * in parameterized scans, since pushing it into the join's outer side would
1925
2449
  * lead to wrong answers.)
1926
2450
  *
1927
- * There is also a nullable_relids field, which is the set of rels the clause
1928
- * references that can be forced null by some outer join below the clause.
1929
- *
1930
- * outerjoin_delayed = true is subtly different from nullable_relids != NULL:
1931
- * a clause might reference some nullable rels and yet not be
1932
- * outerjoin_delayed because it also references all the other rels of the
1933
- * outer join(s). A clause that is not outerjoin_delayed can be enforced
1934
- * anywhere it is computable.
1935
- *
1936
2451
  * To handle security-barrier conditions efficiently, we mark RestrictInfo
1937
2452
  * nodes with a security_level field, in which higher values identify clauses
1938
2453
  * coming from less-trusted sources. The exact semantics are that a clause
@@ -1975,82 +2490,174 @@ typedef struct LimitPath
1975
2490
  * or merge or hash join clause, so it's of no interest to large parts of
1976
2491
  * the planner.
1977
2492
  *
2493
+ * When we generate multiple versions of a clause so as to have versions
2494
+ * that will work after commuting some left joins per outer join identity 3,
2495
+ * we mark the one with the fewest nullingrels bits with has_clone = true,
2496
+ * and the rest with is_clone = true. This allows proper filtering of
2497
+ * these redundant clauses, so that we apply only one version of them.
2498
+ *
1978
2499
  * When join clauses are generated from EquivalenceClasses, there may be
1979
2500
  * several equally valid ways to enforce join equivalence, of which we need
1980
2501
  * apply only one. We mark clauses of this kind by setting parent_ec to
1981
2502
  * point to the generating EquivalenceClass. Multiple clauses with the same
1982
2503
  * parent_ec in the same join are redundant.
2504
+ *
2505
+ * Most fields are ignored for equality, since they may not be set yet, and
2506
+ * should be derivable from the clause anyway.
2507
+ *
2508
+ * parent_ec, left_ec, right_ec are not printed, lest it lead to infinite
2509
+ * recursion in plan tree dump.
1983
2510
  */
1984
2511
 
1985
2512
  typedef struct RestrictInfo
1986
2513
  {
2514
+ pg_node_attr(no_read, no_query_jumble)
2515
+
1987
2516
  NodeTag type;
1988
2517
 
1989
- Expr *clause; /* the represented clause of WHERE or JOIN */
2518
+ /* the represented clause of WHERE or JOIN */
2519
+ Expr *clause;
1990
2520
 
1991
- bool is_pushed_down; /* true if clause was pushed down in level */
2521
+ /* true if clause was pushed down in level */
2522
+ bool is_pushed_down;
1992
2523
 
1993
- bool outerjoin_delayed; /* true if delayed by lower outer join */
2524
+ /* see comment above */
2525
+ bool can_join pg_node_attr(equal_ignore);
1994
2526
 
1995
- bool can_join; /* see comment above */
2527
+ /* see comment above */
2528
+ bool pseudoconstant pg_node_attr(equal_ignore);
1996
2529
 
1997
- bool pseudoconstant; /* see comment above */
2530
+ /* see comment above */
2531
+ bool has_clone;
2532
+ bool is_clone;
1998
2533
 
1999
- bool leakproof; /* true if known to contain no leaked Vars */
2534
+ /* true if known to contain no leaked Vars */
2535
+ bool leakproof pg_node_attr(equal_ignore);
2000
2536
 
2001
- Index security_level; /* see comment above */
2537
+ /* indicates if clause contains any volatile functions */
2538
+ VolatileFunctionStatus has_volatile pg_node_attr(equal_ignore);
2002
2539
 
2003
- /* The set of relids (varnos) actually referenced in the clause: */
2004
- Relids clause_relids;
2540
+ /* see comment above */
2541
+ Index security_level;
2542
+
2543
+ /* number of base rels in clause_relids */
2544
+ int num_base_rels pg_node_attr(equal_ignore);
2545
+
2546
+ /* The relids (varnos+varnullingrels) actually referenced in the clause: */
2547
+ Relids clause_relids pg_node_attr(equal_ignore);
2005
2548
 
2006
2549
  /* The set of relids required to evaluate the clause: */
2007
2550
  Relids required_relids;
2008
2551
 
2552
+ /* Relids above which we cannot evaluate the clause (see comment above) */
2553
+ Relids incompatible_relids;
2554
+
2009
2555
  /* If an outer-join clause, the outer-side relations, else NULL: */
2010
2556
  Relids outer_relids;
2011
2557
 
2012
- /* The relids used in the clause that are nullable by lower outer joins: */
2013
- Relids nullable_relids;
2558
+ /*
2559
+ * Relids in the left/right side of the clause. These fields are set for
2560
+ * any binary opclause.
2561
+ */
2562
+ Relids left_relids pg_node_attr(equal_ignore);
2563
+ Relids right_relids pg_node_attr(equal_ignore);
2014
2564
 
2015
- /* These fields are set for any binary opclause: */
2016
- Relids left_relids; /* relids in left side of clause */
2017
- Relids right_relids; /* relids in right side of clause */
2565
+ /*
2566
+ * Modified clause with RestrictInfos. This field is NULL unless clause
2567
+ * is an OR clause.
2568
+ */
2569
+ Expr *orclause pg_node_attr(equal_ignore);
2570
+
2571
+ /*----------
2572
+ * Serial number of this RestrictInfo. This is unique within the current
2573
+ * PlannerInfo context, with a few critical exceptions:
2574
+ * 1. When we generate multiple clones of the same qual condition to
2575
+ * cope with outer join identity 3, all the clones get the same serial
2576
+ * number. This reflects that we only want to apply one of them in any
2577
+ * given plan.
2578
+ * 2. If we manufacture a commuted version of a qual to use as an index
2579
+ * condition, it copies the original's rinfo_serial, since it is in
2580
+ * practice the same condition.
2581
+ * 3. RestrictInfos made for a child relation copy their parent's
2582
+ * rinfo_serial. Likewise, when an EquivalenceClass makes a derived
2583
+ * equality clause for a child relation, it copies the rinfo_serial of
2584
+ * the matching equality clause for the parent. This allows detection
2585
+ * of redundant pushed-down equality clauses.
2586
+ *----------
2587
+ */
2588
+ int rinfo_serial;
2018
2589
 
2019
- /* This field is NULL unless clause is an OR clause: */
2020
- Expr *orclause; /* modified clause with RestrictInfos */
2590
+ /*
2591
+ * Generating EquivalenceClass. This field is NULL unless clause is
2592
+ * potentially redundant.
2593
+ */
2594
+ EquivalenceClass *parent_ec pg_node_attr(copy_as_scalar, equal_ignore, read_write_ignore);
2021
2595
 
2022
- /* This field is NULL unless clause is potentially redundant: */
2023
- EquivalenceClass *parent_ec; /* generating EquivalenceClass */
2596
+ /*
2597
+ * cache space for cost and selectivity
2598
+ */
2599
+
2600
+ /* eval cost of clause; -1 if not yet set */
2601
+ QualCost eval_cost pg_node_attr(equal_ignore);
2024
2602
 
2025
- /* cache space for cost and selectivity */
2026
- QualCost eval_cost; /* eval cost of clause; -1 if not yet set */
2027
- Selectivity norm_selec; /* selectivity for "normal" (JOIN_INNER)
2028
- * semantics; -1 if not yet set; >1 means a
2029
- * redundant clause */
2030
- Selectivity outer_selec; /* selectivity for outer join semantics; -1 if
2031
- * not yet set */
2603
+ /* selectivity for "normal" (JOIN_INNER) semantics; -1 if not yet set */
2604
+ Selectivity norm_selec pg_node_attr(equal_ignore);
2605
+ /* selectivity for outer join semantics; -1 if not yet set */
2606
+ Selectivity outer_selec pg_node_attr(equal_ignore);
2032
2607
 
2033
- /* valid if clause is mergejoinable, else NIL */
2034
- List *mergeopfamilies; /* opfamilies containing clause operator */
2608
+ /*
2609
+ * opfamilies containing clause operator; valid if clause is
2610
+ * mergejoinable, else NIL
2611
+ */
2612
+ List *mergeopfamilies pg_node_attr(equal_ignore);
2035
2613
 
2036
- /* cache space for mergeclause processing; NULL if not yet set */
2037
- EquivalenceClass *left_ec; /* EquivalenceClass containing lefthand */
2038
- EquivalenceClass *right_ec; /* EquivalenceClass containing righthand */
2039
- EquivalenceMember *left_em; /* EquivalenceMember for lefthand */
2040
- EquivalenceMember *right_em; /* EquivalenceMember for righthand */
2041
- List *scansel_cache; /* list of MergeScanSelCache structs */
2614
+ /*
2615
+ * cache space for mergeclause processing; NULL if not yet set
2616
+ */
2042
2617
 
2043
- /* transient workspace for use while considering a specific join path */
2044
- bool outer_is_left; /* T = outer var on left, F = on right */
2618
+ /* EquivalenceClass containing lefthand */
2619
+ EquivalenceClass *left_ec pg_node_attr(copy_as_scalar, equal_ignore, read_write_ignore);
2620
+ /* EquivalenceClass containing righthand */
2621
+ EquivalenceClass *right_ec pg_node_attr(copy_as_scalar, equal_ignore, read_write_ignore);
2622
+ /* EquivalenceMember for lefthand */
2623
+ EquivalenceMember *left_em pg_node_attr(copy_as_scalar, equal_ignore);
2624
+ /* EquivalenceMember for righthand */
2625
+ EquivalenceMember *right_em pg_node_attr(copy_as_scalar, equal_ignore);
2045
2626
 
2046
- /* valid if clause is hashjoinable, else InvalidOid: */
2047
- Oid hashjoinoperator; /* copy of clause operator */
2627
+ /*
2628
+ * List of MergeScanSelCache structs. Those aren't Nodes, so hard to
2629
+ * copy; instead replace with NIL. That has the effect that copying will
2630
+ * just reset the cache. Likewise, can't compare or print them.
2631
+ */
2632
+ List *scansel_cache pg_node_attr(copy_as(NIL), equal_ignore, read_write_ignore);
2048
2633
 
2049
- /* cache space for hashclause processing; -1 if not yet set */
2050
- Selectivity left_bucketsize; /* avg bucketsize of left side */
2051
- Selectivity right_bucketsize; /* avg bucketsize of right side */
2052
- Selectivity left_mcvfreq; /* left side's most common val's freq */
2053
- Selectivity right_mcvfreq; /* right side's most common val's freq */
2634
+ /*
2635
+ * transient workspace for use while considering a specific join path; T =
2636
+ * outer var on left, F = on right
2637
+ */
2638
+ bool outer_is_left pg_node_attr(equal_ignore);
2639
+
2640
+ /*
2641
+ * copy of clause operator; valid if clause is hashjoinable, else
2642
+ * InvalidOid
2643
+ */
2644
+ Oid hashjoinoperator pg_node_attr(equal_ignore);
2645
+
2646
+ /*
2647
+ * cache space for hashclause processing; -1 if not yet set
2648
+ */
2649
+ /* avg bucketsize of left side */
2650
+ Selectivity left_bucketsize pg_node_attr(equal_ignore);
2651
+ /* avg bucketsize of right side */
2652
+ Selectivity right_bucketsize pg_node_attr(equal_ignore);
2653
+ /* left side's most common val's freq */
2654
+ Selectivity left_mcvfreq pg_node_attr(equal_ignore);
2655
+ /* right side's most common val's freq */
2656
+ Selectivity right_mcvfreq pg_node_attr(equal_ignore);
2657
+
2658
+ /* hash equality operators used for memoize nodes, else InvalidOid */
2659
+ Oid left_hasheqoperator pg_node_attr(equal_ignore);
2660
+ Oid right_hasheqoperator pg_node_attr(equal_ignore);
2054
2661
  } RestrictInfo;
2055
2662
 
2056
2663
  /*
@@ -2093,22 +2700,53 @@ typedef struct MergeScanSelCache
2093
2700
  * of a plan tree. This is used during planning to represent the contained
2094
2701
  * expression. At the end of the planning process it is replaced by either
2095
2702
  * the contained expression or a Var referring to a lower-level evaluation of
2096
- * the contained expression. Typically the evaluation occurs below an outer
2703
+ * the contained expression. Generally the evaluation occurs below an outer
2097
2704
  * join, and Var references above the outer join might thereby yield NULL
2098
2705
  * instead of the expression value.
2099
2706
  *
2707
+ * phrels and phlevelsup correspond to the varno/varlevelsup fields of a
2708
+ * plain Var, except that phrels has to be a relid set since the evaluation
2709
+ * level of a PlaceHolderVar might be a join rather than a base relation.
2710
+ * Likewise, phnullingrels corresponds to varnullingrels.
2711
+ *
2100
2712
  * Although the planner treats this as an expression node type, it is not
2101
2713
  * recognized by the parser or executor, so we declare it here rather than
2102
2714
  * in primnodes.h.
2715
+ *
2716
+ * We intentionally do not compare phexpr. Two PlaceHolderVars with the
2717
+ * same ID and levelsup should be considered equal even if the contained
2718
+ * expressions have managed to mutate to different states. This will
2719
+ * happen during final plan construction when there are nested PHVs, since
2720
+ * the inner PHV will get replaced by a Param in some copies of the outer
2721
+ * PHV. Another way in which it can happen is that initplan sublinks
2722
+ * could get replaced by differently-numbered Params when sublink folding
2723
+ * is done. (The end result of such a situation would be some
2724
+ * unreferenced initplans, which is annoying but not really a problem.)
2725
+ * On the same reasoning, there is no need to examine phrels. But we do
2726
+ * need to compare phnullingrels, as that represents effects that are
2727
+ * external to the original value of the PHV.
2103
2728
  */
2104
2729
 
2105
2730
  typedef struct PlaceHolderVar
2106
2731
  {
2732
+ pg_node_attr(no_query_jumble)
2733
+
2107
2734
  Expr xpr;
2108
- Expr *phexpr; /* the represented expression */
2109
- Relids phrels; /* base relids syntactically within expr src */
2110
- Index phid; /* ID for PHV (unique within planner run) */
2111
- Index phlevelsup; /* > 0 if PHV belongs to outer query */
2735
+
2736
+ /* the represented expression */
2737
+ Expr *phexpr pg_node_attr(equal_ignore);
2738
+
2739
+ /* base+OJ relids syntactically within expr src */
2740
+ Relids phrels pg_node_attr(equal_ignore);
2741
+
2742
+ /* RT indexes of outer joins that can null PHV's value */
2743
+ Relids phnullingrels;
2744
+
2745
+ /* ID for PHV (unique within planner run) */
2746
+ Index phid;
2747
+
2748
+ /* > 0 if PHV belongs to outer query */
2749
+ Index phlevelsup;
2112
2750
  } PlaceHolderVar;
2113
2751
 
2114
2752
  /*
@@ -2127,25 +2765,53 @@ typedef struct PlaceHolderVar
2127
2765
  * We make SpecialJoinInfos for FULL JOINs even though there is no flexibility
2128
2766
  * of planning for them, because this simplifies make_join_rel()'s API.
2129
2767
  *
2130
- * min_lefthand and min_righthand are the sets of base relids that must be
2131
- * available on each side when performing the special join. lhs_strict is
2132
- * true if the special join's condition cannot succeed when the LHS variables
2133
- * are all NULL (this means that an outer join can commute with upper-level
2134
- * outer joins even if it appears in their RHS). We don't bother to set
2135
- * lhs_strict for FULL JOINs, however.
2136
- *
2768
+ * min_lefthand and min_righthand are the sets of base+OJ relids that must be
2769
+ * available on each side when performing the special join.
2137
2770
  * It is not valid for either min_lefthand or min_righthand to be empty sets;
2138
2771
  * if they were, this would break the logic that enforces join order.
2139
2772
  *
2140
- * syn_lefthand and syn_righthand are the sets of base relids that are
2773
+ * syn_lefthand and syn_righthand are the sets of base+OJ relids that are
2141
2774
  * syntactically below this special join. (These are needed to help compute
2142
2775
  * min_lefthand and min_righthand for higher joins.)
2143
2776
  *
2144
- * delay_upper_joins is set true if we detect a pushed-down clause that has
2145
- * to be evaluated after this join is formed (because it references the RHS).
2146
- * Any outer joins that have such a clause and this join in their RHS cannot
2147
- * commute with this join, because that would leave noplace to check the
2148
- * pushed-down clause. (We don't track this for FULL JOINs, either.)
2777
+ * jointype is never JOIN_RIGHT; a RIGHT JOIN is handled by switching
2778
+ * the inputs to make it a LEFT JOIN. It's never JOIN_RIGHT_ANTI either.
2779
+ * So the allowed values of jointype in a join_info_list member are only
2780
+ * LEFT, FULL, SEMI, or ANTI.
2781
+ *
2782
+ * ojrelid is the RT index of the join RTE representing this outer join,
2783
+ * if there is one. It is zero when jointype is INNER or SEMI, and can be
2784
+ * zero for jointype ANTI (if the join was transformed from a SEMI join).
2785
+ * One use for this field is that when constructing the output targetlist of a
2786
+ * join relation that implements this OJ, we add ojrelid to the varnullingrels
2787
+ * and phnullingrels fields of nullable (RHS) output columns, so that the
2788
+ * output Vars and PlaceHolderVars correctly reflect the nulling that has
2789
+ * potentially happened to them.
2790
+ *
2791
+ * commute_above_l is filled with the relids of syntactically-higher outer
2792
+ * joins that have been found to commute with this one per outer join identity
2793
+ * 3 (see optimizer/README), when this join is in the LHS of the upper join
2794
+ * (so, this is the lower join in the first form of the identity).
2795
+ *
2796
+ * commute_above_r is filled with the relids of syntactically-higher outer
2797
+ * joins that have been found to commute with this one per outer join identity
2798
+ * 3, when this join is in the RHS of the upper join (so, this is the lower
2799
+ * join in the second form of the identity).
2800
+ *
2801
+ * commute_below_l is filled with the relids of syntactically-lower outer
2802
+ * joins that have been found to commute with this one per outer join identity
2803
+ * 3 and are in the LHS of this join (so, this is the upper join in the first
2804
+ * form of the identity).
2805
+ *
2806
+ * commute_below_r is filled with the relids of syntactically-lower outer
2807
+ * joins that have been found to commute with this one per outer join identity
2808
+ * 3 and are in the RHS of this join (so, this is the upper join in the second
2809
+ * form of the identity).
2810
+ *
2811
+ * lhs_strict is true if the special join's condition cannot succeed when the
2812
+ * LHS variables are all NULL (this means that an outer join can commute with
2813
+ * upper-level outer joins even if it appears in their RHS). We don't bother
2814
+ * to set lhs_strict for FULL JOINs, however.
2149
2815
  *
2150
2816
  * For a semijoin, we also extract the join operators and their RHS arguments
2151
2817
  * and set semi_operators, semi_rhs_exprs, semi_can_btree, and semi_can_hash.
@@ -2155,18 +2821,14 @@ typedef struct PlaceHolderVar
2155
2821
  * join planning; but it's helpful to have it available during planning of
2156
2822
  * parameterized table scans, so we store it in the SpecialJoinInfo structs.)
2157
2823
  *
2158
- * jointype is never JOIN_RIGHT; a RIGHT JOIN is handled by switching
2159
- * the inputs to make it a LEFT JOIN. So the allowed values of jointype
2160
- * in a join_info_list member are only LEFT, FULL, SEMI, or ANTI.
2161
- *
2162
2824
  * For purposes of join selectivity estimation, we create transient
2163
2825
  * SpecialJoinInfo structures for regular inner joins; so it is possible
2164
2826
  * to have jointype == JOIN_INNER in such a structure, even though this is
2165
2827
  * not allowed within join_info_list. We also create transient
2166
2828
  * SpecialJoinInfos with jointype == JOIN_INNER for outer joins, since for
2167
2829
  * cost estimation purposes it is sometimes useful to know the join size under
2168
- * plain innerjoin semantics. Note that lhs_strict, delay_upper_joins, and
2169
- * of course the semi_xxx fields are not set meaningfully within such structs.
2830
+ * plain innerjoin semantics. Note that lhs_strict and the semi_xxx fields
2831
+ * are not set meaningfully within such structs.
2170
2832
  */
2171
2833
  #ifndef HAVE_SPECIALJOININFO_TYPEDEF
2172
2834
  typedef struct SpecialJoinInfo SpecialJoinInfo;
@@ -2175,14 +2837,20 @@ typedef struct SpecialJoinInfo SpecialJoinInfo;
2175
2837
 
2176
2838
  struct SpecialJoinInfo
2177
2839
  {
2840
+ pg_node_attr(no_read, no_query_jumble)
2841
+
2178
2842
  NodeTag type;
2179
- Relids min_lefthand; /* base relids in minimum LHS for join */
2180
- Relids min_righthand; /* base relids in minimum RHS for join */
2181
- Relids syn_lefthand; /* base relids syntactically within LHS */
2182
- Relids syn_righthand; /* base relids syntactically within RHS */
2843
+ Relids min_lefthand; /* base+OJ relids in minimum LHS for join */
2844
+ Relids min_righthand; /* base+OJ relids in minimum RHS for join */
2845
+ Relids syn_lefthand; /* base+OJ relids syntactically within LHS */
2846
+ Relids syn_righthand; /* base+OJ relids syntactically within RHS */
2183
2847
  JoinType jointype; /* always INNER, LEFT, FULL, SEMI, or ANTI */
2848
+ Index ojrelid; /* outer join's RT index; 0 if none */
2849
+ Relids commute_above_l; /* commuting OJs above this one, if LHS */
2850
+ Relids commute_above_r; /* commuting OJs above this one, if RHS */
2851
+ Relids commute_below_l; /* commuting OJs in this one's LHS */
2852
+ Relids commute_below_r; /* commuting OJs in this one's RHS */
2184
2853
  bool lhs_strict; /* joinclause is strict for some LHS rel */
2185
- bool delay_upper_joins; /* can't commute with upper RHS */
2186
2854
  /* Remaining fields are set only for JOIN_SEMI jointype: */
2187
2855
  bool semi_can_btree; /* true if semi_operators are all btree */
2188
2856
  bool semi_can_hash; /* true if semi_operators are all hash */
@@ -2190,6 +2858,21 @@ struct SpecialJoinInfo
2190
2858
  List *semi_rhs_exprs; /* righthand-side expressions of these ops */
2191
2859
  };
2192
2860
 
2861
+ /*
2862
+ * Transient outer-join clause info.
2863
+ *
2864
+ * We set aside every outer join ON clause that looks mergejoinable,
2865
+ * and process it specially at the end of qual distribution.
2866
+ */
2867
+ typedef struct OuterJoinClauseInfo
2868
+ {
2869
+ pg_node_attr(no_copy_equal, no_read, no_query_jumble)
2870
+
2871
+ NodeTag type;
2872
+ RestrictInfo *rinfo; /* a mergejoinable outer-join clause */
2873
+ SpecialJoinInfo *sjinfo; /* the outer join's SpecialJoinInfo */
2874
+ } OuterJoinClauseInfo;
2875
+
2193
2876
  /*
2194
2877
  * Append-relation info.
2195
2878
  *
@@ -2222,6 +2905,8 @@ struct SpecialJoinInfo
2222
2905
 
2223
2906
  typedef struct AppendRelInfo
2224
2907
  {
2908
+ pg_node_attr(no_query_jumble)
2909
+
2225
2910
  NodeTag type;
2226
2911
 
2227
2912
  /*
@@ -2267,7 +2952,7 @@ typedef struct AppendRelInfo
2267
2952
  * child column is dropped or doesn't exist in the parent.
2268
2953
  */
2269
2954
  int num_child_cols; /* length of array */
2270
- AttrNumber *parent_colnos; /* array of parent attnos, or zeroes */
2955
+ AttrNumber *parent_colnos pg_node_attr(array_size(num_child_cols));
2271
2956
 
2272
2957
  /*
2273
2958
  * We store the parent table's OID here for inheritance, or InvalidOid for
@@ -2277,6 +2962,36 @@ typedef struct AppendRelInfo
2277
2962
  Oid parent_reloid; /* OID of parent relation */
2278
2963
  } AppendRelInfo;
2279
2964
 
2965
+ /*
2966
+ * Information about a row-identity "resjunk" column in UPDATE/DELETE/MERGE.
2967
+ *
2968
+ * In partitioned UPDATE/DELETE/MERGE it's important for child partitions to
2969
+ * share row-identity columns whenever possible, so as not to chew up too many
2970
+ * targetlist columns. We use these structs to track which identity columns
2971
+ * have been requested. In the finished plan, each of these will give rise
2972
+ * to one resjunk entry in the targetlist of the ModifyTable's subplan node.
2973
+ *
2974
+ * All the Vars stored in RowIdentityVarInfos must have varno ROWID_VAR, for
2975
+ * convenience of detecting duplicate requests. We'll replace that, in the
2976
+ * final plan, with the varno of the generating rel.
2977
+ *
2978
+ * Outside this list, a Var with varno ROWID_VAR and varattno k is a reference
2979
+ * to the k-th element of the row_identity_vars list (k counting from 1).
2980
+ * We add such a reference to root->processed_tlist when creating the entry,
2981
+ * and it propagates into the plan tree from there.
2982
+ */
2983
+ typedef struct RowIdentityVarInfo
2984
+ {
2985
+ pg_node_attr(no_copy_equal, no_read, no_query_jumble)
2986
+
2987
+ NodeTag type;
2988
+
2989
+ Var *rowidvar; /* Var to be evaluated (but varno=ROWID_VAR) */
2990
+ int32 rowidwidth; /* estimated average width */
2991
+ char *rowidname; /* name of the resjunk column */
2992
+ Relids rowidrels; /* RTE indexes of target rels using this */
2993
+ } RowIdentityVarInfo;
2994
+
2280
2995
  /*
2281
2996
  * For each distinct placeholder expression generated during planning, we
2282
2997
  * store a PlaceHolderInfo node in the PlannerInfo node's placeholder_list.
@@ -2305,14 +3020,30 @@ typedef struct AppendRelInfo
2305
3020
 
2306
3021
  typedef struct PlaceHolderInfo
2307
3022
  {
3023
+ pg_node_attr(no_read, no_query_jumble)
3024
+
2308
3025
  NodeTag type;
2309
3026
 
2310
- Index phid; /* ID for PH (unique within planner run) */
2311
- PlaceHolderVar *ph_var; /* copy of PlaceHolderVar tree */
2312
- Relids ph_eval_at; /* lowest level we can evaluate value at */
2313
- Relids ph_lateral; /* relids of contained lateral refs, if any */
2314
- Relids ph_needed; /* highest level the value is needed at */
2315
- int32 ph_width; /* estimated attribute width */
3027
+ /* ID for PH (unique within planner run) */
3028
+ Index phid;
3029
+
3030
+ /*
3031
+ * copy of PlaceHolderVar tree (should be redundant for comparison, could
3032
+ * be ignored)
3033
+ */
3034
+ PlaceHolderVar *ph_var;
3035
+
3036
+ /* lowest level we can evaluate value at */
3037
+ Relids ph_eval_at;
3038
+
3039
+ /* relids of contained lateral refs, if any */
3040
+ Relids ph_lateral;
3041
+
3042
+ /* highest level the value is needed at */
3043
+ Relids ph_needed;
3044
+
3045
+ /* estimated attribute width */
3046
+ int32 ph_width;
2316
3047
  } PlaceHolderInfo;
2317
3048
 
2318
3049
  /*
@@ -2322,15 +3053,33 @@ typedef struct PlaceHolderInfo
2322
3053
  */
2323
3054
  typedef struct MinMaxAggInfo
2324
3055
  {
3056
+ pg_node_attr(no_copy_equal, no_read, no_query_jumble)
3057
+
2325
3058
  NodeTag type;
2326
3059
 
2327
- Oid aggfnoid; /* pg_proc Oid of the aggregate */
2328
- Oid aggsortop; /* Oid of its sort operator */
2329
- Expr *target; /* expression we are aggregating on */
2330
- PlannerInfo *subroot; /* modified "root" for planning the subquery */
2331
- Path *path; /* access path for subquery */
2332
- Cost pathcost; /* estimated cost to fetch first row */
2333
- Param *param; /* param for subplan's output */
3060
+ /* pg_proc Oid of the aggregate */
3061
+ Oid aggfnoid;
3062
+
3063
+ /* Oid of its sort operator */
3064
+ Oid aggsortop;
3065
+
3066
+ /* expression we are aggregating on */
3067
+ Expr *target;
3068
+
3069
+ /*
3070
+ * modified "root" for planning the subquery; not printed, too large, not
3071
+ * interesting enough
3072
+ */
3073
+ PlannerInfo *subroot pg_node_attr(read_write_ignore);
3074
+
3075
+ /* access path for subquery */
3076
+ Path *path;
3077
+
3078
+ /* estimated cost to fetch first row */
3079
+ Cost pathcost;
3080
+
3081
+ /* param for subplan's output */
3082
+ Param *param;
2334
3083
  } MinMaxAggInfo;
2335
3084
 
2336
3085
  /*
@@ -2382,6 +3131,8 @@ typedef struct MinMaxAggInfo
2382
3131
  */
2383
3132
  typedef struct PlannerParamItem
2384
3133
  {
3134
+ pg_node_attr(no_copy_equal, no_read, no_query_jumble)
3135
+
2385
3136
  NodeTag type;
2386
3137
 
2387
3138
  Node *item; /* the Var, PlaceHolderVar, or Aggref */
@@ -2511,7 +3262,7 @@ typedef struct
2511
3262
  typedef struct
2512
3263
  {
2513
3264
  bool limit_needed;
2514
- double limit_tuples;
3265
+ Cardinality limit_tuples;
2515
3266
  int64 count_est;
2516
3267
  int64 offset_est;
2517
3268
  } FinalPathExtraData;
@@ -2542,15 +3293,92 @@ typedef struct JoinCostWorkspace
2542
3293
  Cost inner_rescan_run_cost;
2543
3294
 
2544
3295
  /* private for cost_mergejoin code */
2545
- double outer_rows;
2546
- double inner_rows;
2547
- double outer_skip_rows;
2548
- double inner_skip_rows;
3296
+ Cardinality outer_rows;
3297
+ Cardinality inner_rows;
3298
+ Cardinality outer_skip_rows;
3299
+ Cardinality inner_skip_rows;
2549
3300
 
2550
3301
  /* private for cost_hashjoin code */
2551
3302
  int numbuckets;
2552
3303
  int numbatches;
2553
- double inner_rows_total;
3304
+ Cardinality inner_rows_total;
2554
3305
  } JoinCostWorkspace;
2555
3306
 
3307
+ /*
3308
+ * AggInfo holds information about an aggregate that needs to be computed.
3309
+ * Multiple Aggrefs in a query can refer to the same AggInfo by having the
3310
+ * same 'aggno' value, so that the aggregate is computed only once.
3311
+ */
3312
+ typedef struct AggInfo
3313
+ {
3314
+ pg_node_attr(no_copy_equal, no_read, no_query_jumble)
3315
+
3316
+ NodeTag type;
3317
+
3318
+ /*
3319
+ * List of Aggref exprs that this state value is for.
3320
+ *
3321
+ * There will always be at least one, but there can be multiple identical
3322
+ * Aggref's sharing the same per-agg.
3323
+ */
3324
+ List *aggrefs;
3325
+
3326
+ /* Transition state number for this aggregate */
3327
+ int transno;
3328
+
3329
+ /*
3330
+ * "shareable" is false if this agg cannot share state values with other
3331
+ * aggregates because the final function is read-write.
3332
+ */
3333
+ bool shareable;
3334
+
3335
+ /* Oid of the final function, or InvalidOid if none */
3336
+ Oid finalfn_oid;
3337
+ } AggInfo;
3338
+
3339
+ /*
3340
+ * AggTransInfo holds information about transition state that is used by one
3341
+ * or more aggregates in the query. Multiple aggregates can share the same
3342
+ * transition state, if they have the same inputs and the same transition
3343
+ * function. Aggrefs that share the same transition info have the same
3344
+ * 'aggtransno' value.
3345
+ */
3346
+ typedef struct AggTransInfo
3347
+ {
3348
+ pg_node_attr(no_copy_equal, no_read, no_query_jumble)
3349
+
3350
+ NodeTag type;
3351
+
3352
+ /* Inputs for this transition state */
3353
+ List *args;
3354
+ Expr *aggfilter;
3355
+
3356
+ /* Oid of the state transition function */
3357
+ Oid transfn_oid;
3358
+
3359
+ /* Oid of the serialization function, or InvalidOid if none */
3360
+ Oid serialfn_oid;
3361
+
3362
+ /* Oid of the deserialization function, or InvalidOid if none */
3363
+ Oid deserialfn_oid;
3364
+
3365
+ /* Oid of the combine function, or InvalidOid if none */
3366
+ Oid combinefn_oid;
3367
+
3368
+ /* Oid of state value's datatype */
3369
+ Oid aggtranstype;
3370
+
3371
+ /* Additional data about transtype */
3372
+ int32 aggtranstypmod;
3373
+ int transtypeLen;
3374
+ bool transtypeByVal;
3375
+
3376
+ /* Space-consumption estimate */
3377
+ int32 aggtransspace;
3378
+
3379
+ /* Initial value from pg_aggregate entry */
3380
+ Datum initValue pg_node_attr(read_write_ignore);
3381
+ bool initValueIsNull;
3382
+ } AggTransInfo;
3383
+
2556
3384
  #endif /* PATHNODES_H */