pg_query 2.2.1 → 4.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (466) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +21 -1
  3. data/README.md +29 -33
  4. data/Rakefile +2 -2
  5. data/ext/pg_query/include/access/amapi.h +45 -1
  6. data/ext/pg_query/include/access/attmap.h +1 -1
  7. data/ext/pg_query/include/access/attnum.h +2 -2
  8. data/ext/pg_query/include/access/clog.h +4 -2
  9. data/ext/pg_query/include/access/commit_ts.h +6 -9
  10. data/ext/pg_query/include/access/detoast.h +1 -11
  11. data/ext/pg_query/include/access/genam.h +15 -12
  12. data/ext/pg_query/include/access/gin.h +2 -2
  13. data/ext/pg_query/include/access/htup.h +1 -1
  14. data/ext/pg_query/include/access/htup_details.h +75 -87
  15. data/ext/pg_query/include/access/itup.h +7 -1
  16. data/ext/pg_query/include/access/parallel.h +2 -2
  17. data/ext/pg_query/include/access/printtup.h +1 -1
  18. data/ext/pg_query/include/access/relation.h +1 -1
  19. data/ext/pg_query/include/access/relscan.h +17 -2
  20. data/ext/pg_query/include/access/rmgr.h +30 -3
  21. data/ext/pg_query/include/access/rmgrlist.h +23 -23
  22. data/ext/pg_query/include/access/sdir.h +1 -1
  23. data/ext/pg_query/include/access/skey.h +1 -1
  24. data/ext/pg_query/include/access/stratnum.h +4 -2
  25. data/ext/pg_query/include/access/sysattr.h +1 -1
  26. data/ext/pg_query/include/access/table.h +2 -1
  27. data/ext/pg_query/include/access/tableam.h +272 -20
  28. data/ext/pg_query/include/access/toast_compression.h +73 -0
  29. data/ext/pg_query/include/access/transam.h +123 -13
  30. data/ext/pg_query/include/access/tupconvert.h +1 -1
  31. data/ext/pg_query/include/access/tupdesc.h +1 -1
  32. data/ext/pg_query/include/access/tupmacs.h +3 -3
  33. data/ext/pg_query/include/access/twophase.h +3 -1
  34. data/ext/pg_query/include/access/xact.h +73 -19
  35. data/ext/pg_query/include/access/xlog.h +60 -155
  36. data/ext/pg_query/include/access/xlog_internal.h +40 -13
  37. data/ext/pg_query/include/access/xlogdefs.h +8 -16
  38. data/ext/pg_query/include/access/xlogprefetcher.h +55 -0
  39. data/ext/pg_query/include/access/xlogreader.h +145 -39
  40. data/ext/pg_query/include/access/xlogrecord.h +18 -9
  41. data/ext/pg_query/include/access/xlogrecovery.h +157 -0
  42. data/ext/pg_query/include/c.h +101 -44
  43. data/ext/pg_query/include/catalog/catalog.h +3 -1
  44. data/ext/pg_query/include/catalog/catversion.h +2 -2
  45. data/ext/pg_query/include/catalog/dependency.h +8 -16
  46. data/ext/pg_query/include/catalog/genbki.h +83 -5
  47. data/ext/pg_query/include/catalog/index.h +18 -3
  48. data/ext/pg_query/include/catalog/indexing.h +12 -324
  49. data/ext/pg_query/include/catalog/namespace.h +4 -2
  50. data/ext/pg_query/include/catalog/objectaccess.h +70 -2
  51. data/ext/pg_query/include/catalog/objectaddress.h +11 -6
  52. data/ext/pg_query/include/catalog/pg_aggregate.h +14 -10
  53. data/ext/pg_query/include/catalog/pg_aggregate_d.h +2 -1
  54. data/ext/pg_query/include/catalog/pg_am.h +4 -1
  55. data/ext/pg_query/include/catalog/pg_am_d.h +3 -1
  56. data/ext/pg_query/include/catalog/pg_attribute.h +27 -10
  57. data/ext/pg_query/include/catalog/pg_attribute_d.h +21 -18
  58. data/ext/pg_query/include/catalog/pg_authid.h +7 -2
  59. data/ext/pg_query/include/catalog/pg_authid_d.h +17 -9
  60. data/ext/pg_query/include/catalog/pg_class.h +44 -14
  61. data/ext/pg_query/include/catalog/pg_class_d.h +30 -1
  62. data/ext/pg_query/include/catalog/pg_collation.h +33 -8
  63. data/ext/pg_query/include/catalog/pg_collation_d.h +20 -3
  64. data/ext/pg_query/include/catalog/pg_constraint.h +38 -12
  65. data/ext/pg_query/include/catalog/pg_constraint_d.h +10 -4
  66. data/ext/pg_query/include/catalog/pg_control.h +3 -5
  67. data/ext/pg_query/include/catalog/pg_conversion.h +7 -4
  68. data/ext/pg_query/include/catalog/pg_conversion_d.h +4 -1
  69. data/ext/pg_query/include/catalog/pg_depend.h +11 -7
  70. data/ext/pg_query/include/catalog/pg_depend_d.h +3 -1
  71. data/ext/pg_query/include/catalog/pg_event_trigger.h +9 -3
  72. data/ext/pg_query/include/catalog/pg_event_trigger_d.h +3 -1
  73. data/ext/pg_query/include/catalog/pg_index.h +17 -7
  74. data/ext/pg_query/include/catalog/pg_index_d.h +20 -17
  75. data/ext/pg_query/include/catalog/pg_language.h +10 -5
  76. data/ext/pg_query/include/catalog/pg_language_d.h +3 -1
  77. data/ext/pg_query/include/catalog/pg_namespace.h +7 -2
  78. data/ext/pg_query/include/catalog/pg_namespace_d.h +3 -1
  79. data/ext/pg_query/include/catalog/pg_opclass.h +8 -5
  80. data/ext/pg_query/include/catalog/pg_opclass_d.h +3 -1
  81. data/ext/pg_query/include/catalog/pg_operator.h +18 -15
  82. data/ext/pg_query/include/catalog/pg_operator_d.h +37 -1
  83. data/ext/pg_query/include/catalog/pg_opfamily.h +6 -3
  84. data/ext/pg_query/include/catalog/pg_opfamily_d.h +3 -1
  85. data/ext/pg_query/include/catalog/pg_parameter_acl.h +60 -0
  86. data/ext/pg_query/include/catalog/pg_parameter_acl_d.h +34 -0
  87. data/ext/pg_query/include/catalog/pg_partitioned_table.h +20 -9
  88. data/ext/pg_query/include/catalog/pg_partitioned_table_d.h +2 -1
  89. data/ext/pg_query/include/catalog/pg_proc.h +20 -11
  90. data/ext/pg_query/include/catalog/pg_proc_d.h +10 -8
  91. data/ext/pg_query/include/catalog/pg_publication.h +50 -7
  92. data/ext/pg_query/include/catalog/pg_publication_d.h +3 -1
  93. data/ext/pg_query/include/catalog/pg_replication_origin.h +6 -1
  94. data/ext/pg_query/include/catalog/pg_replication_origin_d.h +5 -1
  95. data/ext/pg_query/include/catalog/pg_statistic.h +19 -12
  96. data/ext/pg_query/include/catalog/pg_statistic_d.h +2 -1
  97. data/ext/pg_query/include/catalog/pg_statistic_ext.h +19 -5
  98. data/ext/pg_query/include/catalog/pg_statistic_ext_d.h +7 -2
  99. data/ext/pg_query/include/catalog/pg_transform.h +8 -5
  100. data/ext/pg_query/include/catalog/pg_transform_d.h +3 -1
  101. data/ext/pg_query/include/catalog/pg_trigger.h +24 -8
  102. data/ext/pg_query/include/catalog/pg_trigger_d.h +4 -1
  103. data/ext/pg_query/include/catalog/pg_ts_config.h +6 -3
  104. data/ext/pg_query/include/catalog/pg_ts_config_d.h +3 -1
  105. data/ext/pg_query/include/catalog/pg_ts_dict.h +8 -3
  106. data/ext/pg_query/include/catalog/pg_ts_dict_d.h +3 -1
  107. data/ext/pg_query/include/catalog/pg_ts_parser.h +6 -3
  108. data/ext/pg_query/include/catalog/pg_ts_parser_d.h +3 -1
  109. data/ext/pg_query/include/catalog/pg_ts_template.h +6 -3
  110. data/ext/pg_query/include/catalog/pg_ts_template_d.h +3 -1
  111. data/ext/pg_query/include/catalog/pg_type.h +55 -24
  112. data/ext/pg_query/include/catalog/pg_type_d.h +70 -31
  113. data/ext/pg_query/include/catalog/storage.h +5 -3
  114. data/ext/pg_query/include/commands/async.h +3 -4
  115. data/ext/pg_query/include/commands/dbcommands.h +2 -1
  116. data/ext/pg_query/include/commands/defrem.h +11 -24
  117. data/ext/pg_query/include/commands/event_trigger.h +2 -2
  118. data/ext/pg_query/include/commands/explain.h +1 -1
  119. data/ext/pg_query/include/commands/prepare.h +1 -1
  120. data/ext/pg_query/include/commands/tablespace.h +2 -2
  121. data/ext/pg_query/include/commands/trigger.h +18 -16
  122. data/ext/pg_query/include/commands/user.h +2 -2
  123. data/ext/pg_query/include/commands/vacuum.h +88 -41
  124. data/ext/pg_query/include/commands/variable.h +1 -1
  125. data/ext/pg_query/include/common/file_perm.h +4 -4
  126. data/ext/pg_query/include/common/hashfn.h +1 -1
  127. data/ext/pg_query/include/common/ip.h +1 -7
  128. data/ext/pg_query/include/common/keywords.h +2 -6
  129. data/ext/pg_query/include/common/kwlookup.h +1 -1
  130. data/ext/pg_query/include/common/pg_prng.h +60 -0
  131. data/ext/pg_query/include/common/relpath.h +2 -2
  132. data/ext/pg_query/include/common/string.h +24 -1
  133. data/ext/pg_query/include/common/unicode_combining_table.h +114 -2
  134. data/ext/pg_query/include/common/unicode_east_asian_fw_table.h +125 -0
  135. data/ext/pg_query/include/datatype/timestamp.h +40 -1
  136. data/ext/pg_query/include/executor/execdesc.h +1 -1
  137. data/ext/pg_query/include/executor/executor.h +65 -22
  138. data/ext/pg_query/include/executor/functions.h +17 -3
  139. data/ext/pg_query/include/executor/instrument.h +33 -16
  140. data/ext/pg_query/include/executor/spi.h +41 -3
  141. data/ext/pg_query/include/executor/tablefunc.h +1 -1
  142. data/ext/pg_query/include/executor/tuptable.h +1 -1
  143. data/ext/pg_query/include/fmgr.h +13 -7
  144. data/ext/pg_query/include/funcapi.h +16 -4
  145. data/ext/pg_query/include/getaddrinfo.h +1 -1
  146. data/ext/pg_query/include/jit/jit.h +11 -11
  147. data/ext/pg_query/include/kwlist_d.h +517 -494
  148. data/ext/pg_query/include/lib/dshash.h +112 -0
  149. data/ext/pg_query/include/lib/ilist.h +20 -1
  150. data/ext/pg_query/include/lib/pairingheap.h +1 -1
  151. data/ext/pg_query/include/lib/simplehash.h +140 -15
  152. data/ext/pg_query/include/lib/sort_template.h +432 -0
  153. data/ext/pg_query/include/lib/stringinfo.h +1 -1
  154. data/ext/pg_query/include/libpq/auth.h +6 -4
  155. data/ext/pg_query/include/libpq/crypt.h +5 -4
  156. data/ext/pg_query/include/libpq/hba.h +43 -4
  157. data/ext/pg_query/include/libpq/libpq-be.h +23 -6
  158. data/ext/pg_query/include/libpq/libpq.h +30 -20
  159. data/ext/pg_query/include/libpq/pqcomm.h +17 -31
  160. data/ext/pg_query/include/libpq/pqformat.h +1 -1
  161. data/ext/pg_query/include/libpq/pqsignal.h +4 -4
  162. data/ext/pg_query/include/mb/pg_wchar.h +105 -23
  163. data/ext/pg_query/include/mb/stringinfo_mb.h +1 -1
  164. data/ext/pg_query/include/miscadmin.h +47 -41
  165. data/ext/pg_query/include/nodes/bitmapset.h +1 -1
  166. data/ext/pg_query/include/nodes/execnodes.h +270 -78
  167. data/ext/pg_query/include/nodes/extensible.h +4 -2
  168. data/ext/pg_query/include/nodes/lockoptions.h +1 -1
  169. data/ext/pg_query/include/nodes/makefuncs.h +7 -6
  170. data/ext/pg_query/include/nodes/memnodes.h +5 -3
  171. data/ext/pg_query/include/nodes/nodeFuncs.h +1 -1
  172. data/ext/pg_query/include/nodes/nodes.h +30 -11
  173. data/ext/pg_query/include/nodes/params.h +1 -1
  174. data/ext/pg_query/include/nodes/parsenodes.h +322 -90
  175. data/ext/pg_query/include/nodes/pathnodes.h +243 -66
  176. data/ext/pg_query/include/nodes/pg_list.h +75 -69
  177. data/ext/pg_query/include/nodes/plannodes.h +111 -28
  178. data/ext/pg_query/include/nodes/primnodes.h +99 -47
  179. data/ext/pg_query/include/nodes/print.h +1 -1
  180. data/ext/pg_query/include/nodes/tidbitmap.h +1 -1
  181. data/ext/pg_query/include/nodes/value.h +58 -39
  182. data/ext/pg_query/include/optimizer/cost.h +9 -2
  183. data/ext/pg_query/include/optimizer/geqo.h +9 -7
  184. data/ext/pg_query/include/optimizer/geqo_gene.h +1 -1
  185. data/ext/pg_query/include/optimizer/optimizer.h +25 -17
  186. data/ext/pg_query/include/optimizer/paths.h +6 -6
  187. data/ext/pg_query/include/optimizer/planmain.h +15 -14
  188. data/ext/pg_query/include/parser/analyze.h +19 -5
  189. data/ext/pg_query/include/parser/gram.h +947 -913
  190. data/ext/pg_query/include/parser/gramparse.h +1 -1
  191. data/ext/pg_query/include/parser/kwlist.h +463 -453
  192. data/ext/pg_query/include/parser/parse_agg.h +2 -7
  193. data/ext/pg_query/include/parser/parse_coerce.h +3 -1
  194. data/ext/pg_query/include/parser/parse_expr.h +2 -3
  195. data/ext/pg_query/include/parser/parse_func.h +2 -1
  196. data/ext/pg_query/include/parser/parse_node.h +21 -9
  197. data/ext/pg_query/include/parser/parse_oper.h +1 -3
  198. data/ext/pg_query/include/parser/parse_relation.h +5 -4
  199. data/ext/pg_query/include/parser/parse_type.h +1 -1
  200. data/ext/pg_query/include/parser/parser.h +31 -4
  201. data/ext/pg_query/include/parser/parsetree.h +1 -1
  202. data/ext/pg_query/include/parser/scanner.h +1 -1
  203. data/ext/pg_query/include/parser/scansup.h +2 -5
  204. data/ext/pg_query/include/partitioning/partdefs.h +1 -1
  205. data/ext/pg_query/include/pg_config.h +83 -41
  206. data/ext/pg_query/include/pg_config_manual.h +74 -21
  207. data/ext/pg_query/include/pg_getopt.h +6 -6
  208. data/ext/pg_query/include/pg_query.h +5 -4
  209. data/ext/pg_query/include/pg_query_enum_defs.c +358 -241
  210. data/ext/pg_query/include/pg_query_fingerprint_conds.c +44 -7
  211. data/ext/pg_query/include/pg_query_fingerprint_defs.c +939 -113
  212. data/ext/pg_query/include/pg_query_outfuncs_conds.c +43 -13
  213. data/ext/pg_query/include/pg_query_outfuncs_defs.c +151 -26
  214. data/ext/pg_query/include/pg_query_readfuncs_conds.c +11 -2
  215. data/ext/pg_query/include/pg_query_readfuncs_defs.c +173 -30
  216. data/ext/pg_query/include/pg_trace.h +1 -1
  217. data/ext/pg_query/include/pgstat.h +449 -1238
  218. data/ext/pg_query/include/pgtime.h +14 -4
  219. data/ext/pg_query/include/pl_gram.h +126 -128
  220. data/ext/pg_query/include/pl_reserved_kwlist.h +1 -1
  221. data/ext/pg_query/include/pl_reserved_kwlist_d.h +10 -10
  222. data/ext/pg_query/include/pl_unreserved_kwlist.h +2 -3
  223. data/ext/pg_query/include/pl_unreserved_kwlist_d.h +54 -56
  224. data/ext/pg_query/include/plerrcodes.h +9 -1
  225. data/ext/pg_query/include/plpgsql.h +52 -54
  226. data/ext/pg_query/include/port/atomics/arch-arm.h +7 -1
  227. data/ext/pg_query/include/port/atomics/arch-ppc.h +1 -1
  228. data/ext/pg_query/include/port/atomics/arch-x86.h +1 -1
  229. data/ext/pg_query/include/port/atomics/fallback.h +1 -1
  230. data/ext/pg_query/include/port/atomics/generic-gcc.h +3 -3
  231. data/ext/pg_query/include/port/atomics/generic.h +1 -1
  232. data/ext/pg_query/include/port/atomics.h +1 -1
  233. data/ext/pg_query/include/port/pg_bitutils.h +40 -10
  234. data/ext/pg_query/include/port/pg_bswap.h +1 -1
  235. data/ext/pg_query/include/port/pg_crc32c.h +1 -1
  236. data/ext/pg_query/include/port.h +71 -46
  237. data/ext/pg_query/include/portability/instr_time.h +1 -1
  238. data/ext/pg_query/include/postgres.h +60 -16
  239. data/ext/pg_query/include/postmaster/autovacuum.h +17 -17
  240. data/ext/pg_query/include/postmaster/auxprocess.h +20 -0
  241. data/ext/pg_query/include/postmaster/bgworker.h +2 -1
  242. data/ext/pg_query/include/postmaster/bgworker_internals.h +2 -2
  243. data/ext/pg_query/include/postmaster/bgwriter.h +5 -5
  244. data/ext/pg_query/include/postmaster/fork_process.h +1 -1
  245. data/ext/pg_query/include/postmaster/interrupt.h +1 -1
  246. data/ext/pg_query/include/postmaster/pgarch.h +42 -8
  247. data/ext/pg_query/include/postmaster/postmaster.h +18 -17
  248. data/ext/pg_query/include/postmaster/startup.h +39 -0
  249. data/ext/pg_query/include/postmaster/syslogger.h +15 -10
  250. data/ext/pg_query/include/postmaster/walwriter.h +3 -3
  251. data/ext/pg_query/include/protobuf/pg_query.pb-c.h +1419 -914
  252. data/ext/pg_query/include/protobuf/pg_query.pb.h +43678 -32769
  253. data/ext/pg_query/include/regex/regex.h +18 -16
  254. data/ext/pg_query/include/replication/logicallauncher.h +3 -5
  255. data/ext/pg_query/include/replication/logicalproto.h +161 -17
  256. data/ext/pg_query/include/replication/logicalworker.h +1 -1
  257. data/ext/pg_query/include/replication/origin.h +7 -7
  258. data/ext/pg_query/include/replication/reorderbuffer.h +259 -42
  259. data/ext/pg_query/include/replication/slot.h +22 -11
  260. data/ext/pg_query/include/replication/syncrep.h +5 -5
  261. data/ext/pg_query/include/replication/walreceiver.h +145 -13
  262. data/ext/pg_query/include/replication/walsender.h +8 -8
  263. data/ext/pg_query/include/rewrite/prs2lock.h +1 -1
  264. data/ext/pg_query/include/rewrite/rewriteHandler.h +1 -3
  265. data/ext/pg_query/include/rewrite/rewriteManip.h +1 -1
  266. data/ext/pg_query/include/rewrite/rewriteSupport.h +1 -1
  267. data/ext/pg_query/include/storage/backendid.h +3 -3
  268. data/ext/pg_query/include/storage/block.h +4 -10
  269. data/ext/pg_query/include/storage/buf.h +1 -1
  270. data/ext/pg_query/include/storage/bufmgr.h +19 -14
  271. data/ext/pg_query/include/storage/bufpage.h +6 -8
  272. data/ext/pg_query/include/storage/condition_variable.h +13 -2
  273. data/ext/pg_query/include/storage/dsm.h +4 -1
  274. data/ext/pg_query/include/storage/dsm_impl.h +3 -2
  275. data/ext/pg_query/include/storage/fd.h +33 -3
  276. data/ext/pg_query/include/storage/fileset.h +40 -0
  277. data/ext/pg_query/include/storage/ipc.h +4 -1
  278. data/ext/pg_query/include/storage/item.h +1 -1
  279. data/ext/pg_query/include/storage/itemid.h +1 -1
  280. data/ext/pg_query/include/storage/itemptr.h +3 -1
  281. data/ext/pg_query/include/storage/large_object.h +2 -2
  282. data/ext/pg_query/include/storage/latch.h +9 -13
  283. data/ext/pg_query/include/storage/lmgr.h +2 -1
  284. data/ext/pg_query/include/storage/lock.h +11 -8
  285. data/ext/pg_query/include/storage/lockdefs.h +2 -2
  286. data/ext/pg_query/include/storage/lwlock.h +5 -32
  287. data/ext/pg_query/include/storage/lwlocknames.h +0 -1
  288. data/ext/pg_query/include/storage/off.h +1 -1
  289. data/ext/pg_query/include/storage/pg_sema.h +1 -1
  290. data/ext/pg_query/include/storage/pg_shmem.h +9 -7
  291. data/ext/pg_query/include/storage/pmsignal.h +15 -4
  292. data/ext/pg_query/include/storage/predicate.h +4 -4
  293. data/ext/pg_query/include/storage/proc.h +173 -59
  294. data/ext/pg_query/include/storage/procarray.h +98 -0
  295. data/ext/pg_query/include/storage/proclist_types.h +1 -1
  296. data/ext/pg_query/include/storage/procsignal.h +3 -7
  297. data/ext/pg_query/include/storage/relfilenode.h +1 -1
  298. data/ext/pg_query/include/storage/s_lock.h +60 -21
  299. data/ext/pg_query/include/storage/sharedfileset.h +3 -11
  300. data/ext/pg_query/include/storage/shm_mq.h +5 -4
  301. data/ext/pg_query/include/storage/shm_toc.h +1 -1
  302. data/ext/pg_query/include/storage/shmem.h +1 -1
  303. data/ext/pg_query/include/storage/sinval.h +3 -3
  304. data/ext/pg_query/include/storage/sinvaladt.h +1 -1
  305. data/ext/pg_query/include/storage/smgr.h +10 -8
  306. data/ext/pg_query/include/storage/spin.h +2 -2
  307. data/ext/pg_query/include/storage/standby.h +13 -6
  308. data/ext/pg_query/include/storage/standbydefs.h +2 -2
  309. data/ext/pg_query/include/storage/sync.h +7 -3
  310. data/ext/pg_query/include/tcop/cmdtag.h +1 -1
  311. data/ext/pg_query/include/tcop/cmdtaglist.h +3 -2
  312. data/ext/pg_query/include/tcop/deparse_utility.h +1 -1
  313. data/ext/pg_query/include/tcop/dest.h +1 -1
  314. data/ext/pg_query/include/tcop/fastpath.h +1 -2
  315. data/ext/pg_query/include/tcop/pquery.h +1 -1
  316. data/ext/pg_query/include/tcop/tcopprot.h +19 -11
  317. data/ext/pg_query/include/tcop/utility.h +7 -3
  318. data/ext/pg_query/include/tsearch/ts_cache.h +2 -2
  319. data/ext/pg_query/include/utils/acl.h +24 -3
  320. data/ext/pg_query/include/utils/aclchk_internal.h +1 -1
  321. data/ext/pg_query/include/utils/array.h +7 -2
  322. data/ext/pg_query/include/utils/backend_progress.h +44 -0
  323. data/ext/pg_query/include/utils/backend_status.h +321 -0
  324. data/ext/pg_query/include/utils/builtins.h +10 -11
  325. data/ext/pg_query/include/utils/bytea.h +3 -2
  326. data/ext/pg_query/include/utils/catcache.h +1 -1
  327. data/ext/pg_query/include/utils/date.h +1 -1
  328. data/ext/pg_query/include/utils/datetime.h +8 -7
  329. data/ext/pg_query/include/utils/datum.h +9 -1
  330. data/ext/pg_query/include/utils/dsa.h +1 -1
  331. data/ext/pg_query/include/utils/dynahash.h +4 -3
  332. data/ext/pg_query/include/utils/elog.h +52 -21
  333. data/ext/pg_query/include/utils/errcodes.h +2 -0
  334. data/ext/pg_query/include/utils/expandeddatum.h +1 -1
  335. data/ext/pg_query/include/utils/expandedrecord.h +1 -1
  336. data/ext/pg_query/include/utils/float.h +7 -7
  337. data/ext/pg_query/include/utils/fmgroids.h +1300 -696
  338. data/ext/pg_query/include/utils/fmgrprotos.h +199 -16
  339. data/ext/pg_query/include/utils/fmgrtab.h +6 -5
  340. data/ext/pg_query/include/utils/guc.h +69 -43
  341. data/ext/pg_query/include/utils/guc_tables.h +23 -19
  342. data/ext/pg_query/include/utils/hsearch.h +15 -11
  343. data/ext/pg_query/include/utils/inval.h +4 -1
  344. data/ext/pg_query/include/utils/lsyscache.h +11 -1
  345. data/ext/pg_query/include/utils/memdebug.h +1 -1
  346. data/ext/pg_query/include/utils/memutils.h +8 -3
  347. data/ext/pg_query/include/utils/numeric.h +19 -5
  348. data/ext/pg_query/include/utils/palloc.h +25 -3
  349. data/ext/pg_query/include/utils/partcache.h +1 -1
  350. data/ext/pg_query/include/utils/pg_locale.h +17 -9
  351. data/ext/pg_query/include/utils/pg_lsn.h +1 -1
  352. data/ext/pg_query/include/utils/pgstat_internal.h +784 -0
  353. data/ext/pg_query/include/utils/pidfile.h +1 -1
  354. data/ext/pg_query/include/utils/plancache.h +6 -5
  355. data/ext/pg_query/include/utils/portal.h +10 -12
  356. data/ext/pg_query/include/utils/ps_status.h +1 -1
  357. data/ext/pg_query/include/utils/queryenvironment.h +1 -1
  358. data/ext/pg_query/include/utils/queryjumble.h +88 -0
  359. data/ext/pg_query/include/utils/regproc.h +14 -3
  360. data/ext/pg_query/include/utils/rel.h +71 -19
  361. data/ext/pg_query/include/utils/relcache.h +8 -5
  362. data/ext/pg_query/include/utils/reltrigger.h +1 -1
  363. data/ext/pg_query/include/utils/resowner.h +1 -1
  364. data/ext/pg_query/include/utils/rls.h +2 -2
  365. data/ext/pg_query/include/utils/ruleutils.h +4 -1
  366. data/ext/pg_query/include/utils/sharedtuplestore.h +1 -1
  367. data/ext/pg_query/include/utils/snapmgr.h +34 -14
  368. data/ext/pg_query/include/utils/snapshot.h +14 -1
  369. data/ext/pg_query/include/utils/sortsupport.h +117 -2
  370. data/ext/pg_query/include/utils/syscache.h +6 -1
  371. data/ext/pg_query/include/utils/timeout.h +11 -4
  372. data/ext/pg_query/include/utils/timestamp.h +6 -5
  373. data/ext/pg_query/include/utils/tuplesort.h +25 -11
  374. data/ext/pg_query/include/utils/tuplestore.h +2 -2
  375. data/ext/pg_query/include/utils/typcache.h +24 -17
  376. data/ext/pg_query/include/utils/tzparser.h +1 -1
  377. data/ext/pg_query/include/utils/varlena.h +5 -3
  378. data/ext/pg_query/include/utils/wait_event.h +289 -0
  379. data/ext/pg_query/include/utils/xml.h +4 -4
  380. data/ext/pg_query/pg_query.pb-c.c +4302 -2304
  381. data/ext/pg_query/pg_query_deparse.c +1106 -373
  382. data/ext/pg_query/pg_query_fingerprint.c +30 -10
  383. data/ext/pg_query/pg_query_json_plpgsql.c +0 -25
  384. data/ext/pg_query/pg_query_normalize.c +1 -1
  385. data/ext/pg_query/pg_query_outfuncs_json.c +54 -16
  386. data/ext/pg_query/pg_query_outfuncs_protobuf.c +70 -10
  387. data/ext/pg_query/pg_query_parse.c +1 -1
  388. data/ext/pg_query/pg_query_readfuncs_protobuf.c +42 -8
  389. data/ext/pg_query/pg_query_scan.c +2 -1
  390. data/ext/pg_query/pg_query_split.c +3 -2
  391. data/ext/pg_query/src_backend_catalog_namespace.c +20 -9
  392. data/ext/pg_query/src_backend_catalog_pg_proc.c +4 -1
  393. data/ext/pg_query/src_backend_commands_define.c +11 -1
  394. data/ext/pg_query/src_backend_nodes_bitmapset.c +3 -1
  395. data/ext/pg_query/src_backend_nodes_copyfuncs.c +401 -76
  396. data/ext/pg_query/src_backend_nodes_equalfuncs.c +290 -46
  397. data/ext/pg_query/src_backend_nodes_extensible.c +1 -1
  398. data/ext/pg_query/src_backend_nodes_list.c +74 -11
  399. data/ext/pg_query/src_backend_nodes_makefuncs.c +5 -4
  400. data/ext/pg_query/src_backend_nodes_nodeFuncs.c +55 -12
  401. data/ext/pg_query/src_backend_nodes_value.c +28 -19
  402. data/ext/pg_query/src_backend_parser_gram.c +33874 -31261
  403. data/ext/pg_query/src_backend_parser_parser.c +26 -7
  404. data/ext/pg_query/src_backend_parser_scan.c +172 -209
  405. data/ext/pg_query/src_backend_parser_scansup.c +4 -28
  406. data/ext/pg_query/src_backend_postmaster_postmaster.c +77 -106
  407. data/ext/pg_query/src_backend_storage_ipc_ipc.c +13 -4
  408. data/ext/pg_query/src_backend_storage_lmgr_s_lock.c +5 -4
  409. data/ext/pg_query/src_backend_tcop_postgres.c +62 -23
  410. data/ext/pg_query/src_backend_utils_activity_pgstat_database.c +140 -0
  411. data/ext/pg_query/src_backend_utils_adt_datum.c +13 -1
  412. data/ext/pg_query/src_backend_utils_adt_expandeddatum.c +1 -1
  413. data/ext/pg_query/src_backend_utils_adt_format_type.c +6 -2
  414. data/ext/pg_query/src_backend_utils_adt_ruleutils.c +71 -5
  415. data/ext/pg_query/src_backend_utils_error_assert.c +16 -14
  416. data/ext/pg_query/src_backend_utils_error_elog.c +172 -99
  417. data/ext/pg_query/src_backend_utils_fmgr_fmgr.c +12 -17
  418. data/ext/pg_query/src_backend_utils_hash_dynahash.c +40 -10
  419. data/ext/pg_query/src_backend_utils_init_globals.c +5 -5
  420. data/ext/pg_query/src_backend_utils_mb_mbutils.c +55 -66
  421. data/ext/pg_query/src_backend_utils_misc_guc.c +206 -45
  422. data/ext/pg_query/src_backend_utils_mmgr_aset.c +7 -5
  423. data/ext/pg_query/src_backend_utils_mmgr_mcxt.c +123 -35
  424. data/ext/pg_query/src_common_encnames.c +1 -1
  425. data/ext/pg_query/src_common_hashfn.c +3 -3
  426. data/ext/pg_query/src_common_keywords.c +15 -2
  427. data/ext/pg_query/src_common_kwlist_d.h +517 -494
  428. data/ext/pg_query/src_common_kwlookup.c +1 -1
  429. data/ext/pg_query/src_common_pg_prng.c +152 -0
  430. data/ext/pg_query/src_common_psprintf.c +1 -1
  431. data/ext/pg_query/src_common_string.c +7 -1
  432. data/ext/pg_query/src_common_stringinfo.c +1 -1
  433. data/ext/pg_query/src_common_wchar.c +701 -109
  434. data/ext/pg_query/src_pl_plpgsql_src_pl_comp.c +45 -20
  435. data/ext/pg_query/src_pl_plpgsql_src_pl_funcs.c +1 -18
  436. data/ext/pg_query/src_pl_plpgsql_src_pl_gram.c +1233 -1259
  437. data/ext/pg_query/src_pl_plpgsql_src_pl_handler.c +1 -1
  438. data/ext/pg_query/src_pl_plpgsql_src_pl_reserved_kwlist_d.h +10 -10
  439. data/ext/pg_query/src_pl_plpgsql_src_pl_scanner.c +2 -2
  440. data/ext/pg_query/src_pl_plpgsql_src_pl_unreserved_kwlist_d.h +54 -56
  441. data/ext/pg_query/src_port_pg_bitutils.c +41 -31
  442. data/ext/pg_query/src_port_pgsleep.c +1 -1
  443. data/ext/pg_query/src_port_pgstrcasecmp.c +1 -1
  444. data/ext/pg_query/src_port_qsort.c +12 -224
  445. data/ext/pg_query/src_port_snprintf.c +37 -13
  446. data/ext/pg_query/src_port_strerror.c +9 -19
  447. data/ext/pg_query/src_port_strnlen.c +1 -1
  448. data/lib/pg_query/filter_columns.rb +1 -1
  449. data/lib/pg_query/fingerprint.rb +5 -1
  450. data/lib/pg_query/node.rb +2 -2
  451. data/lib/pg_query/param_refs.rb +1 -1
  452. data/lib/pg_query/parse.rb +18 -8
  453. data/lib/pg_query/pg_query_pb.rb +1108 -942
  454. data/lib/pg_query/truncate.rb +1 -1
  455. data/lib/pg_query/version.rb +1 -1
  456. metadata +28 -18
  457. data/ext/pg_query/include/access/xloginsert.h +0 -64
  458. data/ext/pg_query/include/bootstrap/bootstrap.h +0 -62
  459. data/ext/pg_query/include/parser/parse_clause.h +0 -54
  460. data/ext/pg_query/include/parser/parse_collate.h +0 -27
  461. data/ext/pg_query/include/parser/parse_target.h +0 -46
  462. data/ext/pg_query/pg_query_ruby_freebsd.sym +0 -2
  463. data/ext/pg_query/src_backend_libpq_pqcomm.c +0 -659
  464. data/ext/pg_query/src_backend_parser_parse_expr.c +0 -313
  465. data/ext/pg_query/src_port_erand48.c +0 -127
  466. data/ext/pg_query/src_port_random.c +0 -31
