pg_query 2.1.0 → 4.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (472) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +104 -0
  3. data/README.md +59 -31
  4. data/Rakefile +2 -2
  5. data/ext/pg_query/extconf.rb +8 -2
  6. data/ext/pg_query/include/access/amapi.h +45 -1
  7. data/ext/pg_query/include/access/attmap.h +1 -1
  8. data/ext/pg_query/include/access/attnum.h +2 -2
  9. data/ext/pg_query/include/access/clog.h +4 -2
  10. data/ext/pg_query/include/access/commit_ts.h +6 -9
  11. data/ext/pg_query/include/access/detoast.h +1 -11
  12. data/ext/pg_query/include/access/genam.h +15 -12
  13. data/ext/pg_query/include/access/gin.h +2 -2
  14. data/ext/pg_query/include/access/htup.h +1 -1
  15. data/ext/pg_query/include/access/htup_details.h +75 -87
  16. data/ext/pg_query/include/access/itup.h +7 -1
  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 +17 -2
  21. data/ext/pg_query/include/access/rmgr.h +30 -3
  22. data/ext/pg_query/include/access/rmgrlist.h +23 -23
  23. data/ext/pg_query/include/access/sdir.h +1 -1
  24. data/ext/pg_query/include/access/skey.h +1 -1
  25. data/ext/pg_query/include/access/stratnum.h +4 -2
  26. data/ext/pg_query/include/access/sysattr.h +1 -1
  27. data/ext/pg_query/include/access/table.h +2 -1
  28. data/ext/pg_query/include/access/tableam.h +272 -20
  29. data/ext/pg_query/include/access/toast_compression.h +73 -0
  30. data/ext/pg_query/include/access/transam.h +123 -13
  31. data/ext/pg_query/include/access/tupconvert.h +1 -1
  32. data/ext/pg_query/include/access/tupdesc.h +1 -1
  33. data/ext/pg_query/include/access/tupmacs.h +3 -3
  34. data/ext/pg_query/include/access/twophase.h +5 -1
  35. data/ext/pg_query/include/access/xact.h +79 -19
  36. data/ext/pg_query/include/access/xlog.h +60 -155
  37. data/ext/pg_query/include/access/xlog_internal.h +50 -14
  38. data/ext/pg_query/include/access/xlogdefs.h +8 -16
  39. data/ext/pg_query/include/access/xlogprefetcher.h +55 -0
  40. data/ext/pg_query/include/access/xlogreader.h +148 -32
  41. data/ext/pg_query/include/access/xlogrecord.h +18 -9
  42. data/ext/pg_query/include/access/xlogrecovery.h +157 -0
  43. data/ext/pg_query/include/c.h +101 -44
  44. data/ext/pg_query/include/catalog/catalog.h +3 -1
  45. data/ext/pg_query/include/catalog/catversion.h +2 -2
  46. data/ext/pg_query/include/catalog/dependency.h +10 -16
  47. data/ext/pg_query/include/catalog/genbki.h +83 -5
  48. data/ext/pg_query/include/catalog/index.h +18 -3
  49. data/ext/pg_query/include/catalog/indexing.h +12 -324
  50. data/ext/pg_query/include/catalog/namespace.h +4 -2
  51. data/ext/pg_query/include/catalog/objectaccess.h +70 -2
  52. data/ext/pg_query/include/catalog/objectaddress.h +11 -6
  53. data/ext/pg_query/include/catalog/pg_aggregate.h +14 -10
  54. data/ext/pg_query/include/catalog/pg_aggregate_d.h +2 -1
  55. data/ext/pg_query/include/catalog/pg_am.h +4 -1
  56. data/ext/pg_query/include/catalog/pg_am_d.h +3 -1
  57. data/ext/pg_query/include/catalog/pg_attribute.h +27 -10
  58. data/ext/pg_query/include/catalog/pg_attribute_d.h +21 -18
  59. data/ext/pg_query/include/catalog/pg_authid.h +7 -2
  60. data/ext/pg_query/include/catalog/pg_authid_d.h +17 -9
  61. data/ext/pg_query/include/catalog/pg_class.h +45 -15
  62. data/ext/pg_query/include/catalog/pg_class_d.h +31 -2
  63. data/ext/pg_query/include/catalog/pg_collation.h +33 -8
  64. data/ext/pg_query/include/catalog/pg_collation_d.h +20 -3
  65. data/ext/pg_query/include/catalog/pg_constraint.h +38 -12
  66. data/ext/pg_query/include/catalog/pg_constraint_d.h +10 -4
  67. data/ext/pg_query/include/catalog/pg_control.h +5 -5
  68. data/ext/pg_query/include/catalog/pg_conversion.h +7 -4
  69. data/ext/pg_query/include/catalog/pg_conversion_d.h +4 -1
  70. data/ext/pg_query/include/catalog/pg_depend.h +11 -7
  71. data/ext/pg_query/include/catalog/pg_depend_d.h +3 -1
  72. data/ext/pg_query/include/catalog/pg_event_trigger.h +9 -3
  73. data/ext/pg_query/include/catalog/pg_event_trigger_d.h +3 -1
  74. data/ext/pg_query/include/catalog/pg_index.h +17 -7
  75. data/ext/pg_query/include/catalog/pg_index_d.h +20 -17
  76. data/ext/pg_query/include/catalog/pg_language.h +10 -5
  77. data/ext/pg_query/include/catalog/pg_language_d.h +3 -1
  78. data/ext/pg_query/include/catalog/pg_namespace.h +7 -2
  79. data/ext/pg_query/include/catalog/pg_namespace_d.h +3 -1
  80. data/ext/pg_query/include/catalog/pg_opclass.h +8 -5
  81. data/ext/pg_query/include/catalog/pg_opclass_d.h +3 -1
  82. data/ext/pg_query/include/catalog/pg_operator.h +21 -16
  83. data/ext/pg_query/include/catalog/pg_operator_d.h +37 -1
  84. data/ext/pg_query/include/catalog/pg_opfamily.h +6 -3
  85. data/ext/pg_query/include/catalog/pg_opfamily_d.h +3 -1
  86. data/ext/pg_query/include/catalog/pg_parameter_acl.h +60 -0
  87. data/ext/pg_query/include/catalog/pg_parameter_acl_d.h +34 -0
  88. data/ext/pg_query/include/catalog/pg_partitioned_table.h +20 -9
  89. data/ext/pg_query/include/catalog/pg_partitioned_table_d.h +2 -1
  90. data/ext/pg_query/include/catalog/pg_proc.h +20 -11
  91. data/ext/pg_query/include/catalog/pg_proc_d.h +10 -8
  92. data/ext/pg_query/include/catalog/pg_publication.h +50 -4
  93. data/ext/pg_query/include/catalog/pg_publication_d.h +3 -1
  94. data/ext/pg_query/include/catalog/pg_replication_origin.h +6 -1
  95. data/ext/pg_query/include/catalog/pg_replication_origin_d.h +5 -1
  96. data/ext/pg_query/include/catalog/pg_statistic.h +19 -12
  97. data/ext/pg_query/include/catalog/pg_statistic_d.h +2 -1
  98. data/ext/pg_query/include/catalog/pg_statistic_ext.h +19 -5
  99. data/ext/pg_query/include/catalog/pg_statistic_ext_d.h +7 -2
  100. data/ext/pg_query/include/catalog/pg_transform.h +8 -5
  101. data/ext/pg_query/include/catalog/pg_transform_d.h +3 -1
  102. data/ext/pg_query/include/catalog/pg_trigger.h +24 -8
  103. data/ext/pg_query/include/catalog/pg_trigger_d.h +4 -1
  104. data/ext/pg_query/include/catalog/pg_ts_config.h +6 -3
  105. data/ext/pg_query/include/catalog/pg_ts_config_d.h +3 -1
  106. data/ext/pg_query/include/catalog/pg_ts_dict.h +8 -3
  107. data/ext/pg_query/include/catalog/pg_ts_dict_d.h +3 -1
  108. data/ext/pg_query/include/catalog/pg_ts_parser.h +6 -3
  109. data/ext/pg_query/include/catalog/pg_ts_parser_d.h +3 -1
  110. data/ext/pg_query/include/catalog/pg_ts_template.h +6 -3
  111. data/ext/pg_query/include/catalog/pg_ts_template_d.h +3 -1
  112. data/ext/pg_query/include/catalog/pg_type.h +56 -24
  113. data/ext/pg_query/include/catalog/pg_type_d.h +70 -31
  114. data/ext/pg_query/include/catalog/storage.h +5 -3
  115. data/ext/pg_query/include/commands/async.h +4 -5
  116. data/ext/pg_query/include/commands/dbcommands.h +2 -1
  117. data/ext/pg_query/include/commands/defrem.h +11 -24
  118. data/ext/pg_query/include/commands/event_trigger.h +2 -2
  119. data/ext/pg_query/include/commands/explain.h +1 -1
  120. data/ext/pg_query/include/commands/prepare.h +1 -1
  121. data/ext/pg_query/include/commands/tablespace.h +3 -1
  122. data/ext/pg_query/include/commands/trigger.h +27 -17
  123. data/ext/pg_query/include/commands/user.h +2 -2
  124. data/ext/pg_query/include/commands/vacuum.h +88 -41
  125. data/ext/pg_query/include/commands/variable.h +1 -1
  126. data/ext/pg_query/include/common/file_perm.h +4 -4
  127. data/ext/pg_query/include/common/hashfn.h +1 -1
  128. data/ext/pg_query/include/common/ip.h +1 -7
  129. data/ext/pg_query/include/common/keywords.h +2 -6
  130. data/ext/pg_query/include/common/kwlookup.h +1 -1
  131. data/ext/pg_query/include/common/pg_prng.h +60 -0
  132. data/ext/pg_query/include/common/relpath.h +2 -2
  133. data/ext/pg_query/include/common/string.h +24 -1
  134. data/ext/pg_query/include/common/unicode_combining_table.h +114 -2
  135. data/ext/pg_query/include/common/unicode_east_asian_fw_table.h +125 -0
  136. data/ext/pg_query/include/datatype/timestamp.h +40 -1
  137. data/ext/pg_query/include/executor/execdesc.h +1 -1
  138. data/ext/pg_query/include/executor/executor.h +65 -22
  139. data/ext/pg_query/include/executor/functions.h +17 -3
  140. data/ext/pg_query/include/executor/instrument.h +33 -16
  141. data/ext/pg_query/include/executor/spi.h +41 -3
  142. data/ext/pg_query/include/executor/tablefunc.h +1 -1
  143. data/ext/pg_query/include/executor/tuptable.h +1 -1
  144. data/ext/pg_query/include/fmgr.h +13 -7
  145. data/ext/pg_query/include/funcapi.h +16 -4
  146. data/ext/pg_query/include/getaddrinfo.h +1 -1
  147. data/ext/pg_query/include/jit/jit.h +11 -11
  148. data/ext/pg_query/include/kwlist_d.h +517 -494
  149. data/ext/pg_query/include/lib/dshash.h +112 -0
  150. data/ext/pg_query/include/lib/ilist.h +20 -1
  151. data/ext/pg_query/include/lib/pairingheap.h +1 -1
  152. data/ext/pg_query/include/lib/simplehash.h +150 -25
  153. data/ext/pg_query/include/lib/sort_template.h +432 -0
  154. data/ext/pg_query/include/lib/stringinfo.h +1 -1
  155. data/ext/pg_query/include/libpq/auth.h +6 -4
  156. data/ext/pg_query/include/libpq/crypt.h +5 -4
  157. data/ext/pg_query/include/libpq/hba.h +43 -4
  158. data/ext/pg_query/include/libpq/libpq-be.h +23 -6
  159. data/ext/pg_query/include/libpq/libpq.h +31 -20
  160. data/ext/pg_query/include/libpq/pqcomm.h +17 -31
  161. data/ext/pg_query/include/libpq/pqformat.h +1 -1
  162. data/ext/pg_query/include/libpq/pqsignal.h +4 -4
  163. data/ext/pg_query/include/mb/pg_wchar.h +106 -23
  164. data/ext/pg_query/include/mb/stringinfo_mb.h +1 -1
  165. data/ext/pg_query/include/miscadmin.h +71 -52
  166. data/ext/pg_query/include/nodes/bitmapset.h +1 -1
  167. data/ext/pg_query/include/nodes/execnodes.h +272 -80
  168. data/ext/pg_query/include/nodes/extensible.h +4 -2
  169. data/ext/pg_query/include/nodes/lockoptions.h +1 -1
  170. data/ext/pg_query/include/nodes/makefuncs.h +7 -6
  171. data/ext/pg_query/include/nodes/memnodes.h +5 -3
  172. data/ext/pg_query/include/nodes/nodeFuncs.h +1 -1
  173. data/ext/pg_query/include/nodes/nodes.h +30 -11
  174. data/ext/pg_query/include/nodes/params.h +1 -1
  175. data/ext/pg_query/include/nodes/parsenodes.h +327 -94
  176. data/ext/pg_query/include/nodes/pathnodes.h +245 -67
  177. data/ext/pg_query/include/nodes/pg_list.h +75 -68
  178. data/ext/pg_query/include/nodes/plannodes.h +128 -30
  179. data/ext/pg_query/include/nodes/primnodes.h +99 -47
  180. data/ext/pg_query/include/nodes/print.h +1 -1
  181. data/ext/pg_query/include/nodes/tidbitmap.h +1 -1
  182. data/ext/pg_query/include/nodes/value.h +58 -39
  183. data/ext/pg_query/include/optimizer/cost.h +9 -2
  184. data/ext/pg_query/include/optimizer/geqo.h +9 -7
  185. data/ext/pg_query/include/optimizer/geqo_gene.h +1 -1
  186. data/ext/pg_query/include/optimizer/optimizer.h +25 -22
  187. data/ext/pg_query/include/optimizer/paths.h +6 -6
  188. data/ext/pg_query/include/optimizer/planmain.h +15 -14
  189. data/ext/pg_query/include/parser/analyze.h +19 -5
  190. data/ext/pg_query/include/parser/gram.h +947 -913
  191. data/ext/pg_query/include/parser/gramparse.h +1 -1
  192. data/ext/pg_query/include/parser/kwlist.h +463 -453
  193. data/ext/pg_query/include/parser/parse_agg.h +2 -7
  194. data/ext/pg_query/include/parser/parse_coerce.h +4 -1
  195. data/ext/pg_query/include/parser/parse_expr.h +2 -3
  196. data/ext/pg_query/include/parser/parse_func.h +2 -1
  197. data/ext/pg_query/include/parser/parse_node.h +21 -9
  198. data/ext/pg_query/include/parser/parse_oper.h +1 -3
  199. data/ext/pg_query/include/parser/parse_relation.h +5 -4
  200. data/ext/pg_query/include/parser/parse_type.h +1 -1
  201. data/ext/pg_query/include/parser/parser.h +31 -4
  202. data/ext/pg_query/include/parser/parsetree.h +1 -1
  203. data/ext/pg_query/include/parser/scanner.h +1 -1
  204. data/ext/pg_query/include/parser/scansup.h +2 -5
  205. data/ext/pg_query/include/partitioning/partdefs.h +1 -1
  206. data/ext/pg_query/include/pg_config.h +94 -46
  207. data/ext/pg_query/include/pg_config_manual.h +74 -21
  208. data/ext/pg_query/include/pg_getopt.h +6 -6
  209. data/ext/pg_query/include/pg_query.h +5 -4
  210. data/ext/pg_query/include/pg_query_enum_defs.c +358 -241
  211. data/ext/pg_query/include/pg_query_fingerprint_conds.c +44 -7
  212. data/ext/pg_query/include/pg_query_fingerprint_defs.c +1220 -422
  213. data/ext/pg_query/include/pg_query_outfuncs_conds.c +43 -13
  214. data/ext/pg_query/include/pg_query_outfuncs_defs.c +152 -26
  215. data/ext/pg_query/include/pg_query_readfuncs_conds.c +11 -2
  216. data/ext/pg_query/include/pg_query_readfuncs_defs.c +174 -30
  217. data/ext/pg_query/include/pg_trace.h +1 -1
  218. data/ext/pg_query/include/pgstat.h +449 -1237
  219. data/ext/pg_query/include/pgtime.h +14 -4
  220. data/ext/pg_query/include/pl_gram.h +126 -128
  221. data/ext/pg_query/include/pl_reserved_kwlist.h +1 -1
  222. data/ext/pg_query/include/pl_reserved_kwlist_d.h +10 -10
  223. data/ext/pg_query/include/pl_unreserved_kwlist.h +2 -3
  224. data/ext/pg_query/include/pl_unreserved_kwlist_d.h +54 -56
  225. data/ext/pg_query/include/plerrcodes.h +9 -1
  226. data/ext/pg_query/include/plpgsql.h +52 -54
  227. data/ext/pg_query/include/port/atomics/arch-arm.h +7 -1
  228. data/ext/pg_query/include/port/atomics/arch-ppc.h +1 -1
  229. data/ext/pg_query/include/port/atomics/arch-x86.h +1 -1
  230. data/ext/pg_query/include/port/atomics/fallback.h +1 -1
  231. data/ext/pg_query/include/port/atomics/generic-gcc.h +3 -3
  232. data/ext/pg_query/include/port/atomics/generic.h +1 -1
  233. data/ext/pg_query/include/port/atomics.h +1 -1
  234. data/ext/pg_query/include/port/pg_bitutils.h +88 -12
  235. data/ext/pg_query/include/port/pg_bswap.h +1 -1
  236. data/ext/pg_query/include/port/pg_crc32c.h +1 -1
  237. data/ext/pg_query/include/port.h +72 -43
  238. data/ext/pg_query/include/portability/instr_time.h +1 -1
  239. data/ext/pg_query/include/postgres.h +60 -16
  240. data/ext/pg_query/include/postmaster/autovacuum.h +17 -17
  241. data/ext/pg_query/include/postmaster/auxprocess.h +20 -0
  242. data/ext/pg_query/include/postmaster/bgworker.h +2 -1
  243. data/ext/pg_query/include/postmaster/bgworker_internals.h +2 -2
  244. data/ext/pg_query/include/postmaster/bgwriter.h +5 -5
  245. data/ext/pg_query/include/postmaster/fork_process.h +1 -1
  246. data/ext/pg_query/include/postmaster/interrupt.h +1 -1
  247. data/ext/pg_query/include/postmaster/pgarch.h +42 -8
  248. data/ext/pg_query/include/postmaster/postmaster.h +18 -17
  249. data/ext/pg_query/include/postmaster/startup.h +39 -0
  250. data/ext/pg_query/include/postmaster/syslogger.h +15 -10
  251. data/ext/pg_query/include/postmaster/walwriter.h +3 -3
  252. data/ext/pg_query/include/protobuf/pg_query.pb-c.h +1422 -916
  253. data/ext/pg_query/include/protobuf/pg_query.pb.h +43678 -32769
  254. data/ext/pg_query/include/regex/regex.h +18 -16
  255. data/ext/pg_query/include/replication/logicallauncher.h +3 -5
  256. data/ext/pg_query/include/replication/logicalproto.h +161 -17
  257. data/ext/pg_query/include/replication/logicalworker.h +1 -1
  258. data/ext/pg_query/include/replication/origin.h +7 -7
  259. data/ext/pg_query/include/replication/reorderbuffer.h +262 -44
  260. data/ext/pg_query/include/replication/slot.h +23 -12
  261. data/ext/pg_query/include/replication/syncrep.h +5 -5
  262. data/ext/pg_query/include/replication/walreceiver.h +145 -13
  263. data/ext/pg_query/include/replication/walsender.h +8 -8
  264. data/ext/pg_query/include/rewrite/prs2lock.h +1 -1
  265. data/ext/pg_query/include/rewrite/rewriteHandler.h +1 -3
  266. data/ext/pg_query/include/rewrite/rewriteManip.h +1 -1
  267. data/ext/pg_query/include/rewrite/rewriteSupport.h +1 -1
  268. data/ext/pg_query/include/storage/backendid.h +3 -3
  269. data/ext/pg_query/include/storage/block.h +4 -10
  270. data/ext/pg_query/include/storage/buf.h +1 -1
  271. data/ext/pg_query/include/storage/bufmgr.h +19 -14
  272. data/ext/pg_query/include/storage/bufpage.h +6 -8
  273. data/ext/pg_query/include/storage/condition_variable.h +13 -2
  274. data/ext/pg_query/include/storage/dsm.h +4 -1
  275. data/ext/pg_query/include/storage/dsm_impl.h +3 -2
  276. data/ext/pg_query/include/storage/fd.h +33 -3
  277. data/ext/pg_query/include/storage/fileset.h +40 -0
  278. data/ext/pg_query/include/storage/ipc.h +4 -1
  279. data/ext/pg_query/include/storage/item.h +1 -1
  280. data/ext/pg_query/include/storage/itemid.h +1 -1
  281. data/ext/pg_query/include/storage/itemptr.h +3 -1
  282. data/ext/pg_query/include/storage/large_object.h +2 -2
  283. data/ext/pg_query/include/storage/latch.h +9 -13
  284. data/ext/pg_query/include/storage/lmgr.h +2 -1
  285. data/ext/pg_query/include/storage/lock.h +17 -13
  286. data/ext/pg_query/include/storage/lockdefs.h +2 -2
  287. data/ext/pg_query/include/storage/lwlock.h +6 -32
  288. data/ext/pg_query/include/storage/lwlocknames.h +0 -1
  289. data/ext/pg_query/include/storage/off.h +1 -1
  290. data/ext/pg_query/include/storage/pg_sema.h +1 -1
  291. data/ext/pg_query/include/storage/pg_shmem.h +9 -7
  292. data/ext/pg_query/include/storage/pmsignal.h +15 -4
  293. data/ext/pg_query/include/storage/predicate.h +4 -4
  294. data/ext/pg_query/include/storage/proc.h +183 -55
  295. data/ext/pg_query/include/storage/procarray.h +98 -0
  296. data/ext/pg_query/include/storage/proclist_types.h +1 -1
  297. data/ext/pg_query/include/storage/procsignal.h +3 -7
  298. data/ext/pg_query/include/storage/relfilenode.h +1 -1
  299. data/ext/pg_query/include/storage/s_lock.h +67 -4
  300. data/ext/pg_query/include/storage/sharedfileset.h +3 -11
  301. data/ext/pg_query/include/storage/shm_mq.h +5 -4
  302. data/ext/pg_query/include/storage/shm_toc.h +1 -1
  303. data/ext/pg_query/include/storage/shmem.h +1 -1
  304. data/ext/pg_query/include/storage/sinval.h +3 -3
  305. data/ext/pg_query/include/storage/sinvaladt.h +1 -1
  306. data/ext/pg_query/include/storage/smgr.h +10 -8
  307. data/ext/pg_query/include/storage/spin.h +2 -2
  308. data/ext/pg_query/include/storage/standby.h +13 -6
  309. data/ext/pg_query/include/storage/standbydefs.h +2 -2
  310. data/ext/pg_query/include/storage/sync.h +7 -3
  311. data/ext/pg_query/include/tcop/cmdtag.h +1 -1
  312. data/ext/pg_query/include/tcop/cmdtaglist.h +3 -2
  313. data/ext/pg_query/include/tcop/deparse_utility.h +1 -1
  314. data/ext/pg_query/include/tcop/dest.h +1 -1
  315. data/ext/pg_query/include/tcop/fastpath.h +1 -2
  316. data/ext/pg_query/include/tcop/pquery.h +7 -1
  317. data/ext/pg_query/include/tcop/tcopprot.h +19 -11
  318. data/ext/pg_query/include/tcop/utility.h +7 -3
  319. data/ext/pg_query/include/tsearch/ts_cache.h +2 -2
  320. data/ext/pg_query/include/utils/acl.h +24 -3
  321. data/ext/pg_query/include/utils/aclchk_internal.h +1 -1
  322. data/ext/pg_query/include/utils/array.h +7 -2
  323. data/ext/pg_query/include/utils/backend_progress.h +44 -0
  324. data/ext/pg_query/include/utils/backend_status.h +321 -0
  325. data/ext/pg_query/include/utils/builtins.h +11 -11
  326. data/ext/pg_query/include/utils/bytea.h +3 -2
  327. data/ext/pg_query/include/utils/catcache.h +1 -1
  328. data/ext/pg_query/include/utils/date.h +1 -1
  329. data/ext/pg_query/include/utils/datetime.h +8 -7
  330. data/ext/pg_query/include/utils/datum.h +9 -1
  331. data/ext/pg_query/include/utils/dsa.h +1 -1
  332. data/ext/pg_query/include/utils/dynahash.h +4 -3
  333. data/ext/pg_query/include/utils/elog.h +52 -21
  334. data/ext/pg_query/include/utils/errcodes.h +2 -0
  335. data/ext/pg_query/include/utils/expandeddatum.h +1 -1
  336. data/ext/pg_query/include/utils/expandedrecord.h +1 -1
  337. data/ext/pg_query/include/utils/float.h +7 -7
  338. data/ext/pg_query/include/utils/fmgroids.h +1300 -696
  339. data/ext/pg_query/include/utils/fmgrprotos.h +199 -16
  340. data/ext/pg_query/include/utils/fmgrtab.h +6 -5
  341. data/ext/pg_query/include/utils/guc.h +69 -43
  342. data/ext/pg_query/include/utils/guc_tables.h +23 -19
  343. data/ext/pg_query/include/utils/hsearch.h +15 -11
  344. data/ext/pg_query/include/utils/inval.h +5 -1
  345. data/ext/pg_query/include/utils/lsyscache.h +11 -1
  346. data/ext/pg_query/include/utils/memdebug.h +1 -1
  347. data/ext/pg_query/include/utils/memutils.h +8 -3
  348. data/ext/pg_query/include/utils/numeric.h +19 -5
  349. data/ext/pg_query/include/utils/palloc.h +25 -3
  350. data/ext/pg_query/include/utils/partcache.h +1 -1
  351. data/ext/pg_query/include/utils/pg_locale.h +17 -9
  352. data/ext/pg_query/include/utils/pg_lsn.h +1 -1
  353. data/ext/pg_query/include/utils/pgstat_internal.h +784 -0
  354. data/ext/pg_query/include/utils/pidfile.h +1 -1
  355. data/ext/pg_query/include/utils/plancache.h +6 -5
  356. data/ext/pg_query/include/utils/portal.h +12 -1
  357. data/ext/pg_query/include/utils/ps_status.h +1 -1
  358. data/ext/pg_query/include/utils/queryenvironment.h +1 -1
  359. data/ext/pg_query/include/utils/queryjumble.h +88 -0
  360. data/ext/pg_query/include/utils/regproc.h +14 -3
  361. data/ext/pg_query/include/utils/rel.h +71 -20
  362. data/ext/pg_query/include/utils/relcache.h +9 -7
  363. data/ext/pg_query/include/utils/reltrigger.h +1 -1
  364. data/ext/pg_query/include/utils/resowner.h +1 -1
  365. data/ext/pg_query/include/utils/rls.h +2 -2
  366. data/ext/pg_query/include/utils/ruleutils.h +4 -1
  367. data/ext/pg_query/include/utils/sharedtuplestore.h +1 -1
  368. data/ext/pg_query/include/utils/snapmgr.h +35 -14
  369. data/ext/pg_query/include/utils/snapshot.h +14 -1
  370. data/ext/pg_query/include/utils/sortsupport.h +117 -2
  371. data/ext/pg_query/include/utils/syscache.h +6 -1
  372. data/ext/pg_query/include/utils/timeout.h +11 -4
  373. data/ext/pg_query/include/utils/timestamp.h +6 -5
  374. data/ext/pg_query/include/utils/tuplesort.h +25 -11
  375. data/ext/pg_query/include/utils/tuplestore.h +2 -2
  376. data/ext/pg_query/include/utils/typcache.h +24 -17
  377. data/ext/pg_query/include/utils/tzparser.h +1 -1
  378. data/ext/pg_query/include/utils/varlena.h +5 -3
  379. data/ext/pg_query/include/utils/wait_event.h +289 -0
  380. data/ext/pg_query/include/utils/xml.h +4 -4
  381. data/ext/pg_query/pg_query.pb-c.c +4318 -2307
  382. data/ext/pg_query/pg_query_deparse.c +1114 -381
  383. data/ext/pg_query/pg_query_fingerprint.c +46 -10
  384. data/ext/pg_query/pg_query_fingerprint.h +3 -1
  385. data/ext/pg_query/pg_query_json_plpgsql.c +55 -12
  386. data/ext/pg_query/pg_query_normalize.c +163 -20
  387. data/ext/pg_query/pg_query_outfuncs.h +1 -0
  388. data/ext/pg_query/pg_query_outfuncs_json.c +65 -16
  389. data/ext/pg_query/pg_query_outfuncs_protobuf.c +70 -10
  390. data/ext/pg_query/pg_query_parse.c +1 -1
  391. data/ext/pg_query/pg_query_parse_plpgsql.c +79 -16
  392. data/ext/pg_query/pg_query_readfuncs_protobuf.c +42 -8
  393. data/ext/pg_query/pg_query_ruby.c +1 -1
  394. data/ext/pg_query/pg_query_scan.c +2 -1
  395. data/ext/pg_query/pg_query_split.c +3 -2
  396. data/ext/pg_query/src_backend_catalog_namespace.c +21 -9
  397. data/ext/pg_query/src_backend_catalog_pg_proc.c +4 -1
  398. data/ext/pg_query/src_backend_commands_define.c +11 -1
  399. data/ext/pg_query/src_backend_nodes_bitmapset.c +3 -1
  400. data/ext/pg_query/src_backend_nodes_copyfuncs.c +424 -109
  401. data/ext/pg_query/src_backend_nodes_equalfuncs.c +291 -46
  402. data/ext/pg_query/src_backend_nodes_extensible.c +1 -1
  403. data/ext/pg_query/src_backend_nodes_list.c +86 -11
  404. data/ext/pg_query/src_backend_nodes_makefuncs.c +5 -4
  405. data/ext/pg_query/src_backend_nodes_nodeFuncs.c +55 -12
  406. data/ext/pg_query/src_backend_nodes_value.c +28 -19
  407. data/ext/pg_query/src_backend_parser_gram.c +33890 -31262
  408. data/ext/pg_query/src_backend_parser_parser.c +26 -7
  409. data/ext/pg_query/src_backend_parser_scan.c +644 -441
  410. data/ext/pg_query/src_backend_parser_scansup.c +4 -28
  411. data/ext/pg_query/src_backend_postmaster_postmaster.c +77 -106
  412. data/ext/pg_query/src_backend_storage_ipc_ipc.c +13 -4
  413. data/ext/pg_query/src_backend_storage_lmgr_s_lock.c +5 -4
  414. data/ext/pg_query/src_backend_tcop_postgres.c +73 -24
  415. data/ext/pg_query/src_backend_utils_activity_pgstat_database.c +140 -0
  416. data/ext/pg_query/src_backend_utils_adt_datum.c +13 -1
  417. data/ext/pg_query/src_backend_utils_adt_expandeddatum.c +1 -1
  418. data/ext/pg_query/src_backend_utils_adt_format_type.c +6 -2
  419. data/ext/pg_query/src_backend_utils_adt_ruleutils.c +109 -15
  420. data/ext/pg_query/src_backend_utils_error_assert.c +16 -14
  421. data/ext/pg_query/src_backend_utils_error_elog.c +172 -99
  422. data/ext/pg_query/src_backend_utils_fmgr_fmgr.c +12 -17
  423. data/ext/pg_query/src_backend_utils_hash_dynahash.c +40 -10
  424. data/ext/pg_query/src_backend_utils_init_globals.c +5 -5
  425. data/ext/pg_query/src_backend_utils_mb_mbutils.c +55 -66
  426. data/ext/pg_query/src_backend_utils_misc_guc.c +207 -45
  427. data/ext/pg_query/src_backend_utils_mmgr_aset.c +7 -5
  428. data/ext/pg_query/src_backend_utils_mmgr_mcxt.c +123 -35
  429. data/ext/pg_query/src_common_encnames.c +1 -1
  430. data/ext/pg_query/src_common_hashfn.c +3 -3
  431. data/ext/pg_query/src_common_keywords.c +15 -2
  432. data/ext/pg_query/src_common_kwlist_d.h +517 -494
  433. data/ext/pg_query/src_common_kwlookup.c +1 -1
  434. data/ext/pg_query/src_common_pg_prng.c +152 -0
  435. data/ext/pg_query/src_common_psprintf.c +1 -1
  436. data/ext/pg_query/src_common_string.c +7 -1
  437. data/ext/pg_query/src_common_stringinfo.c +1 -1
  438. data/ext/pg_query/src_common_wchar.c +712 -109
  439. data/ext/pg_query/src_pl_plpgsql_src_pl_comp.c +49 -22
  440. data/ext/pg_query/src_pl_plpgsql_src_pl_funcs.c +1 -18
  441. data/ext/pg_query/src_pl_plpgsql_src_pl_gram.c +1235 -1261
  442. data/ext/pg_query/src_pl_plpgsql_src_pl_handler.c +1 -1
  443. data/ext/pg_query/src_pl_plpgsql_src_pl_reserved_kwlist_d.h +10 -10
  444. data/ext/pg_query/src_pl_plpgsql_src_pl_scanner.c +2 -2
  445. data/ext/pg_query/src_pl_plpgsql_src_pl_unreserved_kwlist_d.h +54 -56
  446. data/ext/pg_query/src_port_pg_bitutils.c +41 -52
  447. data/ext/pg_query/src_port_pgsleep.c +1 -1
  448. data/ext/pg_query/src_port_pgstrcasecmp.c +1 -1
  449. data/ext/pg_query/src_port_qsort.c +12 -224
  450. data/ext/pg_query/src_port_snprintf.c +46 -20
  451. data/ext/pg_query/src_port_strerror.c +9 -19
  452. data/ext/pg_query/src_port_strnlen.c +1 -1
  453. data/lib/pg_query/deparse.rb +7 -1
  454. data/lib/pg_query/filter_columns.rb +6 -4
  455. data/lib/pg_query/fingerprint.rb +18 -3
  456. data/lib/pg_query/node.rb +2 -2
  457. data/lib/pg_query/param_refs.rb +1 -1
  458. data/lib/pg_query/parse.rb +87 -51
  459. data/lib/pg_query/pg_query_pb.rb +1109 -942
  460. data/lib/pg_query/treewalker.rb +6 -0
  461. data/lib/pg_query/truncate.rb +54 -8
  462. data/lib/pg_query/version.rb +1 -1
  463. metadata +29 -18
  464. data/ext/pg_query/include/access/xloginsert.h +0 -64
  465. data/ext/pg_query/include/bootstrap/bootstrap.h +0 -62
  466. data/ext/pg_query/include/parser/parse_clause.h +0 -54
  467. data/ext/pg_query/include/parser/parse_collate.h +0 -27
  468. data/ext/pg_query/include/parser/parse_target.h +0 -46
  469. data/ext/pg_query/src_backend_libpq_pqcomm.c +0 -651
  470. data/ext/pg_query/src_backend_parser_parse_expr.c +0 -313
  471. data/ext/pg_query/src_port_erand48.c +0 -127
  472. data/ext/pg_query/src_port_random.c +0 -31
