pg_query 4.2.2 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (486) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +12 -0
  3. data/README.md +6 -8
  4. data/Rakefile +3 -3
  5. data/ext/pg_query/extconf.rb +1 -3
  6. data/ext/pg_query/include/access/amapi.h +3 -1
  7. data/ext/pg_query/include/access/attmap.h +5 -3
  8. data/ext/pg_query/include/access/attnum.h +1 -1
  9. data/ext/pg_query/include/access/clog.h +1 -1
  10. data/ext/pg_query/include/access/commit_ts.h +1 -1
  11. data/ext/pg_query/include/access/detoast.h +1 -1
  12. data/ext/pg_query/include/access/genam.h +7 -5
  13. data/ext/pg_query/include/access/gin.h +16 -3
  14. data/ext/pg_query/include/access/htup.h +1 -1
  15. data/ext/pg_query/include/access/htup_details.h +6 -2
  16. data/ext/pg_query/include/access/itup.h +61 -58
  17. data/ext/pg_query/include/access/parallel.h +2 -2
  18. data/ext/pg_query/include/access/printtup.h +1 -1
  19. data/ext/pg_query/include/access/relation.h +1 -1
  20. data/ext/pg_query/include/access/relscan.h +1 -1
  21. data/ext/pg_query/include/access/rmgrlist.h +2 -2
  22. data/ext/pg_query/include/access/sdir.h +12 -3
  23. data/ext/pg_query/include/access/skey.h +1 -1
  24. data/ext/pg_query/include/access/stratnum.h +1 -1
  25. data/ext/pg_query/include/access/sysattr.h +1 -1
  26. data/ext/pg_query/include/access/table.h +1 -1
  27. data/ext/pg_query/include/access/tableam.h +68 -45
  28. data/ext/pg_query/include/access/toast_compression.h +1 -1
  29. data/ext/pg_query/include/access/transam.h +1 -1
  30. data/ext/pg_query/include/access/tsmapi.h +82 -0
  31. data/ext/pg_query/include/access/tupconvert.h +5 -2
  32. data/ext/pg_query/include/access/tupdesc.h +2 -2
  33. data/ext/pg_query/include/access/tupmacs.h +58 -98
  34. data/ext/pg_query/include/access/twophase.h +2 -2
  35. data/ext/pg_query/include/access/xact.h +25 -18
  36. data/ext/pg_query/include/access/xlog.h +15 -16
  37. data/ext/pg_query/include/access/xlog_internal.h +100 -62
  38. data/ext/pg_query/include/access/xlogbackup.h +41 -0
  39. data/ext/pg_query/include/access/xlogdefs.h +6 -25
  40. data/ext/pg_query/include/access/xlogprefetcher.h +1 -1
  41. data/ext/pg_query/include/access/xlogreader.h +7 -6
  42. data/ext/pg_query/include/access/xlogrecord.h +17 -5
  43. data/ext/pg_query/include/access/xlogrecovery.h +4 -3
  44. data/ext/pg_query/include/archive/archive_module.h +59 -0
  45. data/ext/pg_query/include/c.h +144 -156
  46. data/ext/pg_query/include/catalog/catalog.h +4 -3
  47. data/ext/pg_query/include/catalog/catversion.h +6 -2
  48. data/ext/pg_query/include/catalog/dependency.h +5 -4
  49. data/ext/pg_query/include/catalog/genbki.h +7 -6
  50. data/ext/pg_query/include/catalog/index.h +4 -4
  51. data/ext/pg_query/include/catalog/indexing.h +1 -1
  52. data/ext/pg_query/include/catalog/namespace.h +2 -2
  53. data/ext/pg_query/include/catalog/objectaccess.h +10 -8
  54. data/ext/pg_query/include/catalog/objectaddress.h +3 -3
  55. data/ext/pg_query/include/catalog/pg_aggregate.h +1 -1
  56. data/ext/pg_query/include/catalog/pg_aggregate_d.h +1 -1
  57. data/ext/pg_query/include/catalog/pg_am.h +1 -1
  58. data/ext/pg_query/include/catalog/pg_am_d.h +1 -1
  59. data/ext/pg_query/include/catalog/pg_attribute.h +19 -17
  60. data/ext/pg_query/include/catalog/pg_attribute_d.h +19 -19
  61. data/ext/pg_query/include/catalog/pg_authid.h +1 -1
  62. data/ext/pg_query/include/catalog/pg_authid_d.h +3 -1
  63. data/ext/pg_query/include/catalog/pg_class.h +1 -1
  64. data/ext/pg_query/include/catalog/pg_class_d.h +1 -1
  65. data/ext/pg_query/include/catalog/pg_collation.h +3 -1
  66. data/ext/pg_query/include/catalog/pg_collation_d.h +4 -3
  67. data/ext/pg_query/include/catalog/pg_constraint.h +2 -2
  68. data/ext/pg_query/include/catalog/pg_constraint_d.h +1 -1
  69. data/ext/pg_query/include/catalog/pg_control.h +9 -1
  70. data/ext/pg_query/include/catalog/pg_conversion.h +2 -2
  71. data/ext/pg_query/include/catalog/pg_conversion_d.h +1 -1
  72. data/ext/pg_query/include/catalog/pg_database.h +124 -0
  73. data/ext/pg_query/include/catalog/pg_database_d.h +52 -0
  74. data/ext/pg_query/include/catalog/pg_depend.h +1 -1
  75. data/ext/pg_query/include/catalog/pg_depend_d.h +1 -1
  76. data/ext/pg_query/include/catalog/pg_event_trigger.h +1 -1
  77. data/ext/pg_query/include/catalog/pg_event_trigger_d.h +1 -1
  78. data/ext/pg_query/include/catalog/pg_index.h +1 -1
  79. data/ext/pg_query/include/catalog/pg_index_d.h +1 -1
  80. data/ext/pg_query/include/catalog/pg_language.h +1 -1
  81. data/ext/pg_query/include/catalog/pg_language_d.h +1 -1
  82. data/ext/pg_query/include/catalog/pg_namespace.h +1 -1
  83. data/ext/pg_query/include/catalog/pg_namespace_d.h +1 -1
  84. data/ext/pg_query/include/catalog/pg_opclass.h +1 -1
  85. data/ext/pg_query/include/catalog/pg_opclass_d.h +1 -1
  86. data/ext/pg_query/include/catalog/pg_operator.h +1 -1
  87. data/ext/pg_query/include/catalog/pg_operator_d.h +1 -1
  88. data/ext/pg_query/include/catalog/pg_opfamily.h +3 -2
  89. data/ext/pg_query/include/catalog/pg_opfamily_d.h +4 -2
  90. data/ext/pg_query/include/catalog/pg_partitioned_table.h +1 -1
  91. data/ext/pg_query/include/catalog/pg_partitioned_table_d.h +1 -1
  92. data/ext/pg_query/include/catalog/pg_proc.h +1 -1
  93. data/ext/pg_query/include/catalog/pg_proc_d.h +1 -1
  94. data/ext/pg_query/include/catalog/pg_publication.h +2 -5
  95. data/ext/pg_query/include/catalog/pg_publication_d.h +1 -1
  96. data/ext/pg_query/include/catalog/pg_replication_origin.h +1 -1
  97. data/ext/pg_query/include/catalog/pg_replication_origin_d.h +1 -1
  98. data/ext/pg_query/include/catalog/pg_statistic.h +1 -1
  99. data/ext/pg_query/include/catalog/pg_statistic_d.h +1 -1
  100. data/ext/pg_query/include/catalog/pg_statistic_ext.h +1 -1
  101. data/ext/pg_query/include/catalog/pg_statistic_ext_d.h +1 -1
  102. data/ext/pg_query/include/catalog/pg_transform.h +1 -1
  103. data/ext/pg_query/include/catalog/pg_transform_d.h +1 -1
  104. data/ext/pg_query/include/catalog/pg_trigger.h +1 -1
  105. data/ext/pg_query/include/catalog/pg_trigger_d.h +1 -1
  106. data/ext/pg_query/include/catalog/pg_ts_config.h +1 -1
  107. data/ext/pg_query/include/catalog/pg_ts_config_d.h +1 -1
  108. data/ext/pg_query/include/catalog/pg_ts_dict.h +1 -1
  109. data/ext/pg_query/include/catalog/pg_ts_dict_d.h +1 -1
  110. data/ext/pg_query/include/catalog/pg_ts_parser.h +1 -1
  111. data/ext/pg_query/include/catalog/pg_ts_parser_d.h +1 -1
  112. data/ext/pg_query/include/catalog/pg_ts_template.h +1 -1
  113. data/ext/pg_query/include/catalog/pg_ts_template_d.h +1 -1
  114. data/ext/pg_query/include/catalog/pg_type.h +1 -1
  115. data/ext/pg_query/include/catalog/pg_type_d.h +1 -1
  116. data/ext/pg_query/include/catalog/storage.h +6 -6
  117. data/ext/pg_query/include/commands/async.h +1 -1
  118. data/ext/pg_query/include/commands/dbcommands.h +2 -1
  119. data/ext/pg_query/include/commands/defrem.h +2 -1
  120. data/ext/pg_query/include/commands/event_trigger.h +1 -1
  121. data/ext/pg_query/include/commands/explain.h +3 -1
  122. data/ext/pg_query/include/commands/prepare.h +1 -1
  123. data/ext/pg_query/include/commands/tablespace.h +4 -4
  124. data/ext/pg_query/include/commands/trigger.h +15 -14
  125. data/ext/pg_query/include/commands/user.h +9 -3
  126. data/ext/pg_query/include/commands/vacuum.h +60 -14
  127. data/ext/pg_query/include/common/cryptohash.h +39 -0
  128. data/ext/pg_query/include/common/file_perm.h +1 -1
  129. data/ext/pg_query/include/common/hashfn.h +1 -1
  130. data/ext/pg_query/include/common/int.h +437 -0
  131. data/ext/pg_query/include/common/ip.h +4 -2
  132. data/ext/pg_query/include/common/keywords.h +1 -1
  133. data/ext/pg_query/include/common/kwlookup.h +2 -2
  134. data/ext/pg_query/include/common/pg_prng.h +3 -2
  135. data/ext/pg_query/include/common/relpath.h +20 -13
  136. data/ext/pg_query/include/common/scram-common.h +70 -0
  137. data/ext/pg_query/include/common/sha2.h +32 -0
  138. data/ext/pg_query/include/common/string.h +5 -3
  139. data/ext/pg_query/include/common/unicode_east_asian_fw_table.h +10 -10
  140. data/ext/pg_query/include/common/{unicode_combining_table.h → unicode_nonspacing_table.h} +31 -13
  141. data/ext/pg_query/include/copyfuncs.funcs.c +5013 -0
  142. data/ext/pg_query/include/copyfuncs.switch.c +938 -0
  143. data/ext/pg_query/include/datatype/timestamp.h +11 -4
  144. data/ext/pg_query/include/equalfuncs.funcs.c +3097 -0
  145. data/ext/pg_query/include/equalfuncs.switch.c +785 -0
  146. data/ext/pg_query/include/executor/execdesc.h +1 -1
  147. data/ext/pg_query/include/executor/executor.h +34 -17
  148. data/ext/pg_query/include/executor/functions.h +1 -1
  149. data/ext/pg_query/include/executor/instrument.h +1 -1
  150. data/ext/pg_query/include/executor/spi.h +2 -2
  151. data/ext/pg_query/include/executor/tablefunc.h +1 -1
  152. data/ext/pg_query/include/executor/tuptable.h +18 -11
  153. data/ext/pg_query/include/fmgr.h +21 -2
  154. data/ext/pg_query/include/foreign/fdwapi.h +294 -0
  155. data/ext/pg_query/include/funcapi.h +12 -12
  156. data/ext/pg_query/include/gram.h +1127 -0
  157. data/ext/pg_query/include/{parser/gramparse.h → gramparse.h} +4 -4
  158. data/ext/pg_query/include/jit/jit.h +2 -2
  159. data/ext/pg_query/include/kwlist_d.h +534 -510
  160. data/ext/pg_query/include/lib/dshash.h +4 -1
  161. data/ext/pg_query/include/lib/ilist.h +435 -22
  162. data/ext/pg_query/include/lib/pairingheap.h +1 -1
  163. data/ext/pg_query/include/lib/simplehash.h +9 -9
  164. data/ext/pg_query/include/lib/sort_template.h +1 -1
  165. data/ext/pg_query/include/lib/stringinfo.h +3 -3
  166. data/ext/pg_query/include/libpq/auth.h +8 -2
  167. data/ext/pg_query/include/libpq/crypt.h +1 -1
  168. data/ext/pg_query/include/libpq/hba.h +24 -17
  169. data/ext/pg_query/include/libpq/libpq-be.h +36 -25
  170. data/ext/pg_query/include/libpq/libpq.h +1 -1
  171. data/ext/pg_query/include/libpq/pqcomm.h +10 -41
  172. data/ext/pg_query/include/libpq/pqformat.h +2 -2
  173. data/ext/pg_query/include/libpq/pqsignal.h +22 -10
  174. data/ext/pg_query/include/libpq/sasl.h +136 -0
  175. data/ext/pg_query/include/libpq/scram.h +37 -0
  176. data/ext/pg_query/include/mb/pg_wchar.h +35 -18
  177. data/ext/pg_query/include/mb/stringinfo_mb.h +1 -1
  178. data/ext/pg_query/include/miscadmin.h +26 -14
  179. data/ext/pg_query/include/nodes/bitmapset.h +11 -7
  180. data/ext/pg_query/include/nodes/execnodes.h +83 -30
  181. data/ext/pg_query/include/nodes/extensible.h +5 -3
  182. data/ext/pg_query/include/nodes/lockoptions.h +1 -1
  183. data/ext/pg_query/include/nodes/makefuncs.h +14 -2
  184. data/ext/pg_query/include/nodes/memnodes.h +7 -4
  185. data/ext/pg_query/include/nodes/miscnodes.h +56 -0
  186. data/ext/pg_query/include/nodes/nodeFuncs.h +89 -29
  187. data/ext/pg_query/include/nodes/nodes.h +95 -510
  188. data/ext/pg_query/include/nodes/nodetags.h +471 -0
  189. data/ext/pg_query/include/nodes/params.h +3 -3
  190. data/ext/pg_query/include/nodes/parsenodes.h +377 -139
  191. data/ext/pg_query/include/nodes/pathnodes.h +1090 -440
  192. data/ext/pg_query/include/nodes/pg_list.h +30 -7
  193. data/ext/pg_query/include/nodes/plannodes.h +367 -124
  194. data/ext/pg_query/include/nodes/primnodes.h +670 -222
  195. data/ext/pg_query/include/nodes/print.h +1 -1
  196. data/ext/pg_query/include/{utils → nodes}/queryjumble.h +5 -7
  197. data/ext/pg_query/include/nodes/replnodes.h +111 -0
  198. data/ext/pg_query/include/nodes/supportnodes.h +346 -0
  199. data/ext/pg_query/include/nodes/tidbitmap.h +1 -1
  200. data/ext/pg_query/include/nodes/value.h +12 -2
  201. data/ext/pg_query/include/optimizer/cost.h +6 -4
  202. data/ext/pg_query/include/optimizer/geqo.h +1 -1
  203. data/ext/pg_query/include/optimizer/geqo_gene.h +1 -1
  204. data/ext/pg_query/include/optimizer/optimizer.h +8 -8
  205. data/ext/pg_query/include/optimizer/paths.h +16 -7
  206. data/ext/pg_query/include/optimizer/planmain.h +3 -6
  207. data/ext/pg_query/include/parser/analyze.h +4 -3
  208. data/ext/pg_query/include/parser/kwlist.h +12 -1
  209. data/ext/pg_query/include/parser/parse_agg.h +4 -2
  210. data/ext/pg_query/include/parser/parse_coerce.h +3 -1
  211. data/ext/pg_query/include/parser/parse_expr.h +1 -1
  212. data/ext/pg_query/include/parser/parse_func.h +1 -1
  213. data/ext/pg_query/include/parser/parse_node.h +22 -4
  214. data/ext/pg_query/include/parser/parse_oper.h +3 -3
  215. data/ext/pg_query/include/parser/parse_relation.h +8 -3
  216. data/ext/pg_query/include/parser/parse_type.h +4 -3
  217. data/ext/pg_query/include/parser/parser.h +1 -1
  218. data/ext/pg_query/include/parser/parsetree.h +1 -1
  219. data/ext/pg_query/include/parser/scanner.h +2 -2
  220. data/ext/pg_query/include/parser/scansup.h +1 -1
  221. data/ext/pg_query/include/partitioning/partdefs.h +1 -1
  222. data/ext/pg_query/include/pg_config.h +23 -217
  223. data/ext/pg_query/include/pg_config_manual.h +8 -46
  224. data/ext/pg_query/include/pg_getopt.h +1 -1
  225. data/ext/pg_query/include/pg_query.h +27 -3
  226. data/ext/pg_query/include/pg_query_enum_defs.c +311 -149
  227. data/ext/pg_query/include/pg_query_fingerprint_conds.c +545 -489
  228. data/ext/pg_query/include/pg_query_fingerprint_defs.c +5092 -4432
  229. data/ext/pg_query/include/pg_query_outfuncs_conds.c +385 -343
  230. data/ext/pg_query/include/pg_query_outfuncs_defs.c +1294 -1161
  231. data/ext/pg_query/include/pg_query_readfuncs_conds.c +137 -123
  232. data/ext/pg_query/include/pg_query_readfuncs_defs.c +1657 -1496
  233. data/ext/pg_query/include/pg_trace.h +1 -1
  234. data/ext/pg_query/include/pgstat.h +172 -93
  235. data/ext/pg_query/include/pgtime.h +3 -3
  236. data/ext/pg_query/include/pl_gram.h +64 -62
  237. data/ext/pg_query/include/pl_reserved_kwlist.h +1 -1
  238. data/ext/pg_query/include/pl_reserved_kwlist_d.h +1 -1
  239. data/ext/pg_query/include/pl_unreserved_kwlist.h +2 -1
  240. data/ext/pg_query/include/pl_unreserved_kwlist_d.h +48 -46
  241. data/ext/pg_query/include/plpgsql.h +17 -22
  242. data/ext/pg_query/include/port/atomics/arch-arm.h +3 -3
  243. data/ext/pg_query/include/port/atomics/arch-ppc.h +21 -21
  244. data/ext/pg_query/include/port/atomics/arch-x86.h +2 -2
  245. data/ext/pg_query/include/port/atomics/fallback.h +3 -3
  246. data/ext/pg_query/include/port/atomics/generic-gcc.h +1 -1
  247. data/ext/pg_query/include/port/atomics/generic.h +1 -1
  248. data/ext/pg_query/include/port/atomics.h +2 -7
  249. data/ext/pg_query/include/port/pg_bitutils.h +62 -25
  250. data/ext/pg_query/include/port/pg_bswap.h +1 -1
  251. data/ext/pg_query/include/port/pg_crc32c.h +1 -1
  252. data/ext/pg_query/include/port/simd.h +375 -0
  253. data/ext/pg_query/include/port.h +42 -75
  254. data/ext/pg_query/include/portability/instr_time.h +81 -140
  255. data/ext/pg_query/include/postgres.h +205 -434
  256. data/ext/pg_query/include/postgres_ext.h +0 -1
  257. data/ext/pg_query/include/postmaster/autovacuum.h +1 -4
  258. data/ext/pg_query/include/postmaster/auxprocess.h +1 -1
  259. data/ext/pg_query/include/postmaster/bgworker.h +2 -2
  260. data/ext/pg_query/include/postmaster/bgworker_internals.h +1 -1
  261. data/ext/pg_query/include/postmaster/bgwriter.h +2 -2
  262. data/ext/pg_query/include/postmaster/fork_process.h +1 -1
  263. data/ext/pg_query/include/postmaster/interrupt.h +1 -1
  264. data/ext/pg_query/include/postmaster/pgarch.h +1 -38
  265. data/ext/pg_query/include/postmaster/postmaster.h +5 -2
  266. data/ext/pg_query/include/postmaster/startup.h +3 -1
  267. data/ext/pg_query/include/postmaster/syslogger.h +2 -2
  268. data/ext/pg_query/include/postmaster/walwriter.h +3 -1
  269. data/ext/pg_query/include/protobuf/pg_query.pb-c.h +6186 -5585
  270. data/ext/pg_query/include/protobuf/pg_query.pb.h +112443 -91222
  271. data/ext/pg_query/include/regex/regex.h +9 -6
  272. data/ext/pg_query/include/replication/logicallauncher.h +6 -1
  273. data/ext/pg_query/include/replication/logicalproto.h +30 -10
  274. data/ext/pg_query/include/replication/logicalworker.h +14 -1
  275. data/ext/pg_query/include/replication/origin.h +4 -4
  276. data/ext/pg_query/include/replication/reorderbuffer.h +113 -45
  277. data/ext/pg_query/include/replication/slot.h +25 -6
  278. data/ext/pg_query/include/replication/syncrep.h +2 -8
  279. data/ext/pg_query/include/replication/walreceiver.h +15 -9
  280. data/ext/pg_query/include/replication/walsender.h +13 -13
  281. data/ext/pg_query/include/rewrite/prs2lock.h +1 -1
  282. data/ext/pg_query/include/rewrite/rewriteHandler.h +1 -4
  283. data/ext/pg_query/include/rewrite/rewriteManip.h +11 -2
  284. data/ext/pg_query/include/rewrite/rewriteSupport.h +1 -1
  285. data/ext/pg_query/include/src_backend_nodes_copyfuncs.funcs.c +5321 -0
  286. data/ext/pg_query/include/src_backend_nodes_equalfuncs.funcs.c +3354 -0
  287. data/ext/pg_query/include/storage/backendid.h +1 -1
  288. data/ext/pg_query/include/storage/block.h +24 -31
  289. data/ext/pg_query/include/storage/buf.h +1 -1
  290. data/ext/pg_query/include/storage/bufmgr.h +183 -87
  291. data/ext/pg_query/include/storage/bufpage.h +146 -93
  292. data/ext/pg_query/include/storage/condition_variable.h +2 -2
  293. data/ext/pg_query/include/storage/dsm.h +3 -6
  294. data/ext/pg_query/include/storage/dsm_impl.h +4 -1
  295. data/ext/pg_query/include/storage/fd.h +24 -20
  296. data/ext/pg_query/include/storage/fileset.h +1 -1
  297. data/ext/pg_query/include/storage/ipc.h +1 -1
  298. data/ext/pg_query/include/storage/item.h +1 -1
  299. data/ext/pg_query/include/storage/itemid.h +1 -1
  300. data/ext/pg_query/include/storage/itemptr.h +94 -57
  301. data/ext/pg_query/include/storage/large_object.h +1 -1
  302. data/ext/pg_query/include/storage/latch.h +9 -1
  303. data/ext/pg_query/include/storage/lmgr.h +6 -1
  304. data/ext/pg_query/include/storage/lock.h +21 -13
  305. data/ext/pg_query/include/storage/lockdefs.h +3 -3
  306. data/ext/pg_query/include/storage/lwlock.h +16 -2
  307. data/ext/pg_query/include/storage/off.h +1 -1
  308. data/ext/pg_query/include/storage/pg_sema.h +1 -1
  309. data/ext/pg_query/include/storage/pg_shmem.h +1 -1
  310. data/ext/pg_query/include/storage/pmsignal.h +1 -1
  311. data/ext/pg_query/include/storage/predicate.h +2 -2
  312. data/ext/pg_query/include/storage/proc.h +22 -17
  313. data/ext/pg_query/include/storage/procarray.h +3 -2
  314. data/ext/pg_query/include/storage/proclist_types.h +1 -1
  315. data/ext/pg_query/include/storage/procsignal.h +3 -1
  316. data/ext/pg_query/include/storage/relfilelocator.h +99 -0
  317. data/ext/pg_query/include/storage/s_lock.h +66 -309
  318. data/ext/pg_query/include/storage/sharedfileset.h +1 -1
  319. data/ext/pg_query/include/storage/shm_mq.h +1 -1
  320. data/ext/pg_query/include/storage/shm_toc.h +1 -1
  321. data/ext/pg_query/include/storage/shmem.h +1 -23
  322. data/ext/pg_query/include/storage/sinval.h +3 -3
  323. data/ext/pg_query/include/storage/sinvaladt.h +4 -2
  324. data/ext/pg_query/include/storage/smgr.h +12 -10
  325. data/ext/pg_query/include/storage/spin.h +1 -1
  326. data/ext/pg_query/include/storage/standby.h +9 -8
  327. data/ext/pg_query/include/storage/standbydefs.h +1 -1
  328. data/ext/pg_query/include/storage/sync.h +3 -3
  329. data/ext/pg_query/include/tcop/cmdtag.h +7 -2
  330. data/ext/pg_query/include/tcop/cmdtaglist.h +1 -1
  331. data/ext/pg_query/include/tcop/deparse_utility.h +1 -1
  332. data/ext/pg_query/include/tcop/dest.h +1 -3
  333. data/ext/pg_query/include/tcop/fastpath.h +1 -1
  334. data/ext/pg_query/include/tcop/pquery.h +1 -1
  335. data/ext/pg_query/include/tcop/tcopprot.h +1 -4
  336. data/ext/pg_query/include/tcop/utility.h +1 -1
  337. data/ext/pg_query/include/tsearch/ts_cache.h +2 -4
  338. data/ext/pg_query/include/utils/acl.h +26 -81
  339. data/ext/pg_query/include/utils/aclchk_internal.h +1 -1
  340. data/ext/pg_query/include/utils/array.h +19 -1
  341. data/ext/pg_query/include/utils/backend_progress.h +2 -1
  342. data/ext/pg_query/include/utils/backend_status.h +24 -3
  343. data/ext/pg_query/include/utils/builtins.h +14 -5
  344. data/ext/pg_query/include/utils/bytea.h +1 -1
  345. data/ext/pg_query/include/utils/catcache.h +1 -1
  346. data/ext/pg_query/include/utils/date.h +37 -9
  347. data/ext/pg_query/include/utils/datetime.h +41 -21
  348. data/ext/pg_query/include/utils/datum.h +1 -1
  349. data/ext/pg_query/include/utils/dsa.h +5 -1
  350. data/ext/pg_query/include/utils/elog.h +101 -26
  351. data/ext/pg_query/include/utils/expandeddatum.h +14 -3
  352. data/ext/pg_query/include/utils/expandedrecord.h +14 -4
  353. data/ext/pg_query/include/utils/float.h +7 -6
  354. data/ext/pg_query/include/utils/fmgroids.h +54 -1
  355. data/ext/pg_query/include/utils/fmgrprotos.h +45 -3
  356. data/ext/pg_query/include/utils/fmgrtab.h +1 -1
  357. data/ext/pg_query/include/utils/guc.h +55 -82
  358. data/ext/pg_query/include/utils/guc_hooks.h +163 -0
  359. data/ext/pg_query/include/utils/guc_tables.h +49 -3
  360. data/ext/pg_query/include/utils/hsearch.h +1 -1
  361. data/ext/pg_query/include/utils/inval.h +3 -3
  362. data/ext/pg_query/include/utils/logtape.h +77 -0
  363. data/ext/pg_query/include/utils/lsyscache.h +5 -1
  364. data/ext/pg_query/include/utils/memdebug.h +1 -1
  365. data/ext/pg_query/include/utils/memutils.h +5 -49
  366. data/ext/pg_query/include/utils/memutils_internal.h +136 -0
  367. data/ext/pg_query/include/utils/memutils_memorychunk.h +237 -0
  368. data/ext/pg_query/include/utils/numeric.h +20 -5
  369. data/ext/pg_query/include/utils/palloc.h +8 -1
  370. data/ext/pg_query/include/utils/partcache.h +3 -2
  371. data/ext/pg_query/include/utils/pg_locale.h +22 -14
  372. data/ext/pg_query/include/utils/pgstat_internal.h +37 -7
  373. data/ext/pg_query/include/utils/pidfile.h +1 -1
  374. data/ext/pg_query/include/utils/plancache.h +1 -1
  375. data/ext/pg_query/include/utils/portal.h +1 -1
  376. data/ext/pg_query/include/utils/probes.h +6 -6
  377. data/ext/pg_query/include/utils/ps_status.h +23 -1
  378. data/ext/pg_query/include/utils/queryenvironment.h +1 -1
  379. data/ext/pg_query/include/utils/regproc.h +3 -3
  380. data/ext/pg_query/include/utils/rel.h +60 -43
  381. data/ext/pg_query/include/utils/relcache.h +13 -8
  382. data/ext/pg_query/include/utils/reltrigger.h +1 -1
  383. data/ext/pg_query/include/utils/resowner.h +1 -1
  384. data/ext/pg_query/include/utils/ruleutils.h +6 -1
  385. data/ext/pg_query/include/utils/sharedtuplestore.h +1 -1
  386. data/ext/pg_query/include/utils/snapmgr.h +4 -2
  387. data/ext/pg_query/include/utils/snapshot.h +1 -1
  388. data/ext/pg_query/include/utils/sortsupport.h +2 -2
  389. data/ext/pg_query/include/utils/syscache.h +4 -1
  390. data/ext/pg_query/include/utils/timeout.h +1 -1
  391. data/ext/pg_query/include/utils/timestamp.h +41 -11
  392. data/ext/pg_query/include/utils/tuplesort.h +189 -35
  393. data/ext/pg_query/include/utils/tuplestore.h +1 -1
  394. data/ext/pg_query/include/utils/typcache.h +1 -1
  395. data/ext/pg_query/include/utils/varlena.h +13 -1
  396. data/ext/pg_query/include/utils/wait_event.h +9 -4
  397. data/ext/pg_query/include/utils/xml.h +15 -5
  398. data/ext/pg_query/include/varatt.h +358 -0
  399. data/ext/pg_query/pg_query.c +1 -1
  400. data/ext/pg_query/pg_query.pb-c.c +19755 -17757
  401. data/ext/pg_query/pg_query_fingerprint.c +8 -3
  402. data/ext/pg_query/pg_query_fingerprint.h +1 -1
  403. data/ext/pg_query/pg_query_internal.h +1 -1
  404. data/ext/pg_query/pg_query_json_plpgsql.c +1 -0
  405. data/ext/pg_query/pg_query_normalize.c +1 -1
  406. data/ext/pg_query/pg_query_outfuncs_protobuf.c +2 -2
  407. data/ext/pg_query/pg_query_parse.c +46 -4
  408. data/ext/pg_query/pg_query_parse_plpgsql.c +1 -1
  409. data/ext/pg_query/pg_query_scan.c +1 -1
  410. data/ext/pg_query/pg_query_split.c +2 -2
  411. data/ext/pg_query/postgres_deparse.c +511 -109
  412. data/ext/pg_query/src_backend_catalog_namespace.c +7 -2
  413. data/ext/pg_query/src_backend_catalog_pg_proc.c +1 -1
  414. data/ext/pg_query/src_backend_commands_define.c +1 -1
  415. data/ext/pg_query/src_backend_nodes_bitmapset.c +11 -70
  416. data/ext/pg_query/src_backend_nodes_copyfuncs.c +96 -6202
  417. data/ext/pg_query/src_backend_nodes_equalfuncs.c +95 -4068
  418. data/ext/pg_query/src_backend_nodes_extensible.c +6 -29
  419. data/ext/pg_query/src_backend_nodes_list.c +14 -2
  420. data/ext/pg_query/src_backend_nodes_makefuncs.c +95 -1
  421. data/ext/pg_query/src_backend_nodes_nodeFuncs.c +283 -132
  422. data/ext/pg_query/src_backend_nodes_value.c +1 -1
  423. data/ext/pg_query/src_backend_parser_gram.c +33208 -31806
  424. data/ext/pg_query/src_backend_parser_parser.c +28 -2
  425. data/ext/pg_query/src_backend_parser_scan.c +4318 -3329
  426. data/ext/pg_query/src_backend_parser_scansup.c +1 -1
  427. data/ext/pg_query/src_backend_postmaster_postmaster.c +129 -110
  428. data/ext/pg_query/src_backend_storage_ipc_ipc.c +1 -1
  429. data/ext/pg_query/src_backend_tcop_postgres.c +66 -87
  430. data/ext/pg_query/src_backend_utils_activity_pgstat_database.c +1 -1
  431. data/ext/pg_query/src_backend_utils_adt_datum.c +5 -7
  432. data/ext/pg_query/src_backend_utils_adt_expandeddatum.c +1 -1
  433. data/ext/pg_query/src_backend_utils_adt_format_type.c +1 -1
  434. data/ext/pg_query/src_backend_utils_adt_numutils.c +489 -0
  435. data/ext/pg_query/src_backend_utils_adt_ruleutils.c +79 -5
  436. data/ext/pg_query/src_backend_utils_error_assert.c +4 -7
  437. data/ext/pg_query/src_backend_utils_error_elog.c +354 -97
  438. data/ext/pg_query/src_backend_utils_fmgr_fmgr.c +33 -1
  439. data/ext/pg_query/src_backend_utils_init_globals.c +5 -2
  440. data/ext/pg_query/src_backend_utils_mb_mbutils.c +13 -4
  441. data/ext/pg_query/src_backend_utils_misc_guc_tables.c +494 -0
  442. data/ext/pg_query/src_backend_utils_mmgr_alignedalloc.c +163 -0
  443. data/ext/pg_query/src_backend_utils_mmgr_aset.c +449 -312
  444. data/ext/pg_query/src_backend_utils_mmgr_generation.c +1039 -0
  445. data/ext/pg_query/src_backend_utils_mmgr_mcxt.c +398 -49
  446. data/ext/pg_query/src_backend_utils_mmgr_slab.c +1021 -0
  447. data/ext/pg_query/src_common_encnames.c +4 -1
  448. data/ext/pg_query/src_common_hashfn.c +1 -1
  449. data/ext/pg_query/src_common_keywords.c +1 -1
  450. data/ext/pg_query/src_common_kwlist_d.h +534 -510
  451. data/ext/pg_query/src_common_kwlookup.c +1 -1
  452. data/ext/pg_query/src_common_psprintf.c +1 -1
  453. data/ext/pg_query/src_common_stringinfo.c +4 -4
  454. data/ext/pg_query/src_common_wchar.c +9 -8
  455. data/ext/pg_query/src_pl_plpgsql_src_pl_comp.c +1 -1
  456. data/ext/pg_query/src_pl_plpgsql_src_pl_funcs.c +3 -1
  457. data/ext/pg_query/src_pl_plpgsql_src_pl_gram.c +661 -694
  458. data/ext/pg_query/src_pl_plpgsql_src_pl_handler.c +1 -1
  459. data/ext/pg_query/src_pl_plpgsql_src_pl_reserved_kwlist_d.h +1 -1
  460. data/ext/pg_query/src_pl_plpgsql_src_pl_scanner.c +1 -1
  461. data/ext/pg_query/src_pl_plpgsql_src_pl_unreserved_kwlist_d.h +48 -46
  462. data/ext/pg_query/src_port_pg_bitutils.c +1 -1
  463. data/ext/pg_query/src_port_pgstrcasecmp.c +29 -1
  464. data/ext/pg_query/src_port_snprintf.c +3 -7
  465. data/ext/pg_query/src_port_strerror.c +1 -1
  466. data/ext/pg_query/src_port_strnlen.c +1 -1
  467. data/lib/pg_query/pg_query_pb.rb +166 -3191
  468. data/lib/pg_query/treewalker.rb +7 -2
  469. data/lib/pg_query/version.rb +1 -1
  470. metadata +43 -24
  471. data/ext/pg_query/include/catalog/pg_parameter_acl.h +0 -60
  472. data/ext/pg_query/include/catalog/pg_parameter_acl_d.h +0 -34
  473. data/ext/pg_query/include/commands/variable.h +0 -38
  474. data/ext/pg_query/include/getaddrinfo.h +0 -162
  475. data/ext/pg_query/include/parser/gram.h +0 -1101
  476. data/ext/pg_query/include/storage/relfilenode.h +0 -99
  477. data/ext/pg_query/include/utils/dynahash.h +0 -20
  478. data/ext/pg_query/include/utils/pg_lsn.h +0 -29
  479. data/ext/pg_query/include/utils/rls.h +0 -50
  480. data/ext/pg_query/include/utils/tzparser.h +0 -39
  481. data/ext/pg_query/src_backend_storage_lmgr_s_lock.c +0 -371
  482. data/ext/pg_query/src_backend_utils_hash_dynahash.c +0 -1116
  483. data/ext/pg_query/src_backend_utils_misc_guc.c +0 -1993
  484. data/ext/pg_query/src_common_pg_prng.c +0 -152
  485. data/ext/pg_query/src_common_string.c +0 -92
  486. data/ext/pg_query/src_port_pgsleep.c +0 -69