@@ -4,7 +4,7 @@
4
4
  * POSTGRES table access method definitions.
5
5
  *
6
6
  *
7
- * Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group
7
+ * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
8
8
  * Portions Copyright (c) 1994, Regents of the University of California
9
9
  *
10
10
  * src/include/access/tableam.h
@@ -19,6 +19,7 @@
19
19
 
20
20
  #include "access/relscan.h"
21
21
  #include "access/sdir.h"
22
+ #include "access/xact.h"
22
23
  #include "utils/guc.h"
23
24
  #include "utils/rel.h"
24
25
  #include "utils/snapshot.h"
@@ -27,8 +28,8 @@
27
28
  #define DEFAULT_TABLE_ACCESS_METHOD "heap"
28
29
 
29
30
  /* GUCs */
30
- extern char *default_table_access_method;
31
- extern bool synchronize_seqscans;
31
+ extern PGDLLIMPORT char *default_table_access_method;
32
+ extern PGDLLIMPORT bool synchronize_seqscans;
32
33
 
33
34
 
34
35
  struct BulkInsertStateData;
@@ -48,18 +49,19 @@ typedef enum ScanOptions
48
49
  SO_TYPE_BITMAPSCAN = 1 << 1,
49
50
  SO_TYPE_SAMPLESCAN = 1 << 2,