@@ -10,10 +10,9 @@
10
10
  /*-------------------------------------------------------------------------
11
11
  *
12
12
  * scansup.c
13
- * support routines for the lex/flex scanner, used by both the normal
14
- * backend as well as the bootstrap backend
13
+ * scanner support routines used by the core lexer
15
14
  *
16
- * Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group
15
+ * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
17
16
  * Portions Copyright (c) 1994, Regents of the University of California
18
17
  *
19
18
  *
@@ -29,19 +28,6 @@
29
28
  #include "mb/pg_wchar.h"
30
29
  #include "parser/scansup.h"
31
30
 
32
- /* ----------------
33
- * scanstr
34
- *
35
- * if the string passed in has escaped codes, map the escape codes to actual
36
- * chars
37
- *
38
- * the string returned is palloc'd and should eventually be pfree'd by the
39
- * caller!
40
- * ----------------
41
- */
42
-
43
-
44
-
45
31
 
46
32
  /*
47
33
  * downcase_truncate_identifier() --- do appropriate downcasing and
@@ -119,20 +105,10 @@ truncate_identifier(char *ident, int len, bool warn)
119
105
  {
120
106
  len = pg_mbcliplen(ident, len, NAMEDATALEN - 1);
121
107
  if (warn)
122
- {
123
- /*
124
- * We avoid using %.*s here because it can misbehave if the data
125
- * is not valid in what libc thinks is the prevailing encoding.
126
- */
127
- char buf[NAMEDATALEN];
128
-
129
- memcpy(buf, ident, len);
130
- buf[len] = '\0';
131
108
  ereport(NOTICE,
132
109
  (errcode(ERRCODE_NAME_TOO_LONG),
133
- errmsg("identifier \"%s\" will be truncated to \"%s\"",
134
- ident, buf)));
135
- }
110
+ errmsg("identifier \"%s\" will be truncated to \"%.*s\"",
111
+ ident, len, ident)));
136
112
  ident[len] = '\0';