@@ -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-2022, 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
@@ -85,51 +87,79 @@ typedef enum UpperRelationKind
85
87
  * PlannerGlobal holds state for an entire planner invocation; this state
86
88
  * is shared across all levels of sub-Queries that exist in the command being
87
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.)
88
93
  *----------
89
94
  */
90
95
  typedef struct PlannerGlobal
91
96
  {
97
+ pg_node_attr(no_copy_equal, no_read, no_query_jumble)
98
+
92
99
  NodeTag type;
93
100
 
94
- ParamListInfo boundParams; /* Param values provided to planner() */
101
+ /* Param values provided to planner() */
102
+ ParamListInfo boundParams pg_node_attr(read_write_ignore);
95
103
 
96
- List *subplans; /* Plans for SubPlan nodes */
104
+ /* Plans for SubPlan nodes */
105
+ List *subplans;
97
106
 
98
- List *subroots; /* PlannerInfos for SubPlan nodes */
107
+ /* PlannerInfos for SubPlan nodes */
108
+ List *subroots pg_node_attr(read_write_ignore);
99
109
 
100
- Bitmapset *rewindPlanIDs; /* indices of subplans that require REWIND */
110
+ /* indices of subplans that require REWIND */
111
+ Bitmapset *rewindPlanIDs;
101
112
 
102
- List *finalrtable; /* "flat" rangetable for executor */
113
+ /* "flat" rangetable for executor */
114
+ List *finalrtable;
103
115
 
104
- List *finalrowmarks; /* "flat" list of PlanRowMarks */
116
+ /* "flat" list of RTEPermissionInfos */
117
+ List *finalrteperminfos;
105
118
 
106
- List *resultRelations; /* "flat" list of integer RT indexes */
119
+ /* "flat" list of PlanRowMarks */
120
+ List *finalrowmarks;
107
121
 
108
- List *appendRelations; /* "flat" list of AppendRelInfos */
122
+ /* "flat" list of integer RT indexes */
123
+ List *resultRelations;
109
124
 
110
- List *relationOids; /* OIDs of relations the plan depends on */
125
+ /* "flat" list of AppendRelInfos */
126
+ List *appendRelations;
111
127
 
112
- List *invalItems; /* other dependencies, as PlanInvalItems */
128
+ /* OIDs of relations the plan depends on */
129
+ List *relationOids;
113
130
 
114
- List *paramExecTypes; /* type OIDs for PARAM_EXEC Params */
131
+ /* other dependencies, as PlanInvalItems */
132
+ List *invalItems;
115
133
 
116
- Index lastPHId; /* highest PlaceHolderVar ID assigned */
134
+ /* type OIDs for PARAM_EXEC Params */
135
+ List *paramExecTypes;
117
136
 
118
- Index lastRowMarkId; /* highest PlanRowMark ID assigned */
137
+ /* highest PlaceHolderVar ID assigned */
138
+ Index lastPHId;
119
139
 
120
- int lastPlanNodeId; /* highest plan node ID assigned */
140
+ /* highest PlanRowMark ID assigned */
141
+ Index lastRowMarkId;
121
142
 
122
- bool transientPlan; /* redo plan when TransactionXmin changes? */
143
+ /* highest plan node ID assigned */
144
+ int lastPlanNodeId;
123
145
 
124
- bool dependsOnRole; /* is plan specific to current role? */
146
+ /* redo plan when TransactionXmin changes? */
147
+ bool transientPlan;
125
148
 
126
- bool parallelModeOK; /* parallel mode potentially OK? */
149
+ /* is plan specific to current role? */
150
+ bool dependsOnRole;
127
151
 
128
- bool parallelModeNeeded; /* parallel mode actually required? */
152
+ /* parallel mode potentially OK? */
153
+ bool parallelModeOK;
129
154
 
130
- char maxParallelHazard; /* worst PROPARALLEL hazard level */
155
+ /* parallel mode actually required? */
156
+ bool parallelModeNeeded;
131
157
 
132
- PartitionDirectory partition_directory; /* partition descriptors */
158
+ /* worst PROPARALLEL hazard level */
159
+ char maxParallelHazard;
160
+
161
+ /* partition descriptors */
162
+ PartitionDirectory partition_directory pg_node_attr(read_write_ignore);
133
163
  } PlannerGlobal;