50
51
  SO_TYPE_TIDSCAN = 1 << 3,
51
- SO_TYPE_ANALYZE = 1 << 4,
52
+ SO_TYPE_TIDRANGESCAN = 1 << 4,
53
+ SO_TYPE_ANALYZE = 1 << 5,
52
54
 
53
55
  /* several of SO_ALLOW_* may be specified */
54
56
  /* allow or disallow use of access strategy */
55
- SO_ALLOW_STRAT = 1 << 5,
57
+ SO_ALLOW_STRAT = 1 << 6,
56
58
  /* report location to syncscan logic? */
57
- SO_ALLOW_SYNC = 1 << 6,
59
+ SO_ALLOW_SYNC = 1 << 7,
58
60
  /* verify visibility page-at-a-time? */
59
- SO_ALLOW_PAGEMODE = 1 << 7,
61
+ SO_ALLOW_PAGEMODE = 1 << 8,
60
62
 
61
63
  /* unregister snapshot at scan end? */
62
- SO_TEMP_SNAPSHOT = 1 << 8
64
+ SO_TEMP_SNAPSHOT = 1 << 9
63
65
  } ScanOptions;
64
66
 
65
67
  /*
@@ -127,6 +129,108 @@ typedef struct TM_FailureData
127
129
  bool traversed;
128
130
  } TM_FailureData;
129
131
 
132
+ /*
133
+ * State used when calling table_index_delete_tuples().
134
+ *
135
+ * Represents the status of table tuples, referenced by table TID and taken by
136
+ * index AM from index tuples. State consists of high level parameters of the
137
+ * deletion operation, plus two mutable palloc()'d arrays for information
138
+ * about the status of individual table tuples. These are conceptually one
139
+ * single array. Using two arrays keeps the TM_IndexDelete struct small,
140
+ * which makes sorting the first array (the deltids array) fast.
141
+ *
142
+ * Some index AM callers perform simple index tuple deletion (by specifying
143
+ * bottomup = false), and include only known-dead deltids. These known-dead
144
+ * entries are all marked knowndeletable = true directly (typically these are
145
+ * TIDs from LP_DEAD-marked index tuples), but that isn't strictly required.
146
+ *
147
+ * Callers that specify bottomup = true are "bottom-up index deletion"
148
+ * callers. The considerations for the tableam are more subtle with these
149
+ * callers because they ask the tableam to perform highly speculative work,
150
+ * and might only expect the tableam to check a small fraction of all entries.
151
+ * Caller is not allowed to specify knowndeletable = true for any entry
152
+ * because everything is highly speculative. Bottom-up caller provides
153
+ * context and hints to tableam -- see comments below for details on how index
154
+ * AMs and tableams should coordinate during bottom-up index deletion.
155
+ *
156
+ * Simple index deletion callers may ask the tableam to perform speculative
157
+ * work, too. This is a little like bottom-up deletion, but not too much.
158
+ * The tableam will only perform speculative work when it's practically free
159
+ * to do so in passing for simple deletion caller (while always performing
160
+ * whatever work is needed to enable knowndeletable/LP_DEAD index tuples to
161
+ * be deleted within index AM). This is the real reason why it's possible for
162
+ * simple index deletion caller to specify knowndeletable = false up front
163
+ * (this means "check if it's possible for me to delete corresponding index
164
+ * tuple when it's cheap to do so in passing"). The index AM should only
165
+ * include "extra" entries for index tuples whose TIDs point to a table block
166
+ * that tableam is expected to have to visit anyway (in the event of a block
167
+ * orientated tableam). The tableam isn't strictly obligated to check these
168
+ * "extra" TIDs, but a block-based AM should always manage to do so in
169
+ * practice.
170
+ *
171
+ * The final contents of the deltids/status arrays are interesting to callers
172
+ * that ask tableam to perform speculative work (i.e. when _any_ items have
173
+ * knowndeletable set to false up front). These index AM callers will
174
+ * naturally need to consult final state to determine which index tuples are
175
+ * in fact deletable.
176
+ *
177
+ * The index AM can keep track of which index tuple relates to which deltid by
178
+ * setting idxoffnum (and/or relying on each entry being uniquely identifiable
179
+ * using tid), which is important when the final contents of the array will
180
+ * need to be interpreted -- the array can shrink from initial size after
181
+ * tableam processing and/or have entries in a new order (tableam may sort
182
+ * deltids array for its own reasons). Bottom-up callers may find that final
183
+ * ndeltids is 0 on return from call to tableam, in which case no index tuple
184
+ * deletions are possible. Simple deletion callers can rely on any entries
185
+ * they know to be deletable appearing in the final array as deletable.
186
+ */
187
+ typedef struct TM_IndexDelete
188
+ {
189
+ ItemPointerData tid; /* table TID from index tuple */
190
+ int16 id; /* Offset into TM_IndexStatus array */
191
+ } TM_IndexDelete;
192
+
193
+ typedef struct TM_IndexStatus
194
+ {
195
+ OffsetNumber idxoffnum; /* Index am page offset number */
196
+ bool knowndeletable; /* Currently known to be deletable? */
197
+
198
+ /* Bottom-up index deletion specific fields follow */
199
+ bool promising; /* Promising (duplicate) index tuple? */
200
+ int16 freespace; /* Space freed in index if deleted */
201
+ } TM_IndexStatus;
202
+
203
+ /*
204
+ * Index AM/tableam coordination is central to the design of bottom-up index
205
+ * deletion. The index AM provides hints about where to look to the tableam
206
+ * by marking some entries as "promising". Index AM does this with duplicate
207
+ * index tuples that are strongly suspected to be old versions left behind by
208
+ * UPDATEs that did not logically modify indexed values. Index AM may find it
209
+ * helpful to only mark entries as promising when they're thought to have been
210
+ * affected by such an UPDATE in the recent past.
211
+ *
212
+ * Bottom-up index deletion casts a wide net at first, usually by including
213
+ * all TIDs on a target index page. It is up to the tableam to worry about
214
+ * the cost of checking transaction status information. The tableam is in
215
+ * control, but needs careful guidance from the index AM. Index AM requests
216
+ * that bottomupfreespace target be met, while tableam measures progress
217
+ * towards that goal by tallying the per-entry freespace value for known
218
+ * deletable entries. (All !bottomup callers can just set these space related
219
+ * fields to zero.)
220
+ */
221
+ typedef struct TM_IndexDeleteOp
222
+ {
223
+ Relation irel; /* Target index relation */
224
+ BlockNumber iblknum; /* Index block number (for error reports) */
225
+ bool bottomup; /* Bottom-up (not simple) deletion? */
226
+ int bottomupfreespace; /* Bottom-up space target */
227
+
228
+ /* Mutable per-TID information follows (index AM initializes entries) */
229
+ int ndeltids; /* Current # of deltids/status elements */
230
+ TM_IndexDelete *deltids;
231
+ TM_IndexStatus *status;
232
+ } TM_IndexDeleteOp;
233
+
130
234
  /* "options" flag bits for table_tuple_insert */