137
113
  }
138
114
  }
@@ -38,7 +38,7 @@
38
38
  * clients.
39
39
  *
40
40
  *
41
- * Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group
41
+ * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
42
42
  * Portions Copyright (c) 1994, Regents of the University of California
43
43
  *
44
44
  *
@@ -101,21 +101,22 @@
101
101
 
102
102
  #include "access/transam.h"
103
103
  #include "access/xlog.h"
104
- #include "bootstrap/bootstrap.h"
104
+ #include "access/xlogrecovery.h"
105
105
  #include "catalog/pg_control.h"
106
106
  #include "common/file_perm.h"
107
107
  #include "common/ip.h"
108
+ #include "common/pg_prng.h"
108
109
  #include "common/string.h"
109
110
  #include "lib/ilist.h"
110
111
  #include "libpq/auth.h"
111
112
  #include "libpq/libpq.h"
112
113
  #include "libpq/pqformat.h"
113
114
  #include "libpq/pqsignal.h"
114
- #include "miscadmin.h"
115
115
  #include "pg_getopt.h"
116
116
  #include "pgstat.h"
117
117
  #include "port/pg_bswap.h"
118
118
  #include "postmaster/autovacuum.h"
119
+ #include "postmaster/auxprocess.h"
119
120
  #include "postmaster/bgworker_internals.h"
