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
@@ -10,10 +10,21 @@
10
10
  * - MemoryContextCallResetCallbacks
11
11
  * - MemoryContextResetOnly
12
12
  * - repalloc
13
+ * - GetMemoryChunkContext
13
14
  * - MemoryContextStats
14
15
  * - MemoryContextStatsDetail
15
16
  * - MemoryContextStatsInternal
16
17
  * - MemoryContextStatsPrint
18
+ * - mcxt_methods
19
+ * - GetMemoryChunkSpace
20
+ * - MemoryContextAllocAligned
21
+ * - MemoryContextAllocExtended
22
+ * - BogusFree
23
+ * - GetMemoryChunkHeader
24
+ * - BogusRealloc
25
+ * - BogusGetChunkContext
26
+ * - BogusGetChunkSpace
27
+ * - GetMemoryChunkMethodID
17
28
  * - pfree
18
29
  * - pstrdup
19
30
  * - MemoryContextStrdup
@@ -43,7 +54,7 @@
43
54
  * context's MemoryContextMethods struct.
44
55
  *
45
56
  *
46
- * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
57
+ * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
47
58
  * Portions Copyright (c) 1994, Regents of the University of California
48
59
  *
49
60
  *
@@ -63,12 +74,105 @@
63
74
  #include "utils/fmgrprotos.h"
64
75
  #include "utils/memdebug.h"
65
76
  #include "utils/memutils.h"
77
+ #include "utils/memutils_internal.h"
78
+ #include "utils/memutils_memorychunk.h"
79
+
66
80
 
81
+ static void BogusFree(void *pointer);
82
+ static void *BogusRealloc(void *pointer, Size size);
83
+ static MemoryContext BogusGetChunkContext(void *pointer);
84
+ static Size BogusGetChunkSpace(void *pointer);
67
85
 
68
86
  /*****************************************************************************
69
87
  * GLOBAL MEMORY *
70
88
  *****************************************************************************/
71
89
 