131
235
  /* TABLE_INSERT_SKIP_WAL was 0x0001; RelationNeedsWAL() now governs */
132
236
  #define TABLE_INSERT_SKIP_FSM 0x0002
@@ -224,6 +328,34 @@ typedef struct TableAmRoutine
224
328
  ScanDirection direction,
225
329
  TupleTableSlot *slot);
226
330
 
331
+ /*-----------
332
+ * Optional functions to provide scanning for ranges of ItemPointers.
333
+ * Implementations must either provide both of these functions, or neither
334
+ * of them.
335
+ *
336
+ * Implementations of scan_set_tidrange must themselves handle
337
+ * ItemPointers of any value. i.e, they must handle each of the following:
338
+ *
339
+ * 1) mintid or maxtid is beyond the end of the table; and
340
+ * 2) mintid is above maxtid; and
341
+ * 3) item offset for mintid or maxtid is beyond the maximum offset
342
+ * allowed by the AM.
343
+ *
344
+ * Implementations can assume that scan_set_tidrange is always called
345
+ * before can_getnextslot_tidrange or after scan_rescan and before any
346
+ * further calls to scan_getnextslot_tidrange.
347
+ */
348
+ void (*scan_set_tidrange) (TableScanDesc scan,
349
+ ItemPointer mintid,
350
+ ItemPointer maxtid);
351
+
352
+ /*
353
+ * Return next tuple from `scan` that's in the range of TIDs defined by
354
+ * scan_set_tidrange.
355
+ */
356
+ bool (*scan_getnextslot_tidrange) (TableScanDesc scan,
357
+ ScanDirection direction,
358
+ TupleTableSlot *slot);
227
359
 