120
121
  #include "postmaster/fork_process.h"
121
122
  #include "postmaster/interrupt.h"
@@ -135,6 +136,7 @@
135
136
  #include "utils/memutils.h"
136
137
  #include "utils/pidfile.h"
137
138
  #include "utils/ps_status.h"
139
+ #include "utils/queryjumble.h"
138
140
  #include "utils/timeout.h"
139
141
  #include "utils/timestamp.h"
140
142
  #include "utils/varlena.h"
@@ -161,28 +163,32 @@
161
163
  * authorization phase). This is used mainly to keep track of how many
162
164
  * children we have and send them appropriate signals when necessary.
163
165
  *
164
- * "Special" children such as the startup, bgwriter and autovacuum launcher
165
- * tasks are not in this list. Autovacuum worker and walsender are in it.
166
+ * As shown in the above set of backend types, this list includes not only
167
+ * "normal" client sessions, but also autovacuum workers, walsenders, and
168
+ * background workers. (Note that at the time of launch, walsenders are
169
+ * labeled BACKEND_TYPE_NORMAL; we relabel them to BACKEND_TYPE_WALSND
170
+ * upon noticing they've changed their PMChildFlags entry. Hence that check
171
+ * must be done before any operation that needs to distinguish walsenders
172
+ * from normal backends.)
173
+ *
166
174
  * Also, "dead_end" children are in it: these are children launched just for