134
164
 
135
165
  /* macro for fetching the Plan associated with a SubPlan node */
@@ -148,6 +178,10 @@ typedef struct PlannerGlobal
148
178
  *
149
179
  * For reasons explained in optimizer/optimizer.h, we define the typedef
150
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.)
151
185
  *----------
152
186
  */
153
187
  #ifndef HAVE_PLANNERINFO_TYPEDEF
@@ -157,15 +191,21 @@ typedef struct PlannerInfo PlannerInfo;
157
191
 
158
192
  struct PlannerInfo
159
193
  {
194
+ pg_node_attr(no_copy_equal, no_read, no_query_jumble)
195
+
160
196
  NodeTag type;
161
197
 
162
- Query *parse; /* the Query being planned */
198
+ /* the Query being planned */
199
+ Query *parse;
163
200
 
164
- PlannerGlobal *glob; /* global info for current planner run */
201
+ /* global info for current planner run */
202
+ PlannerGlobal *glob;
165
203
 
166
- Index query_level; /* 1 at the outermost Query */
204
+ /* 1 at the outermost Query */
205
+ Index query_level;
167
206
 
168
- PlannerInfo *parent_root; /* NULL at outermost Query */
207
+ /* NULL at outermost Query */
208
+ PlannerInfo *parent_root pg_node_attr(read_write_ignore);
169
209
 
170
210
  /*
171
211
  * plan_params contains the expressions that this query level needs to
@@ -173,7 +213,8 @@ struct PlannerInfo
173
213
  * outer_params contains the paramIds of PARAM_EXEC Params that outer
174
214
  * query levels will make available to this query level.
175
215
  */
176
- List *plan_params; /* list of PlannerParamItems, see below */
216
+ /* list of PlannerParamItems, see below */
217
+ List *plan_params;
177
218
  Bitmapset *outer_params;
178
219
 
179
220
  /*
@@ -183,39 +224,46 @@ struct PlannerInfo
183
224
  * does not correspond to a base relation, such as a join RTE or an
184
225
  * unreferenced view RTE; or if the RelOptInfo hasn't been made yet.
185
226
  */
186
- struct RelOptInfo **simple_rel_array; /* All 1-rel RelOptInfos */
187
- 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;
188
230
 
189
231
  /*
190
232
  * simple_rte_array is the same length as simple_rel_array and holds
191
233
  * pointers to the associated rangetable entries. Using this is a shade
192
- * 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.)
193
236
  */
194
- RangeTblEntry **simple_rte_array; /* rangetable as an array */
237
+ RangeTblEntry **simple_rte_array pg_node_attr(read_write_ignore);
195
238
 
196
239
  /*
197
240
  * append_rel_array is the same length as the above arrays, and holds
198
241
  * pointers to the corresponding AppendRelInfo entry indexed by
199
242
  * child_relid, or NULL if the rel is not an appendrel child. The array
200
- * 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.)
201
245
  */
202
- struct AppendRelInfo **append_rel_array;
246
+ struct AppendRelInfo **append_rel_array pg_node_attr(read_write_ignore);
203
247
 
204
248
  /*
205
- * all_baserels is a Relids set of all base relids (but not "other"
206
- * relids) in the query; that is, the Relids identifier of the final join
207
- * we need to form. This is computed in make_one_rel, just before we
208
- * 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.
209
251
  */
210
252
  Relids all_baserels;
211
253
 
212
254
  /*
213
- * nullable_baserels is a Relids set of base relids that are nullable by
214
- * some outer join in the jointree; these are rels that are potentially
215
- * nullable below the WHERE clause, SELECT targetlist, etc. This is
216
- * 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.
217
265
  */
218
- Relids nullable_baserels;
266
+ Relids all_query_rels;
219
267
 
220
268
  /*
221
269
  * join_rel_list is a list of all join-relation RelOptInfos we have
@@ -226,8 +274,8 @@ struct PlannerInfo
226
274
  * even when using the hash table for lookups; this simplifies life for
227
275
  * GEQO.
228
276
  */
229
- List *join_rel_list; /* list of join-relation RelOptInfos */
230
- 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);
231
279
 