228
360
  /* ------------------------------------------------------------------------
229
361
  * Parallel table scan related functions.
@@ -341,10 +473,9 @@ typedef struct TableAmRoutine
341
473
  TupleTableSlot *slot,
342
474
  Snapshot snapshot);
343
475
 
344
- /* see table_compute_xid_horizon_for_tuples() */
345
- TransactionId (*compute_xid_horizon_for_tuples) (Relation rel,
346
- ItemPointerData *items,
347
- int nitems);
476
+ /* see table_index_delete_tuples() */
477
+ TransactionId (*index_delete_tuples) (Relation rel,
478
+ TM_IndexDeleteOp *delstate);
348
479
 
349
480
 
350
481
  /* ------------------------------------------------------------------------
@@ -496,7 +627,7 @@ typedef struct TableAmRoutine
496
627
  * There probably, in the future, needs to be a separate callback to
497
628
  * integrate with autovacuum's scheduling.
498
629
  */
499
- void (*relation_vacuum) (Relation onerel,
630
+ void (*relation_vacuum) (Relation rel,
500
631
  struct VacuumParams *params,
501
632
  BufferAccessStrategy bstrategy);
502
633
 
@@ -903,9 +1034,76 @@ static inline bool
903
1034
  table_scan_getnextslot(TableScanDesc sscan, ScanDirection direction, TupleTableSlot *slot)
904
1035
  {
905
1036
  slot->tts_tableOid = RelationGetRelid(sscan->rs_rd);
1037
+
1038
+ /*
1039
+ * We don't expect direct calls to table_scan_getnextslot with valid
1040
+ * CheckXidAlive for catalog or regular tables. See detailed comments in
1041
+ * xact.c where these variables are declared.
1042
+ */
1043
+ if (unlikely(TransactionIdIsValid(CheckXidAlive) && !bsysscan))
1044
+ elog(ERROR, "unexpected table_scan_getnextslot call during logical decoding");
1045
+
906
1046
  return sscan->rs_rd->rd_tableam->scan_getnextslot(sscan, direction, slot);
907
1047
  }
908
1048
 
1049
+ /* ----------------------------------------------------------------------------
1050
+ * TID Range scanning related functions.
1051
+ * ----------------------------------------------------------------------------
1052
+ */
1053
+
1054
+ /*
1055
+ * table_beginscan_tidrange is the entry point for setting up a TableScanDesc
1056
+ * for a TID range scan.
1057
+ */
1058
+ static inline TableScanDesc
1059
+ table_beginscan_tidrange(Relation rel, Snapshot snapshot,
1060
+ ItemPointer mintid,
1061
+ ItemPointer maxtid)
1062
+ {
1063
+ TableScanDesc sscan;
1064
+ uint32 flags = SO_TYPE_TIDRANGESCAN | SO_ALLOW_PAGEMODE;
1065
+
1066
+ sscan = rel->rd_tableam->scan_begin(rel, snapshot, 0, NULL, NULL, flags);
1067
+
1068
+ /* Set the range of TIDs to scan */
1069
+ sscan->rs_rd->rd_tableam->scan_set_tidrange(sscan, mintid, maxtid);
1070
+
1071
+ return sscan;
1072
+ }
1073
+
1074
+ /*
1075
+ * table_rescan_tidrange resets the scan position and sets the minimum and
1076
+ * maximum TID range to scan for a TableScanDesc created by
1077
+ * table_beginscan_tidrange.
1078
+ */
1079
+ static inline void
1080
+ table_rescan_tidrange(TableScanDesc sscan, ItemPointer mintid,
1081
+ ItemPointer maxtid)
1082
+ {
1083
+ /* Ensure table_beginscan_tidrange() was used. */
1084
+ Assert((sscan->rs_flags & SO_TYPE_TIDRANGESCAN) != 0);
1085
+
1086
+ sscan->rs_rd->rd_tableam->scan_rescan(sscan, NULL, false, false, false, false);
1087
+ sscan->rs_rd->rd_tableam->scan_set_tidrange(sscan, mintid, maxtid);
1088
+ }
1089
+
1090
+ /*
1091
+ * Fetch the next tuple from `sscan` for a TID range scan created by
1092
+ * table_beginscan_tidrange(). Stores the tuple in `slot` and returns true,
1093
+ * or returns false if no more tuples exist in the range.
1094
+ */
1095
+ static inline bool
1096
+ table_scan_getnextslot_tidrange(TableScanDesc sscan, ScanDirection direction,
1097
+ TupleTableSlot *slot)
1098
+ {
1099
+ /* Ensure table_beginscan_tidrange() was used. */
1100
+ Assert((sscan->rs_flags & SO_TYPE_TIDRANGESCAN) != 0);
1101
+
1102
+ return sscan->rs_rd->rd_tableam->scan_getnextslot_tidrange(sscan,
1103
+ direction,
1104
+ slot);
1105
+ }
1106
+
909
1107
 
910
1108
  /* ----------------------------------------------------------------------------
911
1109
  * Parallel table scan related functions.
@@ -1017,6 +1215,13 @@ table_index_fetch_tuple(struct IndexFetchTableData *scan,
1017
1215
  TupleTableSlot *slot,
1018
1216
  bool *call_again, bool *all_dead)
1019
1217
  {
1218
+ /*
1219
+ * We don't expect direct calls to table_index_fetch_tuple with valid
1220
+ * CheckXidAlive for catalog or regular tables. See detailed comments in
1221
+ * xact.c where these variables are declared.
1222
+ */
1223
+ if (unlikely(TransactionIdIsValid(CheckXidAlive) && !bsysscan))
1224
+ elog(ERROR, "unexpected table_index_fetch_tuple call during logical decoding");
1020
1225
 
1021
1226
  return scan->rel->rd_tableam->index_fetch_tuple(scan, tid, snapshot,
1022
1227
  slot, call_again,
@@ -1056,6 +1261,14 @@ table_tuple_fetch_row_version(Relation rel,
1056
1261
  Snapshot snapshot,
1057
1262
  TupleTableSlot *slot)
1058
1263
  {
1264
+ /*
1265
+ * We don't expect direct calls to table_tuple_fetch_row_version with
1266
+ * valid CheckXidAlive for catalog or regular tables. See detailed
1267
+ * comments in xact.c where these variables are declared.
1268
+ */
1269
+ if (unlikely(TransactionIdIsValid(CheckXidAlive) && !bsysscan))
1270
+ elog(ERROR, "unexpected table_tuple_fetch_row_version call during logical decoding");
1271
+
1059
1272
  return rel->rd_tableam->tuple_fetch_row_version(rel, tid, snapshot, slot);
1060
1273
  }
1061
1274
 
@@ -1097,16 +1310,23 @@ table_tuple_satisfies_snapshot(Relation rel, TupleTableSlot *slot,
1097
1310
  }
1098
1311
 
1099
1312
  /*
1100
- * Compute the newest xid among the tuples pointed to by items. This is used
1101
- * to compute what snapshots to conflict with when replaying WAL records for
1102
- * page-level index vacuums.
1313
+ * Determine which index tuples are safe to delete based on their table TID.
1314
+ *
1315
+ * Determines which entries from index AM caller's TM_IndexDeleteOp state
1316
+ * point to vacuumable table tuples. Entries that are found by tableam to be
1317
+ * vacuumable are naturally safe for index AM to delete, and so get directly
1318
+ * marked as deletable. See comments above TM_IndexDelete and comments above
1319
+ * TM_IndexDeleteOp for full details.
1320
+ *
1321
+ * Returns a latestRemovedXid transaction ID that caller generally places in
1322
+ * its index deletion WAL record. This might be used during subsequent REDO
1323
+ * of the WAL record when in Hot Standby mode -- a recovery conflict for the
1324
+ * index deletion operation might be required on the standby.
1103
1325
  */
1104
1326
  static inline TransactionId
1105
- table_compute_xid_horizon_for_tuples(Relation rel,
1106
- ItemPointerData *items,
1107
- int nitems)
1327
+ table_index_delete_tuples(Relation rel, TM_IndexDeleteOp *delstate)
1108
1328
  {
1109
- return rel->rd_tableam->compute_xid_horizon_for_tuples(rel, items, nitems);
1329
+ return rel->rd_tableam->index_delete_tuples(rel, delstate);
1110
1330
  }
1111
1331
 
1112
1332
 
@@ -1713,6 +1933,14 @@ static inline bool
1713
1933
  table_scan_bitmap_next_block(TableScanDesc scan,
1714
1934
  struct TBMIterateResult *tbmres)
1715
1935
  {
1936
+ /*
1937
+ * We don't expect direct calls to table_scan_bitmap_next_block with valid
1938
+ * CheckXidAlive for catalog or regular tables. See detailed comments in
1939
+ * xact.c where these variables are declared.
1940
+ */
1941
+ if (unlikely(TransactionIdIsValid(CheckXidAlive) && !bsysscan))
1942
+ elog(ERROR, "unexpected table_scan_bitmap_next_block call during logical decoding");
1943
+
1716
1944
  return scan->rs_rd->rd_tableam->scan_bitmap_next_block(scan,
1717
1945
  tbmres);
1718
1946
  }
@@ -1730,6 +1958,14 @@ table_scan_bitmap_next_tuple(TableScanDesc scan,
1730
1958
  struct TBMIterateResult *tbmres,
1731
1959
  TupleTableSlot *slot)
1732
1960
  {
1961
+ /*
1962
+ * We don't expect direct calls to table_scan_bitmap_next_tuple with valid
1963
+ * CheckXidAlive for catalog or regular tables. See detailed comments in
1964
+ * xact.c where these variables are declared.
1965
+ */
1966
+ if (unlikely(TransactionIdIsValid(CheckXidAlive) && !bsysscan))
1967
+ elog(ERROR, "unexpected table_scan_bitmap_next_tuple call during logical decoding");
1968
+
1733
1969
  return scan->rs_rd->rd_tableam->scan_bitmap_next_tuple(scan,
1734
1970
  tbmres,
1735
1971
  slot);
@@ -1748,6 +1984,13 @@ static inline bool
1748
1984
  table_scan_sample_next_block(TableScanDesc scan,
1749
1985
  struct SampleScanState *scanstate)
1750
1986
  {
1987
+ /*
1988
+ * We don't expect direct calls to table_scan_sample_next_block with valid
1989
+ * CheckXidAlive for catalog or regular tables. See detailed comments in
1990
+ * xact.c where these variables are declared.
1991
+ */
1992
+ if (unlikely(TransactionIdIsValid(CheckXidAlive) && !bsysscan))
1993
+ elog(ERROR, "unexpected table_scan_sample_next_block call during logical decoding");
1751
1994
  return scan->rs_rd->rd_tableam->scan_sample_next_block(scan, scanstate);
1752
1995
  }
1753
1996
 
@@ -1764,6 +2007,13 @@ table_scan_sample_next_tuple(TableScanDesc scan,
1764
2007
  struct SampleScanState *scanstate,
1765
2008
  TupleTableSlot *slot)
1766
2009
  {
2010
+ /*
2011
+ * We don't expect direct calls to table_scan_sample_next_tuple with valid
2012
+ * CheckXidAlive for catalog or regular tables. See detailed comments in
2013
+ * xact.c where these variables are declared.
2014
+ */
2015
+ if (unlikely(TransactionIdIsValid(CheckXidAlive) && !bsysscan))
2016
+ elog(ERROR, "unexpected table_scan_sample_next_tuple call during logical decoding");
1767
2017
  return scan->rs_rd->rd_tableam->scan_sample_next_tuple(scan, scanstate,
1768
2018
  slot);
1769
2019
  }
@@ -1793,8 +2043,10 @@ extern Size table_block_parallelscan_initialize(Relation rel,
1793
2043
  extern void table_block_parallelscan_reinitialize(Relation rel,
1794
2044
  ParallelTableScanDesc pscan);
1795
2045
  extern BlockNumber table_block_parallelscan_nextpage(Relation rel,
2046
+ ParallelBlockTableScanWorker pbscanwork,
1796
2047
  ParallelBlockTableScanDesc pbscan);
1797
2048
  extern void table_block_parallelscan_startblock_init(Relation rel,
2049
+ ParallelBlockTableScanWorker pbscanwork,
1798
2050
  ParallelBlockTableScanDesc pbscan);
1799
2051
 
1800
2052
 
@@ -0,0 +1,73 @@
1
+ /*-------------------------------------------------------------------------
2
+ *
3
+ * toast_compression.h
4
+ * Functions for toast compression.
5
+ *
6
+ * Copyright (c) 2021-2022, PostgreSQL Global Development Group
7
+ *
8
+ * src/include/access/toast_compression.h
9
+ *
10
+ *-------------------------------------------------------------------------
11
+ */
12
+
13
+ #ifndef TOAST_COMPRESSION_H
14
+ #define TOAST_COMPRESSION_H
15
+
16
+ /*
17
+ * GUC support.
18
+ *
19
+ * default_toast_compression is an integer for purposes of the GUC machinery,
20
+ * but the value is one of the char values defined below, as they appear in
21
+ * pg_attribute.attcompression, e.g. TOAST_PGLZ_COMPRESSION.
22
+ */
23
+ extern PGDLLIMPORT int default_toast_compression;
24
+
25
+ /*
26
+ * Built-in compression method ID. The toast compression header will store
27
+ * this in the first 2 bits of the raw length. These built-in compression
28
+ * method IDs are directly mapped to the built-in compression methods.
29
+ *
30
+ * Don't use these values for anything other than understanding the meaning
31
+ * of the raw bits from a varlena; in particular, if the goal is to identify
32
+ * a compression method, use the constants TOAST_PGLZ_COMPRESSION, etc.
33
+ * below. We might someday support more than 4 compression methods, but
34
+ * we can never have more than 4 values in this enum, because there are
35
+ * only 2 bits available in the places where this is stored.
36
+ */
37
+ typedef enum ToastCompressionId
38
+ {
39
+ TOAST_PGLZ_COMPRESSION_ID = 0,
40
+ TOAST_LZ4_COMPRESSION_ID = 1,
41
+ TOAST_INVALID_COMPRESSION_ID = 2
42
+ } ToastCompressionId;
43
+
44
+ /*
45
+ * Built-in compression methods. pg_attribute will store these in the
46
+ * attcompression column. In attcompression, InvalidCompressionMethod
47
+ * denotes the default behavior.
48
+ */
49
+ #define TOAST_PGLZ_COMPRESSION 'p'
50
+ #define TOAST_LZ4_COMPRESSION 'l'
51
+ #define InvalidCompressionMethod '\0'
52
+
53
+ #define CompressionMethodIsValid(cm) ((cm) != InvalidCompressionMethod)
54
+
55
+
56
+ /* pglz compression/decompression routines */
57
+ extern struct varlena *pglz_compress_datum(const struct varlena *value);
58
+ extern struct varlena *pglz_decompress_datum(const struct varlena *value);
59
+ extern struct varlena *pglz_decompress_datum_slice(const struct varlena *value,
60
+ int32 slicelength);
61
+
62
+ /* lz4 compression/decompression routines */
63
+ extern struct varlena *lz4_compress_datum(const struct varlena *value);
64
+ extern struct varlena *lz4_decompress_datum(const struct varlena *value);
65
+ extern struct varlena *lz4_decompress_datum_slice(const struct varlena *value,
66
+ int32 slicelength);
67
+
68
+ /* other stuff */
69
+ extern ToastCompressionId toast_get_compression_id(struct varlena *attr);
70
+ extern char CompressionNameToMethod(const char *compression);
71
+ extern const char *GetCompressionMethodName(char method);
72
+
73
+ #endif /* TOAST_COMPRESSION_H */