167
175
  * the purpose of sending a friendly rejection message to a would-be client.
168
176
  * We must track them because they are attached to shared memory, but we know
169
177
  * they will never become live backends. dead_end children are not assigned a
170
- * PMChildSlot.
178
+ * PMChildSlot. dead_end children have bkend_type NORMAL.
171
179
  *
172
- * Background workers are in this list, too.
180
+ * "Special" children such as the startup, bgwriter and autovacuum launcher
181
+ * tasks are not in this list. They are tracked via StartupPID and other
182
+ * pid_t variables below. (Thus, there can't be more than one of any given
183
+ * "special" child process type. We use BackendList entries for any child
184
+ * process there can be more than one of.)
173
185
  */
174
186
  typedef struct bkend
175
187
  {
176
188
  pid_t pid; /* process id of backend */
177
189
  int32 cancel_key; /* cancel key for cancels for this backend */
178
190
  int child_slot; /* PMChildSlot for this backend, if any */
179
-
180
- /*
181
- * Flavor of backend or auxiliary process. Note that BACKEND_TYPE_WALSND
182
- * backends initially announce themselves as BACKEND_TYPE_NORMAL, so if
183
- * bkend_type is normal, you should check for a recent transition.
184
- */
185
- int bkend_type;
191
+ int bkend_type; /* child process flavor, see above */
186
192
  bool dead_end; /* is it going to send an error and quit? */
187
193
  bool bgworker_notify; /* gets bgworker start/stop notifications */
188
194
  dlist_node elem; /* list link in BackendList */
@@ -222,11 +228,6 @@ static Backend *ShmemBackendArray;
222
228
  #define MAXLISTEN 64
223
229
 
224
230
 
225
- /*
226
- * Set by the -o option
227
- */
228
-
229
-
230
231
  /*
231
232
  * These globals control the behavior of the postmaster in case some
232
233
  * backend dumps core. Normally, it kills all peers of the dead backend
@@ -251,8 +252,8 @@ static Backend *ShmemBackendArray;
251
252
 
252
253
 
253
254
 
254
- /* PIDs of special child processes; 0 when not running */
255
255
 
256
+ /* PIDs of special child processes; 0 when not running */
256
257
 
257
258
 
258
259
 
@@ -349,13 +350,6 @@ typedef enum
349
350
  * connsAllowed is a sub-state indicator showing the active restriction.
350
351
  * It is of no interest unless pmState is PM_RUN or PM_HOT_STANDBY.
351
352
  */
352
- typedef enum
353
- {
354
- ALLOW_ALL_CONNS, /* normal not-shutting-down state */
355
- ALLOW_SUPERUSER_CONNS, /* only superusers can connect */
356
- ALLOW_NO_CONNS /* no new connections allowed, period */
357
- } ConnsAllowedState;
358
-
359
353
 
360
354
 
361
355
  /* Start time of SIGKILL timeout during immediate shutdown or child crash */
@@ -452,9 +446,10 @@ static void InitPostmasterDeathWatchHandle(void);
452
446
  * even during recovery.
453
447
  */
454
448
  #define PgArchStartupAllowed() \
455
- ((XLogArchivingActive() && pmState == PM_RUN) || \
456
- (XLogArchivingAlways() && \
457
- (pmState == PM_RECOVERY || pmState == PM_HOT_STANDBY)))
449
+ (((XLogArchivingActive() && pmState == PM_RUN) || \
450
+ (XLogArchivingAlways() && \
451
+ (pmState == PM_RECOVERY || pmState == PM_HOT_STANDBY))) && \
452
+ PgArchCanRestart())
458
453
 
459
454
  #ifdef EXEC_BACKEND
460
455
 
@@ -521,13 +516,13 @@ typedef struct
521
516
  PGPROC *AuxiliaryProcs;
522
517
  PGPROC *PreparedXactProcs;
523
518
  PMSignalData *PMSignalState;
524
- InheritableSocket pgStatSock;
525
519
  pid_t PostmasterPid;
526
520
  TimestampTz PgStartTime;
527
521
  TimestampTz PgReloadTime;
528
522
  pg_time_t first_syslogger_file_time;
529
523
  bool redirection_done;
530
524
  bool IsBinaryUpgrade;
525
+ bool query_id_enabled;
531
526
  int max_safe_fds;
532
527
  int MaxBackends;
533
528
  #ifdef WIN32
@@ -540,7 +535,6 @@ typedef struct
540
535
  #endif
541
536
  char my_exec_path[MAXPGPATH];
542
537
  char pkglib_path[MAXPGPATH];
543
- char ExtraOptions[MAXPGPATH];
544
538
  } BackendParameters;