90
+ static const MemoryContextMethods mcxt_methods[] = {
91
+ /* aset.c */
92
+ [MCTX_ASET_ID].alloc = AllocSetAlloc,
93
+ [MCTX_ASET_ID].free_p = AllocSetFree,
94
+ [MCTX_ASET_ID].realloc = AllocSetRealloc,
95
+ [MCTX_ASET_ID].reset = AllocSetReset,
96
+ [MCTX_ASET_ID].delete_context = AllocSetDelete,
97
+ [MCTX_ASET_ID].get_chunk_context = AllocSetGetChunkContext,
98
+ [MCTX_ASET_ID].get_chunk_space = AllocSetGetChunkSpace,
99
+ [MCTX_ASET_ID].is_empty = AllocSetIsEmpty,
100
+ [MCTX_ASET_ID].stats = AllocSetStats,
101
+ #ifdef MEMORY_CONTEXT_CHECKING
102
+ [MCTX_ASET_ID].check = AllocSetCheck,
103
+ #endif
104
+
105
+ /* generation.c */
106
+ [MCTX_GENERATION_ID].alloc = GenerationAlloc,
107
+ [MCTX_GENERATION_ID].free_p = GenerationFree,
108
+ [MCTX_GENERATION_ID].realloc = GenerationRealloc,
109
+ [MCTX_GENERATION_ID].reset = GenerationReset,
110
+ [MCTX_GENERATION_ID].delete_context = GenerationDelete,
111
+ [MCTX_GENERATION_ID].get_chunk_context = GenerationGetChunkContext,
112
+ [MCTX_GENERATION_ID].get_chunk_space = GenerationGetChunkSpace,
113
+ [MCTX_GENERATION_ID].is_empty = GenerationIsEmpty,
114
+ [MCTX_GENERATION_ID].stats = GenerationStats,
115
+ #ifdef MEMORY_CONTEXT_CHECKING
116
+ [MCTX_GENERATION_ID].check = GenerationCheck,
117
+ #endif
118
+
119
+ /* slab.c */
120
+ [MCTX_SLAB_ID].alloc = SlabAlloc,
121
+ [MCTX_SLAB_ID].free_p = SlabFree,
122
+ [MCTX_SLAB_ID].realloc = SlabRealloc,
123
+ [MCTX_SLAB_ID].reset = SlabReset,
124
+ [MCTX_SLAB_ID].delete_context = SlabDelete,
125
+ [MCTX_SLAB_ID].get_chunk_context = SlabGetChunkContext,
126
+ [MCTX_SLAB_ID].get_chunk_space = SlabGetChunkSpace,
127
+ [MCTX_SLAB_ID].is_empty = SlabIsEmpty,
128
+ [MCTX_SLAB_ID].stats = SlabStats,
129
+ #ifdef MEMORY_CONTEXT_CHECKING
130
+ [MCTX_SLAB_ID].check = SlabCheck,
131
+ #endif
132
+
133
+ /* alignedalloc.c */
134
+ [MCTX_ALIGNED_REDIRECT_ID].alloc = NULL, /* not required */
135
+ [MCTX_ALIGNED_REDIRECT_ID].free_p = AlignedAllocFree,
136
+ [MCTX_ALIGNED_REDIRECT_ID].realloc = AlignedAllocRealloc,
137
+ [MCTX_ALIGNED_REDIRECT_ID].reset = NULL, /* not required */
138
+ [MCTX_ALIGNED_REDIRECT_ID].delete_context = NULL, /* not required */
139
+ [MCTX_ALIGNED_REDIRECT_ID].get_chunk_context = AlignedAllocGetChunkContext,
140
+ [MCTX_ALIGNED_REDIRECT_ID].get_chunk_space = AlignedAllocGetChunkSpace,
141
+ [MCTX_ALIGNED_REDIRECT_ID].is_empty = NULL, /* not required */
142
+ [MCTX_ALIGNED_REDIRECT_ID].stats = NULL, /* not required */
143
+ #ifdef MEMORY_CONTEXT_CHECKING
144
+ [MCTX_ALIGNED_REDIRECT_ID].check = NULL, /* not required */
145
+ #endif
146
+
147
+
148
+ /*
149
+ * Unused (as yet) IDs should have dummy entries here. This allows us to
150
+ * fail cleanly if a bogus pointer is passed to pfree or the like. It
151
+ * seems sufficient to provide routines for the methods that might get
152
+ * invoked from inspection of a chunk (see MCXT_METHOD calls below).
153
+ */
154
+
155
+ [MCTX_UNUSED1_ID].free_p = BogusFree,
156
+ [MCTX_UNUSED1_ID].realloc = BogusRealloc,
157
+ [MCTX_UNUSED1_ID].get_chunk_context = BogusGetChunkContext,
158
+ [MCTX_UNUSED1_ID].get_chunk_space = BogusGetChunkSpace,
159
+
160
+ [MCTX_UNUSED2_ID].free_p = BogusFree,
161
+ [MCTX_UNUSED2_ID].realloc = BogusRealloc,
162
+ [MCTX_UNUSED2_ID].get_chunk_context = BogusGetChunkContext,
163
+ [MCTX_UNUSED2_ID].get_chunk_space = BogusGetChunkSpace,
164
+
165
+ [MCTX_UNUSED3_ID].free_p = BogusFree,
166
+ [MCTX_UNUSED3_ID].realloc = BogusRealloc,
167
+ [MCTX_UNUSED3_ID].get_chunk_context = BogusGetChunkContext,
168
+ [MCTX_UNUSED3_ID].get_chunk_space = BogusGetChunkSpace,
169
+
170
+ [MCTX_UNUSED4_ID].free_p = BogusFree,
171
+ [MCTX_UNUSED4_ID].realloc = BogusRealloc,
172
+ [MCTX_UNUSED4_ID].get_chunk_context = BogusGetChunkContext,
173
+ [MCTX_UNUSED4_ID].get_chunk_space = BogusGetChunkSpace,
174
+ };
175
+
72
176
  /*
73
177
  * CurrentMemoryContext
74
178
  * Default memory context for allocations.
@@ -110,6 +214,100 @@ static void MemoryContextStatsPrint(MemoryContext context, void *passthru,
110
214
  #define AssertNotInCriticalSection(context) \
111
215
  Assert(CritSectionCount == 0 || (context)->allowInCritSection)
112
216
 
217
+ /*
218
+ * Call the given function in the MemoryContextMethods for the memory context
219
+ * type that 'pointer' belongs to.
220
+ */
221
+ #define MCXT_METHOD(pointer, method) \
222
+ mcxt_methods[GetMemoryChunkMethodID(pointer)].method
223
+
224
+ /*
225
+ * GetMemoryChunkMethodID
226
+ * Return the MemoryContextMethodID from the uint64 chunk header which
227
+ * directly precedes 'pointer'.
228
+ */
229
+ static inline MemoryContextMethodID
230
+ GetMemoryChunkMethodID(const void *pointer)
231
+ {
232
+ uint64 header;
233
+
234
+ /*
235
+ * Try to detect bogus pointers handed to us, poorly though we can.
236
+ * Presumably, a pointer that isn't MAXALIGNED isn't pointing at an
237
+ * allocated chunk.
238
+ */
239
+ Assert(pointer == (const void *) MAXALIGN(pointer));
240
+
241
+ /* Allow access to the uint64 header */
242
+ VALGRIND_MAKE_MEM_DEFINED((char *) pointer - sizeof(uint64), sizeof(uint64));
243
+
244
+ header = *((const uint64 *) ((const char *) pointer - sizeof(uint64)));
245
+
246
+ /* Disallow access to the uint64 header */
247
+ VALGRIND_MAKE_MEM_NOACCESS((char *) pointer - sizeof(uint64), sizeof(uint64));
248
+
249
+ return (MemoryContextMethodID) (header & MEMORY_CONTEXT_METHODID_MASK);
250
+ }
251
+
252
+ /*
253
+ * GetMemoryChunkHeader
254
+ * Return the uint64 chunk header which directly precedes 'pointer'.
255
+ *
256
+ * This is only used after GetMemoryChunkMethodID, so no need for error checks.
257
+ */
258
+ static inline uint64
259
+ GetMemoryChunkHeader(const void *pointer)
260
+ {
261
+ uint64 header;
262
+
263
+ /* Allow access to the uint64 header */
264
+ VALGRIND_MAKE_MEM_DEFINED((char *) pointer - sizeof(uint64), sizeof(uint64));
265
+
266
+ header = *((const uint64 *) ((const char *) pointer - sizeof(uint64)));
267
+
268
+ /* Disallow access to the uint64 header */
269
+ VALGRIND_MAKE_MEM_NOACCESS((char *) pointer - sizeof(uint64), sizeof(uint64));
270
+
271
+ return header;
272
+ }
273
+
274
+ /*
275
+ * Support routines to trap use of invalid memory context method IDs
276
+ * (from calling pfree or the like on a bogus pointer). As a possible
277
+ * aid in debugging, we report the header word along with the pointer
278
+ * address (if we got here, there must be an accessible header word).
279
+ */
280
+ static void
281
+ BogusFree(void *pointer)
282
+ {
283
+ elog(ERROR, "pfree called with invalid pointer %p (header 0x%016llx)",
284
+ pointer, (unsigned long long) GetMemoryChunkHeader(pointer));
285
+ }
286
+
287
+ static void *
288
+ BogusRealloc(void *pointer, Size size)
289
+ {
290
+ elog(ERROR, "repalloc called with invalid pointer %p (header 0x%016llx)",
291
+ pointer, (unsigned long long) GetMemoryChunkHeader(pointer));
292
+ return NULL; /* keep compiler quiet */
293
+ }
294
+
295
+ static MemoryContext
296
+ BogusGetChunkContext(void *pointer)
297
+ {
298
+ elog(ERROR, "GetMemoryChunkContext called with invalid pointer %p (header 0x%016llx)",
299
+ pointer, (unsigned long long) GetMemoryChunkHeader(pointer));
300
+ return NULL; /* keep compiler quiet */
301
+ }
302
+
303
+ static Size
304
+ BogusGetChunkSpace(void *pointer)
305
+ {
306
+ elog(ERROR, "GetMemoryChunkSpace called with invalid pointer %p (header 0x%016llx)",
307
+ pointer, (unsigned long long) GetMemoryChunkHeader(pointer));
308
+ return 0; /* keep compiler quiet */
309
+ }
310
+
113
311
 