232
280
  /*
233
281
  * When doing a dynamic-programming-style join search, join_rel_level[k]
@@ -235,36 +283,61 @@ struct PlannerInfo
235
283
  * join_cur_level is the current level. New join-relation RelOptInfos are
236
284
  * automatically added to the join_rel_level[join_cur_level] list.
237
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.
289
+ */
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;
294
+
295
+ /* init SubPlans for query */
296
+ List *init_plans;
297
+
298
+ /*
299
+ * per-CTE-item list of subplan IDs (or -1 if no subplan was made for that
300
+ * CTE)
238
301
  */
239
- List **join_rel_level; /* lists of join-relation RelOptInfos */
240
- int join_cur_level; /* index of list being extended */
302
+ List *cte_plan_ids;
241
303
 
242
- List *init_plans; /* init SubPlans for query */
304
+ /* List of Lists of Params for MULTIEXPR subquery outputs */
305
+ List *multiexpr_params;
243
306
 
244
- List *cte_plan_ids; /* per-CTE-item list of subplan IDs (or -1 if
245
- * no subplan was made for that CTE) */
307
+ /* list of JoinDomains used in the query (higher ones first) */
308
+ List *join_domains;
246
309
 
247
- List *multiexpr_params; /* List of Lists of Params for MULTIEXPR
248
- * subquery outputs */
310
+ /* list of active EquivalenceClasses */
311
+ List *eq_classes;
249
312
 
250
- List *eq_classes; /* list of active EquivalenceClasses */
313
+ /* set true once ECs are canonical */
314
+ bool ec_merging_done;
251
315
 
252
- bool ec_merging_done; /* set true once ECs are canonical */
316
+ /* list of "canonical" PathKeys */
317
+ List *canon_pathkeys;
253
318
 
254
- List *canon_pathkeys; /* list of "canonical" PathKeys */
319
+ /*
320
+ * list of OuterJoinClauseInfos for mergejoinable outer join clauses
321
+ * w/nonnullable var on left
322
+ */
323
+ List *left_join_clauses;
255
324
 
256
- List *left_join_clauses; /* list of RestrictInfos for mergejoinable
257
- * outer join clauses w/nonnullable var on
258
- * left */
325
+ /*
326
+ * list of OuterJoinClauseInfos for mergejoinable outer join clauses
327
+ * w/nonnullable var on right
328
+ */
329
+ List *right_join_clauses;
259
330
 
260
- List *right_join_clauses; /* list of RestrictInfos for mergejoinable
261
- * outer join clauses w/nonnullable var on
262
- * right */
331
+ /*
332
+ * list of OuterJoinClauseInfos for mergejoinable full join clauses
333
+ */
334
+ List *full_join_clauses;
263
335
 
264
- List *full_join_clauses; /* list of RestrictInfos for mergejoinable
265
- * full join clauses */
336
+ /* list of SpecialJoinInfos */
337
+ List *join_info_list;
266
338
 
267
- List *join_info_list; /* list of SpecialJoinInfos */
339
+ /* counter for assigning RestrictInfo serial numbers */
340
+ int last_rinfo_serial;
268
341
 
269
342
  /*
270
343
  * all_result_relids is empty for SELECT, otherwise it contains at least
@@ -274,41 +347,99 @@ struct PlannerInfo
274
347
  * included. leaf_result_relids is similar except that only actual result
275
348
  * tables, not partitioned tables, are included in it.
276
349
  */
277
- Relids all_result_relids; /* set of all result relids */
278
- Relids leaf_result_relids; /* set of all leaf relids */
350
+ /* set of all result relids */
351
+ Relids all_result_relids;
352
+ /* set of all leaf relids */
353
+ Relids leaf_result_relids;
279
354
 
280
355
  /*
356
+ * list of AppendRelInfos
357
+ *
281
358
  * Note: for AppendRelInfos describing partitions of a partitioned table,
282
359
  * we guarantee that partitions that come earlier in the partitioned
283
360
  * table's PartitionDesc will appear earlier in append_rel_list.
284
361
  */
285
- List *append_rel_list; /* list of AppendRelInfos */
362
+ List *append_rel_list;
286
363
 
287
- List *row_identity_vars; /* list of RowIdentityVarInfos */
364
+ /* list of RowIdentityVarInfos */
365
+ List *row_identity_vars;
288
366
 
289
- List *rowMarks; /* list of PlanRowMarks */
367
+ /* list of PlanRowMarks */
368
+ List *rowMarks;
290
369
 
291
- List *placeholder_list; /* list of PlaceHolderInfos */
370
+ /* list of PlaceHolderInfos */
371
+ List *placeholder_list;
292
372
 
293
- List *fkey_list; /* list of ForeignKeyOptInfos */
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);
294
377
 
295
- List *query_pathkeys; /* desired pathkeys for query_planner() */
378
+ /* list of ForeignKeyOptInfos */
379
+ List *fkey_list;
380
+
381
+ /* desired pathkeys for query_planner() */
382
+ List *query_pathkeys;
383
+
384
+ /* groupClause pathkeys, if any */
385
+ List *group_pathkeys;
386
+
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;
296
393
 
297
- List *group_pathkeys; /* groupClause pathkeys, if any */
298
- List *window_pathkeys; /* pathkeys of bottom window, if any */
299
- List *distinct_pathkeys; /* distinctClause pathkeys, if any */
300
- List *sort_pathkeys; /* sortClause pathkeys, if any */
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;
301
400
 
302
- List *part_schemes; /* Canonicalised partition schemes used in the
303
- * query. */
401
+ /* Canonicalised partition schemes used in the query. */
402
+ List *part_schemes pg_node_attr(read_write_ignore);
304
403
 
305
- List *initial_rels; /* RelOptInfos we are now trying to join */
404
+ /* RelOptInfos we are now trying to join */
405
+ List *initial_rels pg_node_attr(read_write_ignore);
306
406
 
307
- /* Use fetch_upper_rel() to get any particular upper rel */
308
- List *upper_rels[UPPERREL_FINAL + 1]; /* upper-rel RelOptInfos */
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);
309
412
 
310
413
  /* Result tlists chosen by grouping_planner for upper-stage processing */
311
- 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;
312
443
 
313
444
  /*
314
445
  * The fully-processed targetlist is kept here. It differs from
@@ -329,52 +460,87 @@ struct PlannerInfo
329
460
  */
330
461
  List *update_colnos;
331
462
 