545
539
 
546
540
  static void read_backend_variables(char *id, Port *port);
@@ -558,6 +552,7 @@ static void ShmemBackendArrayRemove(Backend *bn);
558
552
  #endif /* EXEC_BACKEND */
559
553
 
560
554
  #define StartupDataBase() StartChildProcess(StartupProcess)
555
+ #define StartArchiver() StartChildProcess(ArchiverProcess)
561
556
  #define StartBackgroundWriter() StartChildProcess(BgWriterProcess)
562
557
  #define StartCheckpointer() StartChildProcess(CheckpointerProcess)
563
558
  #define StartWalWriter() StartChildProcess(WalWriterProcess)
@@ -582,6 +577,10 @@ HANDLE PostmasterHandle;
582
577
  /*
583
578
  * Postmaster main entry point
584
579
  */
580
+ #ifdef WIN32
581
+ #endif
582
+ #ifdef SIGURG
583
+ #endif
585
584
  #ifdef SIGTTIN
586
585
  #endif
587
586
  #ifdef SIGTTOU
@@ -764,7 +763,8 @@ HANDLE PostmasterHandle;
764
763
  *
765
764
  * Called early in the postmaster and every backend.
766
765
  */
767
-
766
+ #ifndef WIN32
767
+ #endif
768
768
 
769
769
 
770
770
  /*
@@ -838,7 +838,7 @@ HANDLE PostmasterHandle;
838
838
 
839
839
  /*
840
840
  * HandleChildCrash -- cleanup after failed backend, bgwriter, checkpointer,
841
- * walwriter, autovacuum, or background worker.
841
+ * walwriter, autovacuum, archiver or background worker.
842
842
  *
843
843
  * The objectives here are to clean up our local state about the child
844
844
  * process, and to signal all other remaining children to quickdie.
@@ -926,6 +926,8 @@ HANDLE PostmasterHandle;
926
926
  * returns: nothing. Will not return at all if there's any failure.
927
927
  *
928
928
  * Note: this code does not depend on having any access to shared memory.
929
+ * Indeed, our approach to SIGTERM/timeout handling *requires* that
930
+ * shared memory not have been touched yet; see comments within.
929
931
  * In the EXEC_BACKEND case, we are physically attached to shared memory
930
932
  * but have not yet set up most of our local pointers to shmem structures.
931
933
  */
@@ -936,8 +938,7 @@ HANDLE PostmasterHandle;
936
938
  * BackendRun -- set up the backend's argument list and invoke PostgresMain()
937
939
  *
938
940
  * returns:
939
- * Shouldn't return at all.
940
- * If PostgresMain() fails, return status.
941
+ * Doesn't return at all.
941
942
  */
942
943
 
943
944
 
@@ -1127,16 +1128,18 @@ retry:
1127
1128
  NULL);
1128
1129
  if (paramHandle == INVALID_HANDLE_VALUE)
1129
1130
  {
1130
- elog(LOG, "could not create backend parameter file mapping: error code %lu",
1131
- GetLastError());
1131
+ ereport(LOG,
1132
+ (errmsg("could not create backend parameter file mapping: error code %lu",
1133
+ GetLastError())));
1132
1134
  return -1;
1133
1135
  }
1134
1136
 
1135
1137
  param = MapViewOfFile(paramHandle, FILE_MAP_WRITE, 0, 0, sizeof(BackendParameters));
1136
1138
  if (!param)
1137
1139
  {
1138
- elog(LOG, "could not map backend parameter memory: error code %lu",
1139
- GetLastError());
1140
+ ereport(LOG,
1141
+ (errmsg("could not map backend parameter memory: error code %lu",
1142
+ GetLastError())));
1140
1143
  CloseHandle(paramHandle);
1141
1144
  return -1;
1142
1145
  }
@@ -1161,7 +1164,8 @@ retry:
1161
1164
  }
1162
1165
  if (cmdLine[sizeof(cmdLine) - 2] != '\0')