114
312
  /*****************************************************************************
115
313
  * EXPORTED ROUTINES *
@@ -135,7 +333,7 @@ static void MemoryContextStatsPrint(MemoryContext context, void *passthru,
135
333
  void
136
334
  MemoryContextInit(void)
137
335
  {
138
- AssertState(TopMemoryContext == NULL);
336
+ Assert(TopMemoryContext == NULL);
139
337
 
140
338
  /*
141
339
  * First, initialize TopMemoryContext, which is the parent of all others.
@@ -179,7 +377,7 @@ MemoryContextInit(void)
179
377
  void
180
378
  MemoryContextReset(MemoryContext context)
181
379
  {
182
- AssertArg(MemoryContextIsValid(context));
380
+ Assert(MemoryContextIsValid(context));
183
381
 
184
382
  /* save a function call in common case where there are no children */
185
383
  if (context->firstchild != NULL)
@@ -198,7 +396,7 @@ MemoryContextReset(MemoryContext context)
198
396
  void
199
397
  MemoryContextResetOnly(MemoryContext context)
200
398
  {
201
- AssertArg(MemoryContextIsValid(context));
399
+ Assert(MemoryContextIsValid(context));
202
400
 
203
401
  /* Nothing to do if no pallocs since startup or last reset */
204
402
  if (!context->isReset)
@@ -209,10 +407,8 @@ MemoryContextResetOnly(MemoryContext context)
209
407
  * If context->ident points into the context's memory, it will become
210
408
  * a dangling pointer. We could prevent that by setting it to NULL
211
409
  * here, but that would break valid coding patterns that keep the
212
- * ident elsewhere, e.g. in a parent context. Another idea is to use
213
- * MemoryContextContains(), but we don't require ident strings to be
214
- * in separately-palloc'd chunks, so that risks false positives. So
215
- * for now we assume the programmer got it right.
410
+ * ident elsewhere, e.g. in a parent context. So for now we assume
411
+ * the programmer got it right.
216
412
  */
217
413
 
218
414
  context->methods->reset(context);
@@ -242,7 +438,7 @@ MemoryContextResetOnly(MemoryContext context)
242
438
  void
243
439
  MemoryContextDelete(MemoryContext context)
244
440
  {
245
- AssertArg(MemoryContextIsValid(context));
441
+ Assert(MemoryContextIsValid(context));
246
442
  /* We had better not be deleting TopMemoryContext ... */
247
443
  Assert(context != TopMemoryContext);
248
444
  /* And not CurrentMemoryContext, either */
@@ -287,7 +483,7 @@ MemoryContextDelete(MemoryContext context)
287
483
  void
288
484
  MemoryContextDeleteChildren(MemoryContext context)
289
485
  {
290
- AssertArg(MemoryContextIsValid(context));
486
+ Assert(MemoryContextIsValid(context));
291
487
 
292
488
  /*
293
489
  * MemoryContextDelete will delink the child from me, so just iterate as
@@ -369,8 +565,8 @@ MemoryContextCallResetCallbacks(MemoryContext context)
369
565
  void
370
566
  MemoryContextSetParent(MemoryContext context, MemoryContext new_parent)
371
567
  {
372
- AssertArg(MemoryContextIsValid(context));
373
- AssertArg(context != new_parent);
568
+ Assert(MemoryContextIsValid(context));
569
+ Assert(context != new_parent);
374
570
 
375
571
  /* Fast path if it's got correct parent already */
376
572
  if (new_parent == context->parent)
@@ -396,7 +592,7 @@ MemoryContextSetParent(MemoryContext context, MemoryContext new_parent)
396
592
  /* And relink */
397
593
  if (new_parent)
398
594
  {
399
- AssertArg(MemoryContextIsValid(new_parent));
595
+ Assert(MemoryContextIsValid(new_parent));
400
596
  context->parent = new_parent;
401
597
  context->prevchild = NULL;
402
598
  context->nextchild = new_parent->firstchild;
@@ -426,11 +622,22 @@ MemoryContextSetParent(MemoryContext context, MemoryContext new_parent)
426
622
  void
427
623
  MemoryContextAllowInCriticalSection(MemoryContext context, bool allow)
428
624
  {
429
- AssertArg(MemoryContextIsValid(context));
625
+ Assert(MemoryContextIsValid(context));
430
626
 
431
627
  context->allowInCritSection = allow;
432
628
  }
433
629
 
630
+ /*
631
+ * GetMemoryChunkContext
632
+ * Given a currently-allocated chunk, determine the MemoryContext that
633
+ * the chunk belongs to.
634
+ */
635
+ MemoryContext
636
+ GetMemoryChunkContext(void *pointer)
637
+ {
638
+ return MCXT_METHOD(pointer, get_chunk_context) (pointer);
639
+ }
640
+
434
641
  /*
435
642
  * GetMemoryChunkSpace
436
643
  * Given a currently-allocated chunk, determine the total space
@@ -439,7 +646,11 @@ MemoryContextAllowInCriticalSection(MemoryContext context, bool allow)
439
646
  * This is useful for measuring the total space occupied by a set of
440
647
  * allocated chunks.
441
648
  */
442
-
649
+ Size
650
+ GetMemoryChunkSpace(void *pointer)
651
+ {
652
+ return MCXT_METHOD(pointer, get_chunk_space) (pointer);
653
+ }
443
654
 
444
655
  /*
445
656
  * MemoryContextGetParent
@@ -505,10 +716,10 @@ MemoryContextStatsDetail(MemoryContext context, int max_children,
505
716
  * to the connected client.
506
717
  *
507
718
  * We don't buffer the information about all memory contexts in a
508
- * backend into StringInfo and log it as one message. Otherwise which
509
- * may require the buffer to be enlarged very much and lead to OOM
510
- * error since there can be a large number of memory contexts in a
511
- * backend. Instead, we log one message per memory context.
719
+ * backend into StringInfo and log it as one message. That would
720
+ * require the buffer to be enlarged, risking an OOM as there could be
721
+ * a large number of memory contexts in a backend. Instead, we log
722
+ * one message per memory context.
512
723
  */
513
724
  ereport(LOG_SERVER_ONLY,
514
725
  (errhidestmt(true),
@@ -536,7 +747,7 @@ MemoryContextStatsInternal(MemoryContext context, int level,
536
747
  MemoryContext child;
537
748
  int ichild;
538
749
 
539
- AssertArg(MemoryContextIsValid(context));
750
+ Assert(MemoryContextIsValid(context));
540
751
 
541
752
  /* Examine the context itself */
542
753
  context->methods->stats(context,
@@ -699,19 +910,6 @@ MemoryContextStatsPrint(MemoryContext context, void *passthru,
699
910
 
700
911
  #endif
701
912
 
702
- /*
703
- * MemoryContextContains
704
- * Detect whether an allocated chunk of memory belongs to a given
705
- * context or not.
706
- *
707
- * Caution: this test is reliable as long as 'pointer' does point to
708
- * a chunk of memory allocated from *some* context. If 'pointer' points
709
- * at memory obtained in some other way, there is a small chance of a
710
- * false-positive result, since the bits right before it might look like
711
- * a valid chunk header by chance.
712
- */
713
-
714
-
715
913
  /*
716
914
  * MemoryContextCreate
717
915
  * Context-type-independent part of context creation.
@@ -737,7 +935,7 @@ MemoryContextStatsPrint(MemoryContext context, void *passthru,
737
935
  *
738
936
  * node: the as-yet-uninitialized common part of the context header node.
739
937
  * tag: NodeTag code identifying the memory context type.
740
- * methods: context-type-specific methods (usually statically allocated).
938
+ * method_id: MemoryContextMethodID of the context-type being created.
741
939
  * parent: parent context, or NULL if this will be a top-level context.
742
940
  * name: name of context (must be statically allocated).
743
941
  *
@@ -747,7 +945,7 @@ MemoryContextStatsPrint(MemoryContext context, void *passthru,
747
945
  void
748
946
  MemoryContextCreate(MemoryContext node,
749
947
  NodeTag tag,
750
- const MemoryContextMethods *methods,
948
+ MemoryContextMethodID method_id,
751
949
  MemoryContext parent,
752
950
  const char *name)
753
951
  {
@@ -757,7 +955,7 @@ MemoryContextCreate(MemoryContext node,
757
955
  /* Initialize all standard fields of memory context header */
758
956
  node->type = tag;
759
957
  node->isReset = true;
760
- node->methods = methods;
958
+ node->methods = &mcxt_methods[method_id];
761
959
  node->parent = parent;
762
960
  node->firstchild = NULL;
763
961
  node->mem_allocated = 0;
@@ -797,7 +995,7 @@ MemoryContextAlloc(MemoryContext context, Size size)
797
995
  {
798
996
  void *ret;
799
997
 
800
- AssertArg(MemoryContextIsValid(context));
998
+ Assert(MemoryContextIsValid(context));
801
999
  AssertNotInCriticalSection(context);
802
1000
 
803
1001
  if (!AllocSizeIsValid(size))
@@ -840,7 +1038,7 @@ MemoryContextAllocZero(MemoryContext context, Size size)
840
1038
  {
841
1039
  void *ret;
842
1040
 
843
- AssertArg(MemoryContextIsValid(context));
1041
+ Assert(MemoryContextIsValid(context));
844
1042
  AssertNotInCriticalSection(context);
845
1043
 
846
1044
  if (!AllocSizeIsValid(size))
@@ -878,7 +1076,7 @@ MemoryContextAllocZeroAligned(MemoryContext context, Size size)
878
1076
  {
879
1077
  void *ret;
880
1078
 
881
- AssertArg(MemoryContextIsValid(context));
1079
+ Assert(MemoryContextIsValid(context));
882
1080
  AssertNotInCriticalSection(context);
883
1081
 
884
1082
  if (!AllocSizeIsValid(size))
@@ -913,11 +1111,11 @@ MemoryContextAllocExtended(MemoryContext context, Size size, int flags)
913
1111
  {
914
1112
  void *ret;
915
1113
 
916
- AssertArg(MemoryContextIsValid(context));
1114
+ Assert(MemoryContextIsValid(context));
917
1115
  AssertNotInCriticalSection(context);
918
1116
 
919
- if (((flags & MCXT_ALLOC_HUGE) != 0 && !AllocHugeSizeIsValid(size)) ||
920
- ((flags & MCXT_ALLOC_HUGE) == 0 && !AllocSizeIsValid(size)))
1117
+ if (!((flags & MCXT_ALLOC_HUGE) != 0 ? AllocHugeSizeIsValid(size) :
1118
+ AllocSizeIsValid(size)))
921
1119
  elog(ERROR, "invalid memory alloc request size %zu", size);
922
1120
 
923
1121
  context->isReset = false;
@@ -973,7 +1171,7 @@ palloc(Size size)
973
1171
  void *ret;
974
1172
  MemoryContext context = CurrentMemoryContext;
975
1173
 
976
- AssertArg(MemoryContextIsValid(context));
1174
+ Assert(MemoryContextIsValid(context));
977
1175
  AssertNotInCriticalSection(context);
978
1176
 
979
1177
  if (!AllocSizeIsValid(size))
@@ -1004,7 +1202,7 @@ palloc0(Size size)
1004
1202
  void *ret;
1005
1203
  MemoryContext context = CurrentMemoryContext;
1006
1204
 
1007
- AssertArg(MemoryContextIsValid(context));
1205
+ Assert(MemoryContextIsValid(context));
1008
1206
  AssertNotInCriticalSection(context);
1009
1207
 
1010
1208
  if (!AllocSizeIsValid(size))
@@ -1032,6 +1230,125 @@ palloc0(Size size)
1032
1230
 
1033
1231
 
1034
1232
 
1233
+ /*
1234
+ * MemoryContextAllocAligned
1235
+ * Allocate 'size' bytes of memory in 'context' aligned to 'alignto'
1236
+ * bytes.
1237
+ *
1238
+ * Currently, we align addresses by requesting additional bytes from the
1239
+ * MemoryContext's standard allocator function and then aligning the returned
1240
+ * address by the required alignment. This means that the given MemoryContext
1241
+ * must support providing us with a chunk of memory that's larger than 'size'.
1242
+ * For allocators such as Slab, that's not going to work, as slab only allows
1243
+ * chunks of the size that's specified when the context is created.
1244
+ *
1245
+ * 'alignto' must be a power of 2.
1246
+ * 'flags' may be 0 or set the same as MemoryContextAllocExtended().
1247
+ */
1248
+ void *
1249
+ MemoryContextAllocAligned(MemoryContext context,
1250
+ Size size, Size alignto, int flags)
1251
+ {
1252
+ MemoryChunk *alignedchunk;
1253
+ Size alloc_size;
1254
+ void *unaligned;
1255
+ void *aligned;
1256
+
1257
+ /* wouldn't make much sense to waste that much space */
1258
+ Assert(alignto < (128 * 1024 * 1024));
1259
+
1260
+ /* ensure alignto is a power of 2 */
1261
+ Assert((alignto & (alignto - 1)) == 0);
1262
+
1263
+ /*
1264
+ * If the alignment requirements are less than what we already guarantee
1265
+ * then just use the standard allocation function.
1266
+ */
1267
+ if (unlikely(alignto <= MAXIMUM_ALIGNOF))
1268
+ return MemoryContextAllocExtended(context, size, flags);
1269
+
1270
+ /*
1271
+ * We implement aligned pointers by simply allocating enough memory for
1272
+ * the requested size plus the alignment and an additional "redirection"
1273
+ * MemoryChunk. This additional MemoryChunk is required for operations
1274
+ * such as pfree when used on the pointer returned by this function. We
1275
+ * use this redirection MemoryChunk in order to find the pointer to the
1276
+ * memory that was returned by the MemoryContextAllocExtended call below.
1277
+ * We do that by "borrowing" the block offset field and instead of using
1278
+ * that to find the offset into the owning block, we use it to find the
1279
+ * original allocated address.
1280
+ *
1281
+ * Here we must allocate enough extra memory so that we can still align
1282
+ * the pointer returned by MemoryContextAllocExtended and also have enough
1283
+ * space for the redirection MemoryChunk. Since allocations will already
1284
+ * be at least aligned by MAXIMUM_ALIGNOF, we can subtract that amount
1285
+ * from the allocation size to save a little memory.
1286
+ */
1287
+ alloc_size = size + PallocAlignedExtraBytes(alignto);
1288
+
1289
+ #ifdef MEMORY_CONTEXT_CHECKING
1290
+ /* ensure there's space for a sentinel byte */
1291
+ alloc_size += 1;
1292
+ #endif
1293
+
1294
+ /* perform the actual allocation */
1295
+ unaligned = MemoryContextAllocExtended(context, alloc_size, flags);
1296
+
1297
+ /* set the aligned pointer */
1298
+ aligned = (void *) TYPEALIGN(alignto, (char *) unaligned +
1299
+ sizeof(MemoryChunk));
1300
+
1301
+ alignedchunk = PointerGetMemoryChunk(aligned);
1302
+
1303
+ /*
1304
+ * We set the redirect MemoryChunk so that the block offset calculation is
1305
+ * used to point back to the 'unaligned' allocated chunk. This allows us
1306
+ * to use MemoryChunkGetBlock() to find the unaligned chunk when we need
1307
+ * to perform operations such as pfree() and repalloc().
1308
+ *
1309
+ * We store 'alignto' in the MemoryChunk's 'value' so that we know what
1310
+ * the alignment was set to should we ever be asked to realloc this
1311
+ * pointer.
1312
+ */
1313
+ MemoryChunkSetHdrMask(alignedchunk, unaligned, alignto,
1314
+ MCTX_ALIGNED_REDIRECT_ID);
1315
+
1316
+ /* double check we produced a correctly aligned pointer */
1317
+ Assert((void *) TYPEALIGN(alignto, aligned) == aligned);
1318
+
1319
+ #ifdef MEMORY_CONTEXT_CHECKING
1320
+ alignedchunk->requested_size = size;
1321
+ /* set mark to catch clobber of "unused" space */
1322
+ set_sentinel(aligned, size);
1323
+ #endif
1324
+
1325
+ /* Mark the bytes before the redirection header as noaccess */
1326
+ VALGRIND_MAKE_MEM_NOACCESS(unaligned,
1327
+ (char *) alignedchunk - (char *) unaligned);
1328
+
1329
+ /* Disallow access to the redirection chunk header. */
1330
+ VALGRIND_MAKE_MEM_NOACCESS(alignedchunk, sizeof(MemoryChunk));
1331
+
1332
+ return aligned;
1333
+ }
1334
+
1335
+ /*
1336
+ * palloc_aligned
1337
+ * Allocate 'size' bytes returning a pointer that's aligned to the
1338
+ * 'alignto' boundary.
1339
+ *
1340
+ * Currently, we align addresses by requesting additional bytes from the
1341
+ * MemoryContext's standard allocator function and then aligning the returned
1342
+ * address by the required alignment. This means that the given MemoryContext
1343
+ * must support providing us with a chunk of memory that's larger than 'size'.
1344
+ * For allocators such as Slab, that's not going to work, as slab only allows
1345
+ * chunks of the size that's specified when the context is created.
1346
+ *
1347
+ * 'alignto' must be a power of 2.
1348
+ * 'flags' may be 0 or set the same as MemoryContextAllocExtended().
1349
+ */
1350
+
1351
+
1035
1352
  /*
1036
1353
  * pfree
1037
1354
  * Release an allocated chunk.
@@ -1039,10 +1356,17 @@ palloc0(Size size)
1039
1356
  void
1040
1357
  pfree(void *pointer)
1041
1358
  {
1359
+ #ifdef USE_VALGRIND
1360
+ MemoryContextMethodID method = GetMemoryChunkMethodID(pointer);
1042
1361
  MemoryContext context = GetMemoryChunkContext(pointer);
1362
+ #endif
1363
+
1364
+ MCXT_METHOD(pointer, free_p) (pointer);
1043
1365
 
1044
- context->methods->free_p(context, pointer);
1045
- VALGRIND_MEMPOOL_FREE(context, pointer);
1366
+ #ifdef USE_VALGRIND
1367
+ if (method != MCTX_ALIGNED_REDIRECT_ID)
1368
+ VALGRIND_MEMPOOL_FREE(context, pointer);
1369
+ #endif
1046
1370
  }
1047
1371
 
1048
1372
  /*
@@ -1052,7 +1376,12 @@ pfree(void *pointer)
1052
1376
  void *
1053
1377
  repalloc(void *pointer, Size size)
1054
1378
  {
1379
+ #ifdef USE_VALGRIND
1380
+ MemoryContextMethodID method = GetMemoryChunkMethodID(pointer);
1381
+ #endif
1382
+ #if defined(USE_ASSERT_CHECKING) || defined(USE_VALGRIND)
1055
1383
  MemoryContext context = GetMemoryChunkContext(pointer);
1384
+ #endif
1056
1385
  void *ret;
1057
1386
 
1058
1387
  if (!AllocSizeIsValid(size))
@@ -1063,22 +1392,42 @@ repalloc(void *pointer, Size size)
1063
1392
  /* isReset must be false already */
1064
1393
  Assert(!context->isReset);
1065
1394
 
1066
- ret = context->methods->realloc(context, pointer, size);
1395
+ ret = MCXT_METHOD(pointer, realloc) (pointer, size);
1067
1396
  if (unlikely(ret == NULL))
1068
1397
  {
1398
+ MemoryContext cxt = GetMemoryChunkContext(pointer);
1399
+
1069
1400
  MemoryContextStats(TopMemoryContext);
1070
1401
  ereport(ERROR,
1071
1402
  (errcode(ERRCODE_OUT_OF_MEMORY),
1072
1403
  errmsg("out of memory"),
1073
1404
  errdetail("Failed on request of size %zu in memory context \"%s\".",
1074
- size, context->name)));
1405
+ size, cxt->name)));
1075
1406
  }
1076
1407
 
1077
- VALGRIND_MEMPOOL_CHANGE(context, pointer, ret, size);
1408
+ #ifdef USE_VALGRIND
1409
+ if (method != MCTX_ALIGNED_REDIRECT_ID)
1410
+ VALGRIND_MEMPOOL_CHANGE(context, pointer, ret, size);
1411
+ #endif
1078
1412
 
1079
1413
  return ret;
1080
1414
  }
1081
1415
 
1416
+ /*
1417
+ * repalloc_extended
1418
+ * Adjust the size of a previously allocated chunk,
1419
+ * with HUGE and NO_OOM options.
1420
+ */
1421
+ #if defined(USE_ASSERT_CHECKING) || defined(USE_VALGRIND)
1422
+ #endif
1423
+
1424
+ /*
1425
+ * repalloc0
1426
+ * Adjust the size of a previously allocated chunk and zero out the added
1427
+ * space.
1428
+ */
1429
+
1430
+
1082
1431
  /*
1083
1432
  * MemoryContextAllocHuge
1084
1433
  * Allocate (possibly-expansive) space within the specified context.