332
- /* Fields filled during create_plan() for use in setrefs.c */
333
- AttrNumber *grouping_map; /* for GroupingFunc fixup */
334
- List *minmax_aggs; /* List of MinMaxAggInfos */
335
-
336
- MemoryContext planner_cxt; /* context holding PlannerInfo */
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;
337
470
 
338
- Cardinality total_table_pages; /* # of pages in all non-dummy tables of
339
- * query */
471
+ /* context holding PlannerInfo */
472
+ MemoryContext planner_cxt pg_node_attr(read_write_ignore);
340
473
 
341
- Selectivity tuple_fraction; /* tuple_fraction passed to query_planner */
342
- Cardinality limit_tuples; /* limit_tuples passed to query_planner */
474
+ /* # of pages in all non-dummy tables of query */
475
+ Cardinality total_table_pages;
343
476
 
344
- Index qual_security_level; /* minimum security_level for quals */
345
- /* Note: qual_security_level is zero if there are no securityQuals */
477
+ /* tuple_fraction passed to query_planner */
478
+ Selectivity tuple_fraction;
479
+ /* limit_tuples passed to query_planner */
480
+ Cardinality limit_tuples;
346
481
 
347
- bool hasJoinRTEs; /* true if any RTEs are RTE_JOIN kind */
348
- bool hasLateralRTEs; /* true if any RTEs are marked LATERAL */
349
- bool hasHavingQual; /* true if havingQual was non-null */
350
- bool hasPseudoConstantQuals; /* true if any RestrictInfo has
351
- * pseudoconstant = true */
352
- bool hasAlternativeSubPlans; /* true if we've made any of those */
353
- bool hasRecursion; /* true if planning a recursive WITH item */
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;
354
502
 
355
503
  /*
356
504
  * Information about aggregates. Filled by preprocess_aggrefs().
357
505
  */
358
- List *agginfos; /* AggInfo structs */
359
- List *aggtransinfos; /* AggTransInfo structs */
360
- int numOrderedAggs; /* number w/ DISTINCT/ORDER BY/WITHIN GROUP */
361
- bool hasNonPartialAggs; /* does any agg not support partial mode? */
362
- bool hasNonSerialAggs; /* is any partial agg non-serializable? */
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;
363
516
 
364
- /* These fields are used only when hasRecursion is true: */
365
- int wt_param_id; /* PARAM_EXEC ID for the work table */
366
- struct Path *non_recursive_path; /* a path for non-recursive term */
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;
367
524
 
368
- /* These fields are workspace for createplan.c */
369
- Relids curOuterRels; /* outer rels above current node */
370
- List *curOuterParams; /* not-yet-assigned NestLoopParams */
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;
371
532
 
372
- /* These fields are workspace for setrefs.c */
373
- bool *isAltSubplan; /* array corresponding to glob->subplans */
374
- bool *isUsedSubplan; /* array corresponding to glob->subplans */
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);
375
541
 
376
542
  /* optional private data for join_search_hook, e.g., GEQO */
377
- void *join_search_private;
543
+ void *join_search_private pg_node_attr(read_write_ignore);
378
544
 
379
545
  /* Does this query modify any partition key columns? */
380
546
  bool partColsUpdated;
@@ -430,9 +596,10 @@ typedef struct PartitionSchemeData *PartitionScheme;
430
596
  * or the output of a sub-SELECT or function that appears in the range table.
431
597
  * In either case it is uniquely identified by an RT index. A "joinrel"
432
598
  * is the joining of two or more base rels. A joinrel is identified by
433
- * the set of RT indexes for its component baserels. We create RelOptInfo
434
- * nodes for each baserel and joinrel, and store them in the PlannerInfo's
435
- * 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.
436
603
  *
437
604
  * Note that there is only one joinrel for any given set of component
438
605
  * baserels, no matter what order we assemble them in; so an unordered
@@ -465,14 +632,13 @@ typedef struct PartitionSchemeData *PartitionScheme;
465
632
  * Many of the fields in these RelOptInfos are meaningless, but their Path
466
633
  * fields always hold Paths showing ways to do that processing step.
467
634
  *
468
- * Lastly, there is a RelOptKind for "dead" relations, which are base rels
469
- * that we have proven we don't need to join after all.
470
- *
471
635
  * Parts of this data structure are specific to various scan and join
472
636
  * mechanisms. It didn't seem worth creating new node types for them.
473
637
  *
474
- * relids - Set of base-relation identifiers; it is a base relation
475
- * 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
476
642
  * rows - estimated number of tuples in the relation after restriction
477
643
  * clauses have been applied (ie, output rows of a plan for it)
478
644
  * consider_startup - true if there is any value in keeping plain paths for
@@ -514,12 +680,13 @@ typedef struct PartitionSchemeData *PartitionScheme;
514
680
  * the attribute is needed as part of final targetlist
515
681
  * attr_widths - cache space for per-attribute width estimates;
516
682
  * zero means not computed yet
683
+ * nulling_relids - relids of outer joins that can null this rel
517
684
  * lateral_vars - lateral cross-references of rel, if any (list of
518
685
  * Vars and PlaceHolderVars)
519
686
  * lateral_referencers - relids of rels that reference this one laterally
520
687
  * (includes both direct and indirect lateral references)
521
688
  * indexlist - list of IndexOptInfo nodes for relation's indexes
522
- * (always NIL if it's not a table)
689
+ * (always NIL if it's not a table or partitioned table)
523
690
  * pages - number of disk pages in relation (zero if not a table)
524
691
  * tuples - number of tuples in relation (not considering restrictions)
525
692
  * allvisfrac - fraction of disk pages that are marked all-visible
@@ -631,6 +798,9 @@ typedef struct PartitionSchemeData *PartitionScheme;
631
798
  * Furthermore, FULL JOINs add extra nullable_partexprs expressions
632
799
  * corresponding to COALESCE expressions of the left and right join columns,
633
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.)
634
804
  *----------
635
805
  */
636
806
 
@@ -644,8 +814,7 @@ typedef enum RelOptKind
644
814
  RELOPT_OTHER_MEMBER_REL,
645
815
  RELOPT_OTHER_JOINREL,
646
816
  RELOPT_UPPER_REL,
647
- RELOPT_OTHER_UPPER_REL,
648
- RELOPT_DEADREL
817
+ RELOPT_OTHER_UPPER_REL
649
818
  } RelOptKind;
650
819
 
651
820
  /*
@@ -674,25 +843,43 @@ typedef enum RelOptKind
674
843
 
675
844
  typedef struct RelOptInfo
676
845
  {
846
+ pg_node_attr(no_copy_equal, no_read, no_query_jumble)
847
+
677
848
  NodeTag type;
678
849
 
679
850
  RelOptKind reloptkind;
680
851
 
681
- /* all relations included in this RelOptInfo */
682
- 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;
683
857
 
684
- /* size estimates generated by planner */
685
- Cardinality rows; /* estimated number of result tuples */
858
+ /*
859
+ * size estimates generated by planner
860
+ */
861
+ /* estimated number of result tuples */
862
+ Cardinality rows;
686
863
 
687
- /* per-relation planner control flags */
688
- bool consider_startup; /* keep cheap-startup-cost paths? */
689
- bool consider_param_startup; /* ditto, for parameterized paths? */
690
- 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;
691
873
 
692
- /* default result targetlist for Paths scanning this relation */
693
- 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;
694
879
 
695
- /* materialization information */
880
+ /*
881
+ * materialization information
882
+ */
696
883
  List *pathlist; /* Path structures */
697
884
  List *ppilist; /* ParamPathInfos used in pathlist */
698
885
  List *partial_pathlist; /* partial Paths */
@@ -701,79 +888,146 @@ typedef struct RelOptInfo
701
888
  struct Path *cheapest_unique_path;
702
889
  List *cheapest_parameterized_paths;
703
890
 
704
- /* parameterization information needed for both base rels and join rels */
705
- /* (see also lateral_vars and lateral_referencers) */
706
- Relids direct_lateral_relids; /* rels directly laterally referenced */
707
- 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;
708
899
 
709
- /* information about a base rel (not set for join rels!) */
900
+ /*
901
+ * information about a base rel (not set for join rels!)
902
+ */
710
903
  Index relid;
711
- Oid reltablespace; /* containing tablespace */
712
- RTEKind rtekind; /* RELATION, SUBQUERY, FUNCTION, etc */
713
- AttrNumber min_attr; /* smallest attrno of rel (often <0) */
714
- AttrNumber max_attr; /* largest attrno of rel */
715
- Relids *attr_needed; /* array indexed [min_attr .. max_attr] */
716
- int32 *attr_widths; /* array indexed [min_attr .. max_attr] */
717
- List *lateral_vars; /* LATERAL Vars and PHVs referenced by rel */
718
- Relids lateral_referencers; /* rels that reference me laterally */
719
- List *indexlist; /* list of IndexOptInfo */
720
- List *statlist; /* list of StatisticExtInfo */
721
- BlockNumber pages; /* size estimates derived from pg_class */
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;
722
928
  Cardinality tuples;
723
929
  double allvisfrac;
724
- Bitmapset *eclass_indexes; /* Indexes in PlannerInfo's eq_classes list of
725
- * ECs that mention this rel */
930
+ /* indexes in PlannerInfo's eq_classes list of ECs that mention this rel */
931
+ Bitmapset *eclass_indexes;
726
932
  PlannerInfo *subroot; /* if subquery */
727
933
  List *subplan_params; /* if subquery */
728
- int rel_parallel_workers; /* wanted number of parallel workers */
729
- uint32 amflags; /* Bitmask of optional features supported by
730
- * the table AM */
731
-
732
- /* Information about foreign tables and foreign joins */
733
- Oid serverid; /* identifies server for the table or join */
734
- Oid userid; /* identifies user to check access as */
735
- bool useridiscurrent; /* join is only valid for current user */
934
+ /* wanted number of parallel workers */
935
+ int rel_parallel_workers;
936
+ /* Bitmask of optional features supported by the table AM */
937
+ uint32 amflags;
938
+
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;
736
948
  /* use "struct FdwRoutine" to avoid including fdwapi.h here */
737
- struct FdwRoutine *fdwroutine;
738
- void *fdw_private;
739
-
740
- /* cache space for remembering if we have proven this relation unique */
741
- List *unique_for_rels; /* known unique for these other relid
742
- * set(s) */
743
- List *non_unique_for_rels; /* known not unique for these set(s) */
744
-
745
- /* used by various scans and joins: */
746
- List *baserestrictinfo; /* RestrictInfo structures (if base rel) */
747
- QualCost baserestrictcost; /* cost of evaluating the above */
748
- Index baserestrict_min_security; /* min security_level found in
749
- * baserestrictinfo */
750
- List *joininfo; /* RestrictInfo structures for join clauses
751
- * involving this rel */
752
- bool has_eclass_joins; /* T means joininfo is incomplete */
753
-
754
- /* used by partitionwise joins: */
755
- bool consider_partitionwise_join; /* consider partitionwise join
756
- * paths? (if partitioned rel) */
757
- Relids top_parent_relids; /* Relids of topmost parents (if "other"
758
- * rel) */
759
-
760
- /* used for partitioned relations: */
761
- PartitionScheme part_scheme; /* Partitioning scheme */
762
- int nparts; /* Number of partitions; -1 if not yet set; in
763
- * case of a join relation 0 means it's
764
- * considered unpartitioned */
765
- struct PartitionBoundInfoData *boundinfo; /* Partition bounds */
766
- bool partbounds_merged; /* True if partition bounds were created
767
- * by partition_bounds_merge() */
768
- List *partition_qual; /* Partition constraint, if not the root */
769
- struct RelOptInfo **part_rels; /* Array of RelOptInfos of partitions,
770
- * stored in the same order as bounds */
771
- Bitmapset *live_parts; /* Bitmap with members acting as indexes into
772
- * the part_rels[] array to indicate which
773
- * partitions survived partition pruning. */
774
- Relids all_partrels; /* Relids set of all partition relids */
775
- List **partexprs; /* Non-nullable partition key expressions */
776
- List **nullable_partexprs; /* Nullable partition key expressions */
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);
777
1031
  } RelOptInfo;
778
1032
 