1163
1166
  {
1164
- elog(LOG, "subprocess command line too long");
1167
+ ereport(LOG,
1168
+ (errmsg("subprocess command line too long")));
1165
1169
  UnmapViewOfFile(param);
1166
1170
  CloseHandle(paramHandle);
1167
1171
  return -1;
@@ -1178,8 +1182,9 @@ retry:
1178
1182
  if (!CreateProcess(NULL, cmdLine, NULL, NULL, TRUE, CREATE_SUSPENDED,
1179
1183
  NULL, NULL, &si, &pi))
1180
1184
  {
1181
- elog(LOG, "CreateProcess call failed: %m (error code %lu)",
1182
- GetLastError());
1185
+ ereport(LOG,
1186
+ (errmsg("CreateProcess() call failed: %m (error code %lu)",
1187
+ GetLastError())));
1183
1188
  UnmapViewOfFile(param);
1184
1189
  CloseHandle(paramHandle);
1185
1190
  return -1;
@@ -1204,11 +1209,13 @@ retry:
1204
1209
 
1205
1210
  /* Drop the parameter shared memory that is now inherited to the backend */
1206
1211
  if (!UnmapViewOfFile(param))
1207
- elog(LOG, "could not unmap view of backend parameter file: error code %lu",
1208
- GetLastError());
1212
+ ereport(LOG,
1213
+ (errmsg("could not unmap view of backend parameter file: error code %lu",
1214
+ GetLastError())));
1209
1215
  if (!CloseHandle(paramHandle))
1210
- elog(LOG, "could not close handle to backend parameter file: error code %lu",
1211
- GetLastError());
1216
+ ereport(LOG,
1217
+ (errmsg("could not close handle to backend parameter file: error code %lu",
1218
+ GetLastError())));
1212
1219
 
1213
1220
  /*
1214
1221
  * Reserve the memory region used by our main shared memory segment before
@@ -1314,9 +1321,6 @@ SubPostmasterMain(int argc, char *argv[])
1314
1321
  IsPostmasterEnvironment = true;
1315
1322
  whereToSendOutput = DestNone;
1316
1323
 
1317
- /* Setup as postmaster child */
1318
- InitPostmasterChild();
1319
-
1320
1324
  /* Setup essential subsystems (to ensure elog() behaves sanely) */
1321
1325
  InitializeGUCOptions();
1322
1326
 
@@ -1331,6 +1335,9 @@ SubPostmasterMain(int argc, char *argv[])
1331
1335
  /* Close the postmaster's sockets (as soon as we know them) */
1332
1336
  ClosePostmasterPorts(strcmp(argv[1], "--forklog") == 0);
1333
1337
 
1338
+ /* Setup as postmaster child */
1339
+ InitPostmasterChild();
1340
+
1334
1341
  /*
1335
1342
  * If appropriate, physically re-attach to shared memory segment. We want
1336
1343
  * to do this before going any further to ensure that we can attach at the
@@ -1340,7 +1347,7 @@ SubPostmasterMain(int argc, char *argv[])
1340
1347
  * If testing EXEC_BACKEND on Linux, you should run this as root before
1341
1348
  * starting the postmaster:
1342
1349
  *
1343
- * echo 0 >/proc/sys/kernel/randomize_va_space
1350
+ * sysctl -w kernel.randomize_va_space=0
1344
1351
  *
1345
1352
  * This prevents using randomized stack and code addresses that cause the
1346
1353
  * child process's memory map to be different from the parent's, making it
@@ -1350,7 +1357,7 @@ SubPostmasterMain(int argc, char *argv[])
1350
1357
  if (strcmp(argv[1], "--forkbackend") == 0 ||
1351
1358
  strcmp(argv[1], "--forkavlauncher") == 0 ||
1352
1359
  strcmp(argv[1], "--forkavworker") == 0 ||
1353
- strcmp(argv[1], "--forkboot") == 0 ||
1360
+ strcmp(argv[1], "--forkaux") == 0 ||
1354
1361
  strncmp(argv[1], "--forkbgworker=", 15) == 0)
1355
1362
  PGSharedMemoryReAttach();
1356
1363
  else
@@ -1362,19 +1369,6 @@ SubPostmasterMain(int argc, char *argv[])
1362
1369
  if (strcmp(argv[1], "--forkavworker") == 0)
1363
1370
  AutovacuumWorkerIAm();
1364
1371
 
1365
- /*
1366
- * Start our win32 signal implementation. This has to be done after we
1367
- * read the backend variables, because we need to pick up the signal pipe
1368
- * from the parent process.
1369
- */
1370
- #ifdef WIN32
1371
- pgwin32_signal_initialize();
1372
- #endif
1373
-
1374
- /* In EXEC_BACKEND case we will not have inherited these settings */
1375
- pqinitmask();
1376
- PG_SETMASK(&BlockSig);
1377
-
1378
1372
  /* Read in remaining GUC variables */
1379
1373
  read_nondefault_variables();
1380
1374
 
@@ -1451,8 +1445,12 @@ SubPostmasterMain(int argc, char *argv[])
1451
1445
  /* And run the backend */
1452
1446
  BackendRun(&port); /* does not return */
1453
1447
  }
1454
- if (strcmp(argv[1], "--forkboot") == 0)
1448
+ if (strcmp(argv[1], "--forkaux") == 0)
1455
1449
  {
1450
+ AuxProcType auxtype;
1451
+
1452
+ Assert(argc == 4);
1453
+
1456
1454
  /* Restore basic shared memory pointers */
1457
1455
  InitShmemAccess(UsedShmemSegAddr);
1458
1456
 
@@ -1462,7 +1460,8 @@ SubPostmasterMain(int argc, char *argv[])
1462
1460
  /* Attach process to shared data structures */
1463
1461
  CreateSharedMemoryAndSemaphores();
1464
1462
 
1465
- AuxiliaryProcessMain(argc - 2, argv + 2); /* does not return */
1463
+ auxtype = atoi(argv[3]);
1464
+ AuxiliaryProcessMain(auxtype); /* does not return */
1466
1465
  }
1467
1466
  if (strcmp(argv[1], "--forkavlauncher") == 0)
1468
1467
  {
@@ -1512,18 +1511,6 @@ SubPostmasterMain(int argc, char *argv[])
1512
1511
 
1513
1512
  StartBackgroundWorker();
1514
1513
  }
1515
- if (strcmp(argv[1], "--forkarch") == 0)
1516
- {
1517
- /* Do not want to attach to shared memory */
1518
-
1519
- PgArchiverMain(argc, argv); /* does not return */
1520
- }
1521
- if (strcmp(argv[1], "--forkcol") == 0)
1522
- {
1523
- /* Do not want to attach to shared memory */
1524
-
1525
- PgstatCollectorMain(argc, argv); /* does not return */
1526
- }
1527
1514
  if (strcmp(argv[1], "--forklog") == 0)
1528
1515
  {
1529
1516
  /* Do not want to attach to shared memory */
@@ -1558,18 +1545,16 @@ SubPostmasterMain(int argc, char *argv[])
1558
1545
 
1559
1546
  /*
1560
1547
  * SIGTERM while processing startup packet.
1561
- * Clean up and exit(1).
1562
1548
  *
1563
- * Running proc_exit() from a signal handler is pretty unsafe, since we
1564
- * can't know what code we've interrupted. But the alternative of using
1565
- * _exit(2) is also unpalatable, since it'd mean that a "fast shutdown"
1566
- * would cause a database crash cycle (forcing WAL replay at restart)
1567
- * if any sessions are in authentication. So we live with it for now.
1549
+ * Running proc_exit() from a signal handler would be quite unsafe.
1550
+ * However, since we have not yet touched shared memory, we can just
1551
+ * pull the plug and exit without running any atexit handlers.
1568
1552
  *
1569
- * One might be tempted to try to send a message indicating why we are
1570
- * disconnecting. However, that would make this even more unsafe. Also,
1571
- * it seems undesirable to provide clues about the database's state to
1572
- * a client that has not yet completed authentication.
1553
+ * One might be tempted to try to send a message, or log one, indicating
1554
+ * why we are disconnecting. However, that would be quite unsafe in itself.
1555
+ * Also, it seems undesirable to provide clues about the database's state
1556
+ * to a client that has not yet completed authentication, or even sent us
1557
+ * a startup packet.
1573
1558
  */
1574
1559
 
1575
1560
 
@@ -1586,11 +1571,7 @@ SubPostmasterMain(int argc, char *argv[])
1586
1571
 
1587
1572
  /*
1588
1573
  * Timeout while processing startup packet.
1589
- * As for process_startup_packet_die(), we clean up and exit(1).
1590
- *
1591
- * This is theoretically just as hazardous as in process_startup_packet_die(),
1592
- * although in practice we're almost certainly waiting for client input,
1593
- * which greatly reduces the risk.
1574
+ * As for process_startup_packet_die(), we exit via _exit(1).
1594
1575
  */
1595
1576
 
1596
1577
 
@@ -1617,8 +1598,6 @@ SubPostmasterMain(int argc, char *argv[])
1617
1598
  * to start subprocess.
1618
1599
  */
1619
1600
  #ifdef EXEC_BACKEND
1620
- #endif
1621
- #ifdef EXEC_BACKEND
1622
1601
  #else /* !EXEC_BACKEND */
1623
1602
  #endif /* EXEC_BACKEND */
1624
1603
 
@@ -1769,7 +1748,6 @@ extern slock_t *ShmemLock;
1769
1748
  extern slock_t *ProcStructLock;
1770
1749
  extern PGPROC *AuxiliaryProcs;
1771
1750
  extern PMSignalData *PMSignalState;
1772
- extern pgsocket pgStatSock;
1773
1751
  extern pg_time_t first_syslogger_file_time;
1774
1752
 
1775
1753
  #ifndef WIN32
@@ -1825,8 +1803,6 @@ save_backend_variables(BackendParameters *param, Port *port,
1825
1803
  param->AuxiliaryProcs = AuxiliaryProcs;
1826
1804
  param->PreparedXactProcs = PreparedXactProcs;
1827
1805
  param->PMSignalState = PMSignalState;
1828
- if (!write_inheritable_socket(&param->pgStatSock, pgStatSock, childPid))
1829
- return false;
1830
1806
 
1831
1807
  param->PostmasterPid = PostmasterPid;
1832
1808
  param->PgStartTime = PgStartTime;
@@ -1835,6 +1811,7 @@ save_backend_variables(BackendParameters *param, Port *port,
1835
1811
 
1836
1812
  param->redirection_done = redirection_done;
1837
1813
  param->IsBinaryUpgrade = IsBinaryUpgrade;
1814
+ param->query_id_enabled = query_id_enabled;
1838
1815
  param->max_safe_fds = max_safe_fds;
1839
1816
 
1840
1817
  param->MaxBackends = MaxBackends;
@@ -1856,8 +1833,6 @@ save_backend_variables(BackendParameters *param, Port *port,
1856
1833
 
1857
1834
  strlcpy(param->pkglib_path, pkglib_path, MAXPGPATH);
1858
1835
 
1859
- strlcpy(param->ExtraOptions, ExtraOptions, MAXPGPATH);
1860
-
1861
1836
  return true;
1862
1837
  }
1863
1838
 
@@ -2061,7 +2036,6 @@ restore_backend_variables(BackendParameters *param, Port *port)
2061
2036
  AuxiliaryProcs = param->AuxiliaryProcs;
2062
2037
  PreparedXactProcs = param->PreparedXactProcs;
2063
2038
  PMSignalState = param->PMSignalState;
2064
- read_inheritable_socket(&pgStatSock, &param->pgStatSock);
2065
2039
 
2066
2040
  PostmasterPid = param->PostmasterPid;
2067
2041
  PgStartTime = param->PgStartTime;
@@ -2070,6 +2044,7 @@ restore_backend_variables(BackendParameters *param, Port *port)
2070
2044
 
2071
2045
  redirection_done = param->redirection_done;
2072
2046
  IsBinaryUpgrade = param->IsBinaryUpgrade;
2047
+ query_id_enabled = param->query_id_enabled;
2073
2048
  max_safe_fds = param->max_safe_fds;
2074
2049
 
2075
2050
  MaxBackends = param->MaxBackends;
@@ -2088,8 +2063,6 @@ restore_backend_variables(BackendParameters *param, Port *port)
2088
2063
 
2089
2064
  strlcpy(pkglib_path, param->pkglib_path, MAXPGPATH);
2090
2065
 
2091
- strlcpy(ExtraOptions, param->ExtraOptions, MAXPGPATH);
2092
-
2093
2066
  /*
2094
2067
  * We need to restore fd.c's counts of externally-opened FDs; to avoid
2095
2068
  * confusion, be sure to do this after restoring max_safe_fds. (Note:
@@ -2101,8 +2074,6 @@ restore_backend_variables(BackendParameters *param, Port *port)
2101
2074
  if (postmaster_alive_fds[1] >= 0)
2102
2075
  ReserveExternalFD();
2103
2076
  #endif
2104
- if (pgStatSock != PGINVALID_SOCKET)
2105
- ReserveExternalFD();
2106
2077
  }
2107
2078
 
2108
2079
 
@@ -15,7 +15,7 @@
15
15
  * exit-time cleanup for either a postmaster or a backend.
16
16
  *
17
17
  *
18
- * Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group
18
+ * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
19
19
  * Portions Copyright (c) 1994, Regents of the University of California
20
20
  *
21
21
  *
@@ -173,9 +173,9 @@ void proc_exit(int code) { printf("Terminating process due to FATAL error\n"); e
173
173
  * cancel_before_shmem_exit
174
174
  *
175
175
  * this function removes a previously-registered before_shmem_exit
176
- * callback. For simplicity, only the latest entry can be
177
- * removed. (We could work harder but there is no need for
178
- * current uses.)
176
+ * callback. We only look at the latest entry for removal, as we
177
+ * expect callers to add and remove temporary before_shmem_exit
178
+ * callbacks in strict LIFO order.
179
179
  * ----------------------------------------------------------------
180
180
  */
181
181
 
@@ -190,3 +190,12 @@ void proc_exit(int code) { printf("Terminating process due to FATAL error\n"); e
190
190
  * ----------------------------------------------------------------
191
191
  */
192
192
 
193
+
194
+ /* ----------------------------------------------------------------
195
+ * check_on_shmem_exit_lists_are_empty
196
+ *
197
+ * Debugging check that no shmem cleanup handlers have been registered
198
+ * prematurely in the current process.
199
+ * ----------------------------------------------------------------
200
+ */
201
+
@@ -46,7 +46,7 @@
46
46
  * the probability of unintended failure) than to fix the total time
47
47
  * spent.
48
48
  *
49
- * Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group
49
+ * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
50
50
  * Portions Copyright (c) 1994, Regents of the University of California
51
51
  *
52
52
  *
@@ -60,6 +60,7 @@
60
60
  #include <time.h>
61
61
  #include <unistd.h>
62
62
 
63
+ #include "common/pg_prng.h"
63
64
  #include "port/atomics.h"
64
65
  #include "storage/s_lock.h"
65
66
 
@@ -155,7 +156,7 @@ perform_spin_delay(SpinDelayStatus *status)
155
156
 
156
157
  /* increase delay by a random fraction between 1X and 2X */
157
158
  status->cur_delay += (int) (status->cur_delay *
158
- ((double) random() / (double) MAX_RANDOM_VALUE) + 0.5);
159
+ pg_prng_double(&pg_global_prng_state) + 0.5);
159
160
  /* wrap back to minimum delay when max is exceeded */
160
161
  if (status->cur_delay > MAX_DELAY_USEC)
161
162
  status->cur_delay = MIN_DELAY_USEC;
@@ -296,7 +297,7 @@ volatile struct test_lock_struct test_lock;
296
297
  int
297
298
  main()
298
299
  {
299
- srandom((unsigned int) time(NULL));
300
+ pg_prng_seed(&pg_global_prng_state, (uint64) time(NULL));
300
301
 
301
302
  test_lock.pad1 = test_lock.pad2 = 0x44;
302
303
 
@@ -361,7 +362,7 @@ main()
361
362
  printf(" if S_LOCK() and TAS() are working.\n");
362
363
  fflush(stdout);
363
364
 
364
- s_lock(&test_lock.lock, __FILE__, __LINE__);
365
+ s_lock(&test_lock.lock, __FILE__, __LINE__, PG_FUNCNAME_MACRO);
365
366
 
366
367
  printf("S_LOCK_TEST: failed, lock not locked\n");
367
368
  return 1;