779
1033
  /*
@@ -834,60 +1088,104 @@ typedef struct IndexOptInfo IndexOptInfo;
834
1088
 
835
1089
  struct IndexOptInfo
836
1090
  {
1091
+ pg_node_attr(no_copy_equal, no_read, no_query_jumble)
1092
+
837
1093
  NodeTag type;
838
1094
 
839
- Oid indexoid; /* OID of the index relation */
840
- Oid reltablespace; /* tablespace of index (not table) */
841
- RelOptInfo *rel; /* back-link to index's table */
842
-
843
- /* index-size statistics (from pg_class and elsewhere) */
844
- BlockNumber pages; /* number of disk pages in index */
845
- Cardinality tuples; /* number of index tuples in index */
846
- int tree_height; /* index tree height, or -1 if unknown */
847
-
848
- /* index descriptor information */
849
- int ncolumns; /* number of columns in index */
850
- int nkeycolumns; /* number of key columns in index */
851
- int *indexkeys; /* column numbers of index's attributes both
852
- * key and included columns, or 0 */
853
- Oid *indexcollations; /* OIDs of collations of index columns */
854
- Oid *opfamily; /* OIDs of operator families for columns */
855
- Oid *opcintype; /* OIDs of opclass declared input data types */
856
- Oid *sortopfamily; /* OIDs of btree opfamilies, if orderable */
857
- bool *reverse_sort; /* is sort order descending? */
858
- bool *nulls_first; /* do NULLs come first in the sort order? */
859
- bytea **opclassoptions; /* opclass-specific options for columns */
860
- bool *canreturn; /* which index cols can be returned in an
861
- * index-only scan? */
862
- Oid relam; /* OID of the access method (in pg_am) */
863
-
864
- List *indexprs; /* expressions for non-simple index columns */
865
- List *indpred; /* predicate if a partial index, else NIL */
866
-
867
- List *indextlist; /* targetlist representing index columns */
868
-
869
- List *indrestrictinfo; /* parent relation's baserestrictinfo
870
- * list, less any conditions implied by
871
- * the index's predicate (unless it's a
872
- * target rel, see comments in
873
- * check_index_predicates()) */
874
-
875
- bool predOK; /* true if index predicate matches query */
876
- bool unique; /* true if a unique index */
877
- bool immediate; /* is uniqueness enforced immediately? */
878
- bool hypothetical; /* true if index doesn't really exist */
879
-
880
- /* Remaining fields are copied from the index AM's API struct: */
881
- bool amcanorderbyop; /* does AM support order by operator result? */
882
- bool amoptionalkey; /* can query omit key for the first column? */
883
- bool amsearcharray; /* can AM handle ScalarArrayOpExpr quals? */
884
- bool amsearchnulls; /* can AM search for NULL/NOT NULL entries? */
885
- bool amhasgettuple; /* does AM have amgettuple interface? */
886
- bool amhasgetbitmap; /* does AM have amgetbitmap interface? */
887
- bool amcanparallel; /* does AM support parallel scan? */
888
- 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 */
889
1187
  /* Rather than include amapi.h here, we declare amcostestimate like this */
890
- void (*amcostestimate) (); /* AM's cost estimator */
1188
+ void (*amcostestimate) () pg_node_attr(read_write_ignore);
891
1189
  };
892
1190
 
893
1191
  /*
@@ -900,21 +1198,39 @@ struct IndexOptInfo
900
1198
  */
901
1199
  typedef struct ForeignKeyOptInfo
902
1200
  {
1201
+ pg_node_attr(custom_read_write, no_copy_equal, no_read, no_query_jumble)
1202
+
903
1203
  NodeTag type;
904
1204
 
905
- /* Basic data about the foreign key (fetched from catalogs): */
906
- Index con_relid; /* RT index of the referencing table */
907
- Index ref_relid; /* RT index of the referenced table */
908
- int nkeys; /* number of columns in the foreign key */
909
- AttrNumber conkey[INDEX_MAX_KEYS]; /* cols in referencing table */
910
- AttrNumber confkey[INDEX_MAX_KEYS]; /* cols in referenced table */
911
- Oid conpfeqop[INDEX_MAX_KEYS]; /* PK = FK operator OIDs */
912
-
913
- /* Derived info about whether FK's equality conditions match the query: */
914
- int nmatched_ec; /* # of FK cols matched by ECs */
915
- int nconst_ec; /* # of these ECs that are ec_has_const */
916
- int nmatched_rcols; /* # of FK cols matched by non-EC rinfos */
917
- 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;
918
1234
  /* Pointer to eclass matching each column's condition, if there is one */
919
1235
  struct EquivalenceClass *eclass[INDEX_MAX_KEYS];
920
1236
  /* Pointer to eclass member for the referencing Var, if there is one */
@@ -932,21 +1248,69 @@ typedef struct ForeignKeyOptInfo
932
1248
  */
933
1249
  typedef struct StatisticExtInfo
934
1250
  {
1251
+ pg_node_attr(no_copy_equal, no_read, no_query_jumble)
1252
+
935
1253
  NodeTag type;
936
1254
 
937
- Oid statOid; /* OID of the statistics row */
938
- bool inherit; /* includes child relations */
939
- RelOptInfo *rel; /* back-link to statistic's table */
940
- char kind; /* statistics kind of this entry */
941
- Bitmapset *keys; /* attnums of the columns covered */
942
- List *exprs; /* expressions */
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;
943
1272
  } StatisticExtInfo;
944
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
+
945
1309
  /*
946
1310
  * EquivalenceClasses
947
1311
  *
948
- * Whenever we can determine that a mergejoinable equality clause A = B is
949
- * 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
950
1314
  * the expressions A and B to record this knowledge. If we later find another
951
1315
  * equivalence B = C, we add C to the existing EquivalenceClass; this may
952
1316
  * require merging two existing EquivalenceClasses. At the end of the qual
@@ -960,6 +1324,18 @@ typedef struct StatisticExtInfo
960
1324
  * that all or none of the input datatypes are collatable, so that a single
961
1325
  * collation value is sufficient.)
962
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
+ *
963
1339
  * We also use EquivalenceClasses as the base structure for PathKeys, letting
964
1340
  * us represent knowledge about different sort orderings being equivalent.
965
1341
  * Since every PathKey must reference an EquivalenceClass, we will end up
@@ -974,16 +1350,19 @@ typedef struct StatisticExtInfo
974
1350
  * entry: consider SELECT random() AS a, random() AS b ... ORDER BY b,a.
975
1351
  * So we record the SortGroupRef of the originating sort clause.
976
1352
  *
977
- * We allow equality clauses appearing below the nullable side of an outer join
978
- * to form EquivalenceClasses, but these have a slightly different meaning:
979
- * the included values might be all NULL rather than all the same non-null
980
- * values. See src/backend/optimizer/README for more on that point.
981
- *
982
1353
  * NB: if ec_merged isn't NULL, this class has been merged into another, and
983
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.
984
1361
  */
985
1362
  typedef struct EquivalenceClass
986
1363
  {
1364
+ pg_node_attr(custom_read_write, no_copy_equal, no_read, no_query_jumble)
1365
+
987
1366
  NodeTag type;
988
1367
 
989
1368
  List *ec_opfamilies; /* btree operator family OIDs */
@@ -995,7 +1374,6 @@ typedef struct EquivalenceClass
995
1374
  * for child members (see below) */
996
1375
  bool ec_has_const; /* any pseudoconstants in ec_members? */
997
1376
  bool ec_has_volatile; /* the (sole) member is a volatile expr */
998
- bool ec_below_outer_join; /* equivalence applies below an OJ */
999
1377
  bool ec_broken; /* failed to generate needed clauses? */
1000
1378
  Index ec_sortref; /* originating sortclause label, or 0 */
1001
1379
  Index ec_min_security; /* minimum security_level in ec_sources */
@@ -1004,11 +1382,11 @@ typedef struct EquivalenceClass
1004
1382
  } EquivalenceClass;
1005
1383
 
1006
1384
  /*
1007
- * If an EC contains a const and isn't below-outer-join, any PathKey depending
1008
- * 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.
1009
1387
  */
1010
1388
  #define EC_MUST_BE_REDUNDANT(eclass) \
1011
- ((eclass)->ec_has_const && !(eclass)->ec_below_outer_join)
1389
+ ((eclass)->ec_has_const)
1012
1390
 
1013
1391
  /*
1014
1392
  * EquivalenceMember - one member expression of an EquivalenceClass
@@ -1034,14 +1412,18 @@ typedef struct EquivalenceClass
1034
1412
  */
1035
1413
  typedef struct EquivalenceMember
1036
1414
  {
1415
+ pg_node_attr(no_copy_equal, no_read, no_query_jumble)
1416
+
1037
1417
  NodeTag type;
1038
1418
 
1039
1419
  Expr *em_expr; /* the expression represented */
1040
1420
  Relids em_relids; /* all relids appearing in em_expr */
1041
- Relids em_nullable_relids; /* nullable by lower outer joins */
1042
1421
  bool em_is_const; /* expression is pseudoconstant? */
1043
1422
  bool em_is_child; /* derived version for a child relation? */
1044
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);
1045
1427
  } EquivalenceMember;
1046
1428
 
1047
1429
  /*
@@ -1063,9 +1445,12 @@ typedef struct EquivalenceMember
1063
1445
  */
1064
1446
  typedef struct PathKey
1065
1447
  {
1448
+ pg_node_attr(no_read, no_query_jumble)
1449
+
1066
1450
  NodeTag type;
1067
1451
 
1068
- 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);
1069
1454
  Oid pk_opfamily; /* btree opfamily defining the ordering */
1070
1455
  int pk_strategy; /* sort direction (ASC or DESC) */
1071
1456
  bool pk_nulls_first; /* do NULLs come before normal values? */
@@ -1108,13 +1493,24 @@ typedef enum VolatileFunctionStatus
1108
1493
  */
1109
1494
  typedef struct PathTarget
1110
1495
  {
1496
+ pg_node_attr(no_copy_equal, no_read, no_query_jumble)
1497
+
1111
1498
  NodeTag type;
1112
- List *exprs; /* list of expressions to be computed */
1113
- Index *sortgrouprefs; /* corresponding sort/group refnos, or 0 */
1114
- QualCost cost; /* cost of evaluating the expressions */
1115
- int width; /* estimated avg width of result tuples */
1116
- VolatileFunctionStatus has_volatile_expr; /* indicates if exprs contain
1117
- * any volatile functions. */
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;
1118
1514
  } PathTarget;
1119
1515
 
1120
1516
  /* Convenience macro to get a sort/group refno from a PathTarget */
@@ -1134,15 +1530,24 @@ typedef struct PathTarget
1134
1530
  * Note: ppi_clauses is only used in ParamPathInfos for base relation paths;
1135
1531
  * in join cases it's NIL because the set of relevant clauses varies depending
1136
1532
  * on how the join is formed. The relevant clauses will appear in each
1137
- * 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.)
1138
1540
  */
1139
1541
  typedef struct ParamPathInfo
1140
1542
  {
1543
+ pg_node_attr(no_copy_equal, no_read, no_query_jumble)
1544
+
1141
1545
  NodeTag type;
1142
1546
 
1143
1547
  Relids ppi_req_outer; /* rels supplying parameters used by path */
1144
1548
  Cardinality ppi_rows; /* estimated number of result tuples */
1145
1549
  List *ppi_clauses; /* join clauses available from outer rels */
1550
+ Bitmapset *ppi_serials; /* set of rinfo_serial for enforced quals */
1146
1551
  } ParamPathInfo;
1147
1552
 
1148
1553
 
@@ -1174,29 +1579,58 @@ typedef struct ParamPathInfo
1174
1579
  *
1175
1580
  * "pathkeys" is a List of PathKey nodes (see above), describing the sort
1176
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.
1177
1586
  */
1178
1587
  typedef struct Path
1179
1588
  {
1589
+ pg_node_attr(no_copy_equal, no_read, no_query_jumble)
1590
+
1180
1591
  NodeTag type;
1181
1592
 
1182
- NodeTag pathtype; /* tag identifying scan/join method */
1593
+ /* tag identifying scan/join method */
1594
+ NodeTag pathtype;
1595
+
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);
1183
1603
 
1184
- RelOptInfo *parent; /* the relation this path can build */
1185
- PathTarget *pathtarget; /* list of Vars/Exprs, cost, width */
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);
1186
1610
 
1187
- ParamPathInfo *param_info; /* parameterization info, or NULL if none */
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);
1188
1619
 
1189
- bool parallel_aware; /* engage parallel-aware logic? */
1190
- bool parallel_safe; /* OK to use as part of parallel plan? */
1191
- int parallel_workers; /* desired # of workers; 0 = not parallel */
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;
1192
1626
 
1193
1627
  /* estimated size/costs for path (see costsize.c for more info) */
1194
1628
  Cardinality rows; /* estimated number of result tuples */
1195
1629
  Cost startup_cost; /* cost expended before fetching any tuples */
1196
1630
  Cost total_cost; /* total cost (assuming all tuples fetched) */
1197
1631
 
1198
- List *pathkeys; /* sort ordering of path's output */
1199
- /* 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;
1200
1634
  } Path;
1201
1635
 
1202
1636
  /* Macro for extracting a path's parameterization relids; beware double eval */
@@ -1228,12 +1662,9 @@ typedef struct Path
1228
1662
  * on which index column each ORDER BY can be used with.)
1229
1663
  *
1230
1664
  * 'indexscandir' is one of:
1231
- * ForwardScanDirection: forward scan of an ordered index
1665
+ * ForwardScanDirection: forward scan of an index
1232
1666
  * BackwardScanDirection: backward scan of an ordered index
1233
- * NoMovementScanDirection: scan of an unordered index, or don't care
1234
- * (The executor doesn't care whether it gets ForwardScanDirection or
1235
- * NoMovementScanDirection for an indexscan, but the planner wants to
1236
- * distinguish ordered from unordered indexes for building pathkeys.)
1667
+ * Unordered indexes will always have an indexscandir of ForwardScanDirection.
1237
1668
  *
1238
1669
  * 'indextotalcost' and 'indexselectivity' are saved in the IndexPath so that
1239
1670
  * we need not recompute them when considering using the same index in a
@@ -1289,6 +1720,8 @@ typedef struct IndexPath
1289
1720
  */
1290
1721
  typedef struct IndexClause
1291
1722
  {
1723
+ pg_node_attr(no_copy_equal, no_read, no_query_jumble)
1724
+
1292
1725
  NodeTag type;
1293
1726
  struct RestrictInfo *rinfo; /* original restriction or join clause */
1294
1727
  List *indexquals; /* indexqual(s) derived from it */
@@ -1403,15 +1836,18 @@ typedef struct ForeignPath
1403
1836
  } ForeignPath;
1404
1837
 
1405
1838
  /*
1406
- * 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.
1407
1841
  *
1408
1842
  * We provide a set of hooks here - which the provider must take care to set
1409
1843
  * up correctly - to allow extensions to supply their own methods of scanning
1410
- * a relation. For example, a provider might provide GPU acceleration, a
1411
- * 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.
1412
1847
  *
1413
- * CustomPaths can be injected into the planning process for a relation by
1414
- * 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.
1415
1851
  *
1416
1852
  * Core code must avoid assuming that the CustomPath is only as large as
1417
1853
  * the structure declared here; providers are allowed to make it the first
@@ -1513,8 +1949,8 @@ typedef struct MemoizePath
1513
1949
  {
1514
1950
  Path path;
1515
1951
  Path *subpath; /* outerpath to cache tuples from */
1516
- List *hash_operators; /* hash operators for each key */
1517
- List *param_exprs; /* cache keys */
1952
+ List *hash_operators; /* OIDs of hash equality ops for cache keys */
1953
+ List *param_exprs; /* expressions that are cache keys */
1518
1954
  bool singlerow; /* true if the cache entry is to be marked as
1519
1955
  * complete after caching the first record. */
1520
1956
  bool binary_mode; /* true when cache key should be compared bit
@@ -1584,6 +2020,8 @@ typedef struct GatherMergePath
1584
2020
 
1585
2021
  typedef struct JoinPath
1586
2022
  {
2023
+ pg_node_attr(abstract)
2024
+
1587
2025
  Path path;
1588
2026
 
1589
2027
  JoinType jointype;
@@ -1786,6 +2224,8 @@ typedef struct AggPath
1786
2224
 
1787
2225
  typedef struct GroupingSetData
1788
2226
  {
2227
+ pg_node_attr(no_copy_equal, no_read, no_query_jumble)
2228
+
1789
2229
  NodeTag type;
1790
2230
  List *set; /* grouping set as list of sortgrouprefs */
1791
2231
  Cardinality numGroups; /* est. number of result groups */
@@ -1793,6 +2233,8 @@ typedef struct GroupingSetData
1793
2233
 
1794
2234
  typedef struct RollupData
1795
2235
  {
2236
+ pg_node_attr(no_copy_equal, no_read, no_query_jumble)
2237
+
1796
2238
  NodeTag type;
1797
2239
  List *groupClause; /* applicable subset of parse->groupClause */
1798
2240
  List *gsets; /* lists of integer indexes into groupClause */
@@ -1892,7 +2334,7 @@ typedef struct ModifyTablePath
1892
2334
  CmdType operation; /* INSERT, UPDATE, DELETE, or MERGE */
1893
2335
  bool canSetTag; /* do we set the command tag/es_processed? */
1894
2336
  Index nominalRelation; /* Parent RT index for use of EXPLAIN */
1895
- Index rootRelation; /* Root RT index, if target is partitioned */
2337
+ Index rootRelation; /* Root RT index, if partitioned/inherited */
1896
2338
  bool partColsUpdated; /* some part key in hierarchy updated? */
1897
2339
  List *resultRelations; /* integer list of RT indexes */
1898
2340
  List *updateColnosLists; /* per-target-table update_colnos lists */
@@ -1930,17 +2372,17 @@ typedef struct LimitPath
1930
2372
  * If a restriction clause references a single base relation, it will appear
1931
2373
  * in the baserestrictinfo list of the RelOptInfo for that base rel.
1932
2374
  *
1933
- * 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
1934
2376
  * appear in the joininfo list of every RelOptInfo that describes a strict
1935
- * 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
1936
2378
  * used to drive join tree building by selecting plausible join candidates.
1937
2379
  * The clause cannot actually be applied until we have built a join rel
1938
- * containing all the base rels it references, however.
2380
+ * containing all the relations it references, however.
1939
2381
  *
1940
- * 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
1941
2383
  * in a multi-relation restriction clause, we place that clause into the
1942
2384
  * joinrestrictinfo lists of paths for the join rel, if neither left nor
1943
- * 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
1944
2386
  * will be applied at that join level, and will not propagate any further up
1945
2387
  * the join tree. (Note: the "predicate migration" code was once intended to
1946
2388
  * push restriction clauses up and down the plan tree based on evaluation
@@ -1961,12 +2403,14 @@ typedef struct LimitPath
1961
2403
  * or join to enforce that all members of each EquivalenceClass are in fact
1962
2404
  * equal in all rows emitted by the scan or join.
1963
2405
  *
1964
- * When dealing with outer joins we have to be very careful about pushing qual
1965
- * clauses up and down the tree. An outer join's own JOIN/ON conditions must
1966
- * be evaluated exactly at that join node, unless they are "degenerate"
1967
- * conditions that reference only Vars from the nullable side of the join.
1968
- * Quals appearing in WHERE or in a JOIN above the outer join cannot be pushed
1969
- * 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
+ *
1970
2414
  * RestrictInfo nodes contain a flag to indicate whether a qual has been
1971
2415
  * pushed down to a lower level than its original syntactic placement in the
1972
2416
  * join tree would suggest. If an outer join prevents us from pushing a qual
@@ -1989,10 +2433,14 @@ typedef struct LimitPath
1989
2433
  * conditions. Possibly we should rename it to reflect that meaning? But
1990
2434
  * see also the comments for RINFO_IS_PUSHED_DOWN, below.)
1991
2435
  *
1992
- * RestrictInfo nodes also contain an outerjoin_delayed flag, which is true
1993
- * if the clause's applicability must be delayed due to any outer joins
1994
- * appearing below it (ie, it has to be postponed to some join level higher
1995
- * 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.
1996
2444
  *
1997
2445
  * There is also an outer_relids field, which is NULL except for outer join
1998
2446
  * clauses; for those, it is the set of relids on the outer side of the
@@ -2000,15 +2448,6 @@ typedef struct LimitPath
2000
2448
  * in parameterized scans, since pushing it into the join's outer side would
2001
2449
  * lead to wrong answers.)
2002
2450
  *
2003
- * There is also a nullable_relids field, which is the set of rels the clause
2004
- * references that can be forced null by some outer join below the clause.
2005
- *
2006
- * outerjoin_delayed = true is subtly different from nullable_relids != NULL:
2007
- * a clause might reference some nullable rels and yet not be
2008
- * outerjoin_delayed because it also references all the other rels of the
2009
- * outer join(s). A clause that is not outerjoin_delayed can be enforced
2010
- * anywhere it is computable.
2011
- *
2012
2451
  * To handle security-barrier conditions efficiently, we mark RestrictInfo
2013
2452
  * nodes with a security_level field, in which higher values identify clauses
2014
2453
  * coming from less-trusted sources. The exact semantics are that a clause
@@ -2051,89 +2490,174 @@ typedef struct LimitPath
2051
2490
  * or merge or hash join clause, so it's of no interest to large parts of
2052
2491
  * the planner.
2053
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
+ *
2054
2499
  * When join clauses are generated from EquivalenceClasses, there may be
2055
2500
  * several equally valid ways to enforce join equivalence, of which we need
2056
2501
  * apply only one. We mark clauses of this kind by setting parent_ec to
2057
2502
  * point to the generating EquivalenceClass. Multiple clauses with the same
2058
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.
2059
2510
  */
2060
2511
 
2061
2512
  typedef struct RestrictInfo
2062
2513
  {
2514
+ pg_node_attr(no_read, no_query_jumble)
2515
+
2063
2516
  NodeTag type;
2064
2517
 
2065
- Expr *clause; /* the represented clause of WHERE or JOIN */
2518
+ /* the represented clause of WHERE or JOIN */
2519
+ Expr *clause;
2066
2520
 
2067
- 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;
2068
2523
 
2069
- bool outerjoin_delayed; /* true if delayed by lower outer join */
2524
+ /* see comment above */
2525
+ bool can_join pg_node_attr(equal_ignore);
2070
2526
 
2071
- bool can_join; /* see comment above */
2527
+ /* see comment above */
2528
+ bool pseudoconstant pg_node_attr(equal_ignore);
2072
2529
 
2073
- bool pseudoconstant; /* see comment above */
2530
+ /* see comment above */
2531
+ bool has_clone;
2532
+ bool is_clone;
2074
2533
 
2075
- 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);
2076
2536
 
2077
- VolatileFunctionStatus has_volatile; /* to indicate if clause contains
2078
- * any volatile functions. */
2537
+ /* indicates if clause contains any volatile functions */
2538
+ VolatileFunctionStatus has_volatile pg_node_attr(equal_ignore);
2079
2539
 
2080
- Index security_level; /* see comment above */
2540
+ /* see comment above */
2541
+ Index security_level;
2081
2542
 
2082
- /* The set of relids (varnos) actually referenced in the clause: */
2083
- Relids clause_relids;
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);
2084
2548
 
2085
2549
  /* The set of relids required to evaluate the clause: */
2086
2550
  Relids required_relids;
2087
2551
 
2552
+ /* Relids above which we cannot evaluate the clause (see comment above) */
2553
+ Relids incompatible_relids;
2554
+
2088
2555
  /* If an outer-join clause, the outer-side relations, else NULL: */
2089
2556
  Relids outer_relids;
2090
2557
 
2091
- /* The relids used in the clause that are nullable by lower outer joins: */
2092
- 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);
2564
+
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;
2589
+
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);
2595
+
2596
+ /*
2597
+ * cache space for cost and selectivity
2598
+ */
2093
2599
 
2094
- /* These fields are set for any binary opclause: */
2095
- Relids left_relids; /* relids in left side of clause */
2096
- Relids right_relids; /* relids in right side of clause */
2600
+ /* eval cost of clause; -1 if not yet set */
2601
+ QualCost eval_cost pg_node_attr(equal_ignore);
2097
2602
 
2098
- /* This field is NULL unless clause is an OR clause: */
2099
- Expr *orclause; /* modified clause with RestrictInfos */
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);
2100
2607
 
2101
- /* This field is NULL unless clause is potentially redundant: */
2102
- EquivalenceClass *parent_ec; /* generating EquivalenceClass */
2608
+ /*
2609
+ * opfamilies containing clause operator; valid if clause is
2610
+ * mergejoinable, else NIL
2611
+ */
2612
+ List *mergeopfamilies pg_node_attr(equal_ignore);
2103
2613
 
2104
- /* cache space for cost and selectivity */
2105
- QualCost eval_cost; /* eval cost of clause; -1 if not yet set */
2106
- Selectivity norm_selec; /* selectivity for "normal" (JOIN_INNER)
2107
- * semantics; -1 if not yet set; >1 means a
2108
- * redundant clause */
2109
- Selectivity outer_selec; /* selectivity for outer join semantics; -1 if
2110
- * not yet set */
2614
+ /*
2615
+ * cache space for mergeclause processing; NULL if not yet set
2616
+ */
2111
2617
 
2112
- /* valid if clause is mergejoinable, else NIL */
2113
- List *mergeopfamilies; /* opfamilies containing clause operator */
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);
2114
2626
 
2115
- /* cache space for mergeclause processing; NULL if not yet set */
2116
- EquivalenceClass *left_ec; /* EquivalenceClass containing lefthand */
2117
- EquivalenceClass *right_ec; /* EquivalenceClass containing righthand */
2118
- EquivalenceMember *left_em; /* EquivalenceMember for lefthand */
2119
- EquivalenceMember *right_em; /* EquivalenceMember for righthand */
2120
- List *scansel_cache; /* list of MergeScanSelCache structs */
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);
2121
2633
 
2122
- /* transient workspace for use while considering a specific join path */
2123
- bool outer_is_left; /* T = outer var on left, F = on right */
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);
2124
2639
 
2125
- /* valid if clause is hashjoinable, else InvalidOid: */
2126
- Oid hashjoinoperator; /* copy of clause operator */
2640
+ /*
2641
+ * copy of clause operator; valid if clause is hashjoinable, else
2642
+ * InvalidOid
2643
+ */
2644
+ Oid hashjoinoperator pg_node_attr(equal_ignore);
2127
2645
 
2128
- /* cache space for hashclause processing; -1 if not yet set */
2129
- Selectivity left_bucketsize; /* avg bucketsize of left side */
2130
- Selectivity right_bucketsize; /* avg bucketsize of right side */
2131
- Selectivity left_mcvfreq; /* left side's most common val's freq */
2132
- Selectivity right_mcvfreq; /* right side's most common val's freq */
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);
2133
2657
 
2134
2658
  /* hash equality operators used for memoize nodes, else InvalidOid */
2135
- Oid left_hasheqoperator;
2136
- Oid right_hasheqoperator;
2659
+ Oid left_hasheqoperator pg_node_attr(equal_ignore);
2660
+ Oid right_hasheqoperator pg_node_attr(equal_ignore);
2137
2661
  } RestrictInfo;
2138
2662
 
2139
2663
  /*
@@ -2176,22 +2700,53 @@ typedef struct MergeScanSelCache
2176
2700
  * of a plan tree. This is used during planning to represent the contained
2177
2701
  * expression. At the end of the planning process it is replaced by either
2178
2702
  * the contained expression or a Var referring to a lower-level evaluation of
2179
- * the contained expression. Typically the evaluation occurs below an outer
2703
+ * the contained expression. Generally the evaluation occurs below an outer
2180
2704
  * join, and Var references above the outer join might thereby yield NULL
2181
2705
  * instead of the expression value.
2182
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
+ *
2183
2712
  * Although the planner treats this as an expression node type, it is not
2184
2713
  * recognized by the parser or executor, so we declare it here rather than
2185
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.
2186
2728
  */
2187
2729
 
2188
2730
  typedef struct PlaceHolderVar
2189
2731
  {
2732
+ pg_node_attr(no_query_jumble)
2733
+
2190
2734
  Expr xpr;
2191
- Expr *phexpr; /* the represented expression */
2192
- Relids phrels; /* base relids syntactically within expr src */
2193
- Index phid; /* ID for PHV (unique within planner run) */
2194
- 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;
2195
2750
  } PlaceHolderVar;
2196
2751
 
2197
2752
  /*
@@ -2210,25 +2765,53 @@ typedef struct PlaceHolderVar
2210
2765
  * We make SpecialJoinInfos for FULL JOINs even though there is no flexibility
2211
2766
  * of planning for them, because this simplifies make_join_rel()'s API.
2212
2767
  *
2213
- * min_lefthand and min_righthand are the sets of base relids that must be
2214
- * available on each side when performing the special join. lhs_strict is
2215
- * true if the special join's condition cannot succeed when the LHS variables
2216
- * are all NULL (this means that an outer join can commute with upper-level
2217
- * outer joins even if it appears in their RHS). We don't bother to set
2218
- * lhs_strict for FULL JOINs, however.
2219
- *
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.
2220
2770
  * It is not valid for either min_lefthand or min_righthand to be empty sets;
2221
2771
  * if they were, this would break the logic that enforces join order.
2222
2772
  *
2223
- * 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
2224
2774
  * syntactically below this special join. (These are needed to help compute
2225
2775
  * min_lefthand and min_righthand for higher joins.)
2226
2776
  *
2227
- * delay_upper_joins is set true if we detect a pushed-down clause that has
2228
- * to be evaluated after this join is formed (because it references the RHS).
2229
- * Any outer joins that have such a clause and this join in their RHS cannot
2230
- * commute with this join, because that would leave noplace to check the
2231
- * 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.
2232
2815
  *
2233
2816
  * For a semijoin, we also extract the join operators and their RHS arguments
2234
2817
  * and set semi_operators, semi_rhs_exprs, semi_can_btree, and semi_can_hash.
@@ -2238,18 +2821,14 @@ typedef struct PlaceHolderVar
2238
2821
  * join planning; but it's helpful to have it available during planning of
2239
2822
  * parameterized table scans, so we store it in the SpecialJoinInfo structs.)
2240
2823
  *
2241
- * jointype is never JOIN_RIGHT; a RIGHT JOIN is handled by switching
2242
- * the inputs to make it a LEFT JOIN. So the allowed values of jointype
2243
- * in a join_info_list member are only LEFT, FULL, SEMI, or ANTI.
2244
- *
2245
2824
  * For purposes of join selectivity estimation, we create transient
2246
2825
  * SpecialJoinInfo structures for regular inner joins; so it is possible
2247
2826
  * to have jointype == JOIN_INNER in such a structure, even though this is
2248
2827
  * not allowed within join_info_list. We also create transient
2249
2828
  * SpecialJoinInfos with jointype == JOIN_INNER for outer joins, since for
2250
2829
  * cost estimation purposes it is sometimes useful to know the join size under
2251
- * plain innerjoin semantics. Note that lhs_strict, delay_upper_joins, and
2252
- * 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.
2253
2832
  */
2254
2833
  #ifndef HAVE_SPECIALJOININFO_TYPEDEF
2255
2834
  typedef struct SpecialJoinInfo SpecialJoinInfo;
@@ -2258,14 +2837,20 @@ typedef struct SpecialJoinInfo SpecialJoinInfo;
2258
2837
 
2259
2838
  struct SpecialJoinInfo
2260
2839
  {
2840
+ pg_node_attr(no_read, no_query_jumble)
2841
+
2261
2842
  NodeTag type;
2262
- Relids min_lefthand; /* base relids in minimum LHS for join */
2263
- Relids min_righthand; /* base relids in minimum RHS for join */
2264
- Relids syn_lefthand; /* base relids syntactically within LHS */
2265
- 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 */
2266
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 */
2267
2853
  bool lhs_strict; /* joinclause is strict for some LHS rel */
2268
- bool delay_upper_joins; /* can't commute with upper RHS */
2269
2854
  /* Remaining fields are set only for JOIN_SEMI jointype: */
2270
2855
  bool semi_can_btree; /* true if semi_operators are all btree */
2271
2856
  bool semi_can_hash; /* true if semi_operators are all hash */
@@ -2273,6 +2858,21 @@ struct SpecialJoinInfo
2273
2858
  List *semi_rhs_exprs; /* righthand-side expressions of these ops */
2274
2859
  };
2275
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
+
2276
2876
  /*
2277
2877
  * Append-relation info.
2278
2878
  *
@@ -2305,6 +2905,8 @@ struct SpecialJoinInfo
2305
2905
 
2306
2906
  typedef struct AppendRelInfo
2307
2907
  {
2908
+ pg_node_attr(no_query_jumble)
2909
+
2308
2910
  NodeTag type;
2309
2911
 
2310
2912
  /*
@@ -2350,7 +2952,7 @@ typedef struct AppendRelInfo
2350
2952
  * child column is dropped or doesn't exist in the parent.
2351
2953
  */
2352
2954
  int num_child_cols; /* length of array */
2353
- AttrNumber *parent_colnos; /* array of parent attnos, or zeroes */
2955
+ AttrNumber *parent_colnos pg_node_attr(array_size(num_child_cols));
2354
2956
 
2355
2957
  /*
2356
2958
  * We store the parent table's OID here for inheritance, or InvalidOid for
@@ -2380,6 +2982,8 @@ typedef struct AppendRelInfo
2380
2982
  */
2381
2983
  typedef struct RowIdentityVarInfo
2382
2984
  {
2985
+ pg_node_attr(no_copy_equal, no_read, no_query_jumble)
2986
+
2383
2987
  NodeTag type;
2384
2988
 
2385
2989
  Var *rowidvar; /* Var to be evaluated (but varno=ROWID_VAR) */
@@ -2416,14 +3020,30 @@ typedef struct RowIdentityVarInfo
2416
3020
 
2417
3021
  typedef struct PlaceHolderInfo
2418
3022
  {
3023
+ pg_node_attr(no_read, no_query_jumble)
3024
+
2419
3025
  NodeTag type;
2420
3026
 
2421
- Index phid; /* ID for PH (unique within planner run) */
2422
- PlaceHolderVar *ph_var; /* copy of PlaceHolderVar tree */
2423
- Relids ph_eval_at; /* lowest level we can evaluate value at */
2424
- Relids ph_lateral; /* relids of contained lateral refs, if any */
2425
- Relids ph_needed; /* highest level the value is needed at */
2426
- 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;
2427
3047
  } PlaceHolderInfo;
2428
3048
 
2429
3049
  /*
@@ -2433,15 +3053,33 @@ typedef struct PlaceHolderInfo
2433
3053
  */
2434
3054
  typedef struct MinMaxAggInfo
2435
3055
  {
3056
+ pg_node_attr(no_copy_equal, no_read, no_query_jumble)
3057
+
2436
3058
  NodeTag type;
2437
3059
 
2438
- Oid aggfnoid; /* pg_proc Oid of the aggregate */
2439
- Oid aggsortop; /* Oid of its sort operator */
2440
- Expr *target; /* expression we are aggregating on */
2441
- PlannerInfo *subroot; /* modified "root" for planning the subquery */
2442
- Path *path; /* access path for subquery */
2443
- Cost pathcost; /* estimated cost to fetch first row */
2444
- 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;
2445
3083
  } MinMaxAggInfo;
2446
3084
 
2447
3085
  /*
@@ -2493,6 +3131,8 @@ typedef struct MinMaxAggInfo
2493
3131
  */
2494
3132
  typedef struct PlannerParamItem
2495
3133
  {
3134
+ pg_node_attr(no_copy_equal, no_read, no_query_jumble)
3135
+
2496
3136
  NodeTag type;
2497
3137
 
2498
3138
  Node *item; /* the Var, PlaceHolderVar, or Aggref */
@@ -2671,14 +3311,19 @@ typedef struct JoinCostWorkspace
2671
3311
  */
2672
3312
  typedef struct AggInfo
2673
3313
  {
3314
+ pg_node_attr(no_copy_equal, no_read, no_query_jumble)
3315
+
3316
+ NodeTag type;
3317
+
2674
3318
  /*
2675
- * Link to an Aggref expr this state value is for.
3319
+ * List of Aggref exprs that this state value is for.
2676
3320
  *
2677
- * There can be multiple identical Aggref's sharing the same per-agg. This
2678
- * points to the first one of them.
3321
+ * There will always be at least one, but there can be multiple identical
3322
+ * Aggref's sharing the same per-agg.
2679
3323
  */
2680
- Aggref *representative_aggref;
3324
+ List *aggrefs;
2681
3325
 
3326
+ /* Transition state number for this aggregate */
2682
3327
  int transno;
2683
3328
 
2684
3329
  /*
@@ -2687,9 +3332,8 @@ typedef struct AggInfo
2687
3332
  */
2688
3333
  bool shareable;
2689
3334
 
2690
- /* Oid of the final function or InvalidOid */
3335
+ /* Oid of the final function, or InvalidOid if none */
2691
3336
  Oid finalfn_oid;
2692
-
2693
3337
  } AggInfo;
2694
3338
 
2695
3339
  /*
@@ -2701,34 +3345,40 @@ typedef struct AggInfo
2701
3345
  */
2702
3346
  typedef struct AggTransInfo
2703
3347
  {
3348
+ pg_node_attr(no_copy_equal, no_read, no_query_jumble)
3349
+
3350
+ NodeTag type;
3351
+
3352
+ /* Inputs for this transition state */
2704
3353
  List *args;
2705
3354
  Expr *aggfilter;
2706
3355
 
2707
3356
  /* Oid of the state transition function */
2708
3357
  Oid transfn_oid;
2709
3358
 
2710
- /* Oid of the serialization function or InvalidOid */
3359
+ /* Oid of the serialization function, or InvalidOid if none */
2711
3360
  Oid serialfn_oid;
2712
3361
 
2713
- /* Oid of the deserialization function or InvalidOid */
3362
+ /* Oid of the deserialization function, or InvalidOid if none */
2714
3363
  Oid deserialfn_oid;
2715
3364
 
2716
- /* Oid of the combine function or InvalidOid */
3365
+ /* Oid of the combine function, or InvalidOid if none */
2717
3366
  Oid combinefn_oid;
2718
3367
 
2719
3368
  /* Oid of state value's datatype */
2720
3369
  Oid aggtranstype;
3370
+
3371
+ /* Additional data about transtype */
2721
3372
  int32 aggtranstypmod;
2722
3373
  int transtypeLen;
2723
3374
  bool transtypeByVal;
3375
+
3376
+ /* Space-consumption estimate */
2724
3377
  int32 aggtransspace;
2725
3378
 
2726
- /*
2727
- * initial value from pg_aggregate entry
2728
- */
2729
- Datum initValue;
3379
+ /* Initial value from pg_aggregate entry */
3380
+ Datum initValue pg_node_attr(read_write_ignore);
2730
3381
  bool initValueIsNull;
2731
-
2732
3382
  } AggTransInfo;
2733
3383
 
2734
3384
  #endif /* PATHNODES_H */