gitlab-pg_query 1.3.1 → 2.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +217 -99
- data/README.md +92 -69
- data/Rakefile +85 -5
- data/ext/pg_query/extconf.rb +3 -40
- data/ext/pg_query/guc-file.c +0 -0
- data/ext/pg_query/include/access/amapi.h +246 -0
- data/ext/pg_query/include/access/attmap.h +52 -0
- data/ext/pg_query/include/access/attnum.h +64 -0
- data/ext/pg_query/include/access/clog.h +61 -0
- data/ext/pg_query/include/access/commit_ts.h +77 -0
- data/ext/pg_query/include/access/detoast.h +92 -0
- data/ext/pg_query/include/access/genam.h +228 -0
- data/ext/pg_query/include/access/gin.h +78 -0
- data/ext/pg_query/include/access/htup.h +89 -0
- data/ext/pg_query/include/access/htup_details.h +819 -0
- data/ext/pg_query/include/access/itup.h +161 -0
- data/ext/pg_query/include/access/parallel.h +82 -0
- data/ext/pg_query/include/access/printtup.h +35 -0
- data/ext/pg_query/include/access/relation.h +28 -0
- data/ext/pg_query/include/access/relscan.h +176 -0
- data/ext/pg_query/include/access/rmgr.h +35 -0
- data/ext/pg_query/include/access/rmgrlist.h +49 -0
- data/ext/pg_query/include/access/sdir.h +58 -0
- data/ext/pg_query/include/access/skey.h +151 -0
- data/ext/pg_query/include/access/stratnum.h +83 -0
- data/ext/pg_query/include/access/sysattr.h +29 -0
- data/ext/pg_query/include/access/table.h +27 -0
- data/ext/pg_query/include/access/tableam.h +1825 -0
- data/ext/pg_query/include/access/transam.h +265 -0
- data/ext/pg_query/include/access/tupconvert.h +51 -0
- data/ext/pg_query/include/access/tupdesc.h +154 -0
- data/ext/pg_query/include/access/tupmacs.h +247 -0
- data/ext/pg_query/include/access/twophase.h +61 -0
- data/ext/pg_query/include/access/xact.h +463 -0
- data/ext/pg_query/include/access/xlog.h +398 -0
- data/ext/pg_query/include/access/xlog_internal.h +330 -0
- data/ext/pg_query/include/access/xlogdefs.h +109 -0
- data/ext/pg_query/include/access/xloginsert.h +64 -0
- data/ext/pg_query/include/access/xlogreader.h +327 -0
- data/ext/pg_query/include/access/xlogrecord.h +227 -0
- data/ext/pg_query/include/bootstrap/bootstrap.h +62 -0
- data/ext/pg_query/include/c.h +1322 -0
- data/ext/pg_query/include/catalog/catalog.h +42 -0
- data/ext/pg_query/include/catalog/catversion.h +58 -0
- data/ext/pg_query/include/catalog/dependency.h +275 -0
- data/ext/pg_query/include/catalog/genbki.h +64 -0
- data/ext/pg_query/include/catalog/index.h +199 -0
- data/ext/pg_query/include/catalog/indexing.h +366 -0
- data/ext/pg_query/include/catalog/namespace.h +188 -0
- data/ext/pg_query/include/catalog/objectaccess.h +197 -0
- data/ext/pg_query/include/catalog/objectaddress.h +84 -0
- data/ext/pg_query/include/catalog/pg_aggregate.h +176 -0
- data/ext/pg_query/include/catalog/pg_aggregate_d.h +77 -0
- data/ext/pg_query/include/catalog/pg_am.h +60 -0
- data/ext/pg_query/include/catalog/pg_am_d.h +45 -0
- data/ext/pg_query/include/catalog/pg_attribute.h +204 -0
- data/ext/pg_query/include/catalog/pg_attribute_d.h +59 -0
- data/ext/pg_query/include/catalog/pg_authid.h +58 -0
- data/ext/pg_query/include/catalog/pg_authid_d.h +49 -0
- data/ext/pg_query/include/catalog/pg_class.h +200 -0
- data/ext/pg_query/include/catalog/pg_class_d.h +103 -0
- data/ext/pg_query/include/catalog/pg_collation.h +73 -0
- data/ext/pg_query/include/catalog/pg_collation_d.h +45 -0
- data/ext/pg_query/include/catalog/pg_constraint.h +247 -0
- data/ext/pg_query/include/catalog/pg_constraint_d.h +67 -0
- data/ext/pg_query/include/catalog/pg_control.h +250 -0
- data/ext/pg_query/include/catalog/pg_conversion.h +72 -0
- data/ext/pg_query/include/catalog/pg_conversion_d.h +35 -0
- data/ext/pg_query/include/catalog/pg_depend.h +73 -0
- data/ext/pg_query/include/catalog/pg_depend_d.h +34 -0
- data/ext/pg_query/include/catalog/pg_event_trigger.h +51 -0
- data/ext/pg_query/include/catalog/pg_event_trigger_d.h +34 -0
- data/ext/pg_query/include/catalog/pg_index.h +80 -0
- data/ext/pg_query/include/catalog/pg_index_d.h +56 -0
- data/ext/pg_query/include/catalog/pg_language.h +67 -0
- data/ext/pg_query/include/catalog/pg_language_d.h +39 -0
- data/ext/pg_query/include/catalog/pg_namespace.h +59 -0
- data/ext/pg_query/include/catalog/pg_namespace_d.h +34 -0
- data/ext/pg_query/include/catalog/pg_opclass.h +85 -0
- data/ext/pg_query/include/catalog/pg_opclass_d.h +49 -0
- data/ext/pg_query/include/catalog/pg_operator.h +102 -0
- data/ext/pg_query/include/catalog/pg_operator_d.h +106 -0
- data/ext/pg_query/include/catalog/pg_opfamily.h +60 -0
- data/ext/pg_query/include/catalog/pg_opfamily_d.h +47 -0
- data/ext/pg_query/include/catalog/pg_partitioned_table.h +63 -0
- data/ext/pg_query/include/catalog/pg_partitioned_table_d.h +35 -0
- data/ext/pg_query/include/catalog/pg_proc.h +211 -0
- data/ext/pg_query/include/catalog/pg_proc_d.h +99 -0
- data/ext/pg_query/include/catalog/pg_publication.h +115 -0
- data/ext/pg_query/include/catalog/pg_publication_d.h +36 -0
- data/ext/pg_query/include/catalog/pg_replication_origin.h +57 -0
- data/ext/pg_query/include/catalog/pg_replication_origin_d.h +29 -0
- data/ext/pg_query/include/catalog/pg_statistic.h +275 -0
- data/ext/pg_query/include/catalog/pg_statistic_d.h +194 -0
- data/ext/pg_query/include/catalog/pg_statistic_ext.h +74 -0
- data/ext/pg_query/include/catalog/pg_statistic_ext_d.h +40 -0
- data/ext/pg_query/include/catalog/pg_transform.h +45 -0
- data/ext/pg_query/include/catalog/pg_transform_d.h +32 -0
- data/ext/pg_query/include/catalog/pg_trigger.h +137 -0
- data/ext/pg_query/include/catalog/pg_trigger_d.h +106 -0
- data/ext/pg_query/include/catalog/pg_ts_config.h +50 -0
- data/ext/pg_query/include/catalog/pg_ts_config_d.h +32 -0
- data/ext/pg_query/include/catalog/pg_ts_dict.h +54 -0
- data/ext/pg_query/include/catalog/pg_ts_dict_d.h +33 -0
- data/ext/pg_query/include/catalog/pg_ts_parser.h +57 -0
- data/ext/pg_query/include/catalog/pg_ts_parser_d.h +35 -0
- data/ext/pg_query/include/catalog/pg_ts_template.h +48 -0
- data/ext/pg_query/include/catalog/pg_ts_template_d.h +32 -0
- data/ext/pg_query/include/catalog/pg_type.h +372 -0
- data/ext/pg_query/include/catalog/pg_type_d.h +285 -0
- data/ext/pg_query/include/catalog/storage.h +48 -0
- data/ext/pg_query/include/commands/async.h +54 -0
- data/ext/pg_query/include/commands/dbcommands.h +35 -0
- data/ext/pg_query/include/commands/defrem.h +173 -0
- data/ext/pg_query/include/commands/event_trigger.h +88 -0
- data/ext/pg_query/include/commands/explain.h +127 -0
- data/ext/pg_query/include/commands/prepare.h +61 -0
- data/ext/pg_query/include/commands/tablespace.h +67 -0
- data/ext/pg_query/include/commands/trigger.h +277 -0
- data/ext/pg_query/include/commands/user.h +37 -0
- data/ext/pg_query/include/commands/vacuum.h +293 -0
- data/ext/pg_query/include/commands/variable.h +38 -0
- data/ext/pg_query/include/common/file_perm.h +56 -0
- data/ext/pg_query/include/common/hashfn.h +104 -0
- data/ext/pg_query/include/common/ip.h +37 -0
- data/ext/pg_query/include/common/keywords.h +33 -0
- data/ext/pg_query/include/common/kwlookup.h +44 -0
- data/ext/pg_query/include/common/relpath.h +90 -0
- data/ext/pg_query/include/common/string.h +19 -0
- data/ext/pg_query/include/common/unicode_combining_table.h +196 -0
- data/ext/pg_query/include/datatype/timestamp.h +197 -0
- data/ext/pg_query/include/executor/execdesc.h +70 -0
- data/ext/pg_query/include/executor/executor.h +614 -0
- data/ext/pg_query/include/executor/functions.h +41 -0
- data/ext/pg_query/include/executor/instrument.h +101 -0
- data/ext/pg_query/include/executor/spi.h +175 -0
- data/ext/pg_query/include/executor/tablefunc.h +67 -0
- data/ext/pg_query/include/executor/tuptable.h +487 -0
- data/ext/pg_query/include/fmgr.h +775 -0
- data/ext/pg_query/include/funcapi.h +348 -0
- data/ext/pg_query/include/getaddrinfo.h +162 -0
- data/ext/pg_query/include/jit/jit.h +105 -0
- data/ext/pg_query/include/kwlist_d.h +1072 -0
- data/ext/pg_query/include/lib/ilist.h +727 -0
- data/ext/pg_query/include/lib/pairingheap.h +102 -0
- data/ext/pg_query/include/lib/simplehash.h +1059 -0
- data/ext/pg_query/include/lib/stringinfo.h +161 -0
- data/ext/pg_query/include/libpq/auth.h +29 -0
- data/ext/pg_query/include/libpq/crypt.h +46 -0
- data/ext/pg_query/include/libpq/hba.h +140 -0
- data/ext/pg_query/include/libpq/libpq-be.h +326 -0
- data/ext/pg_query/include/libpq/libpq.h +133 -0
- data/ext/pg_query/include/libpq/pqcomm.h +208 -0
- data/ext/pg_query/include/libpq/pqformat.h +210 -0
- data/ext/pg_query/include/libpq/pqsignal.h +42 -0
- data/ext/pg_query/include/mb/pg_wchar.h +672 -0
- data/ext/pg_query/include/mb/stringinfo_mb.h +24 -0
- data/ext/pg_query/include/miscadmin.h +476 -0
- data/ext/pg_query/include/nodes/bitmapset.h +122 -0
- data/ext/pg_query/include/nodes/execnodes.h +2520 -0
- data/ext/pg_query/include/nodes/extensible.h +160 -0
- data/ext/pg_query/include/nodes/lockoptions.h +61 -0
- data/ext/pg_query/include/nodes/makefuncs.h +108 -0
- data/ext/pg_query/include/nodes/memnodes.h +108 -0
- data/ext/pg_query/include/nodes/nodeFuncs.h +162 -0
- data/ext/pg_query/include/nodes/nodes.h +842 -0
- data/ext/pg_query/include/nodes/params.h +170 -0
- data/ext/pg_query/include/nodes/parsenodes.h +3579 -0
- data/ext/pg_query/include/nodes/pathnodes.h +2556 -0
- data/ext/pg_query/include/nodes/pg_list.h +605 -0
- data/ext/pg_query/include/nodes/plannodes.h +1251 -0
- data/ext/pg_query/include/nodes/primnodes.h +1541 -0
- data/ext/pg_query/include/nodes/print.h +34 -0
- data/ext/pg_query/include/nodes/tidbitmap.h +75 -0
- data/ext/pg_query/include/nodes/value.h +61 -0
- data/ext/pg_query/include/optimizer/cost.h +206 -0
- data/ext/pg_query/include/optimizer/geqo.h +88 -0
- data/ext/pg_query/include/optimizer/geqo_gene.h +45 -0
- data/ext/pg_query/include/optimizer/optimizer.h +199 -0
- data/ext/pg_query/include/optimizer/paths.h +249 -0
- data/ext/pg_query/include/optimizer/planmain.h +119 -0
- data/ext/pg_query/include/parser/analyze.h +49 -0
- data/ext/pg_query/include/parser/gram.h +1067 -0
- data/ext/pg_query/include/parser/gramparse.h +75 -0
- data/ext/pg_query/include/parser/kwlist.h +477 -0
- data/ext/pg_query/include/parser/parse_agg.h +68 -0
- data/ext/pg_query/include/parser/parse_clause.h +54 -0
- data/ext/pg_query/include/parser/parse_coerce.h +97 -0
- data/ext/pg_query/include/parser/parse_collate.h +27 -0
- data/ext/pg_query/include/parser/parse_expr.h +26 -0
- data/ext/pg_query/include/parser/parse_func.h +73 -0
- data/ext/pg_query/include/parser/parse_node.h +327 -0
- data/ext/pg_query/include/parser/parse_oper.h +67 -0
- data/ext/pg_query/include/parser/parse_relation.h +123 -0
- data/ext/pg_query/include/parser/parse_target.h +46 -0
- data/ext/pg_query/include/parser/parse_type.h +60 -0
- data/ext/pg_query/include/parser/parser.h +41 -0
- data/ext/pg_query/include/parser/parsetree.h +61 -0
- data/ext/pg_query/include/parser/scanner.h +152 -0
- data/ext/pg_query/include/parser/scansup.h +30 -0
- data/ext/pg_query/include/partitioning/partdefs.h +26 -0
- data/ext/pg_query/include/pg_config.h +989 -0
- data/ext/pg_query/include/pg_config_ext.h +8 -0
- data/ext/pg_query/include/pg_config_manual.h +350 -0
- data/ext/pg_query/include/pg_config_os.h +8 -0
- data/ext/pg_query/include/pg_getopt.h +56 -0
- data/ext/pg_query/include/pg_query.h +121 -0
- data/ext/pg_query/include/pg_query_enum_defs.c +2454 -0
- data/ext/pg_query/include/pg_query_fingerprint_conds.c +875 -0
- data/ext/pg_query/include/pg_query_fingerprint_defs.c +12413 -0
- data/ext/pg_query/include/pg_query_json_helper.c +61 -0
- data/ext/pg_query/include/pg_query_outfuncs_conds.c +686 -0
- data/ext/pg_query/include/pg_query_outfuncs_defs.c +2437 -0
- data/ext/pg_query/include/pg_query_readfuncs_conds.c +222 -0
- data/ext/pg_query/include/pg_query_readfuncs_defs.c +2878 -0
- data/ext/pg_query/include/pg_trace.h +17 -0
- data/ext/pg_query/include/pgstat.h +1487 -0
- data/ext/pg_query/include/pgtime.h +84 -0
- data/ext/pg_query/include/pl_gram.h +385 -0
- data/ext/pg_query/include/pl_reserved_kwlist.h +52 -0
- data/ext/pg_query/include/pl_reserved_kwlist_d.h +114 -0
- data/ext/pg_query/include/pl_unreserved_kwlist.h +112 -0
- data/ext/pg_query/include/pl_unreserved_kwlist_d.h +246 -0
- data/ext/pg_query/include/plerrcodes.h +990 -0
- data/ext/pg_query/include/plpgsql.h +1347 -0
- data/ext/pg_query/include/port.h +524 -0
- data/ext/pg_query/include/port/atomics.h +524 -0
- data/ext/pg_query/include/port/atomics/arch-arm.h +26 -0
- data/ext/pg_query/include/port/atomics/arch-ppc.h +254 -0
- data/ext/pg_query/include/port/atomics/arch-x86.h +252 -0
- data/ext/pg_query/include/port/atomics/fallback.h +170 -0
- data/ext/pg_query/include/port/atomics/generic-gcc.h +286 -0
- data/ext/pg_query/include/port/atomics/generic.h +401 -0
- data/ext/pg_query/include/port/pg_bitutils.h +226 -0
- data/ext/pg_query/include/port/pg_bswap.h +161 -0
- data/ext/pg_query/include/port/pg_crc32c.h +101 -0
- data/ext/pg_query/include/portability/instr_time.h +256 -0
- data/ext/pg_query/include/postgres.h +764 -0
- data/ext/pg_query/include/postgres_ext.h +74 -0
- data/ext/pg_query/include/postmaster/autovacuum.h +83 -0
- data/ext/pg_query/include/postmaster/bgworker.h +161 -0
- data/ext/pg_query/include/postmaster/bgworker_internals.h +64 -0
- data/ext/pg_query/include/postmaster/bgwriter.h +45 -0
- data/ext/pg_query/include/postmaster/fork_process.h +17 -0
- data/ext/pg_query/include/postmaster/interrupt.h +32 -0
- data/ext/pg_query/include/postmaster/pgarch.h +39 -0
- data/ext/pg_query/include/postmaster/postmaster.h +77 -0
- data/ext/pg_query/include/postmaster/syslogger.h +98 -0
- data/ext/pg_query/include/postmaster/walwriter.h +21 -0
- data/ext/pg_query/include/protobuf-c.h +1106 -0
- data/ext/pg_query/include/protobuf-c/protobuf-c.h +1106 -0
- data/ext/pg_query/include/protobuf/pg_query.pb-c.h +10846 -0
- data/ext/pg_query/include/protobuf/pg_query.pb.h +124718 -0
- data/ext/pg_query/include/regex/regex.h +184 -0
- data/ext/pg_query/include/replication/logicallauncher.h +31 -0
- data/ext/pg_query/include/replication/logicalproto.h +110 -0
- data/ext/pg_query/include/replication/logicalworker.h +19 -0
- data/ext/pg_query/include/replication/origin.h +73 -0
- data/ext/pg_query/include/replication/reorderbuffer.h +467 -0
- data/ext/pg_query/include/replication/slot.h +219 -0
- data/ext/pg_query/include/replication/syncrep.h +115 -0
- data/ext/pg_query/include/replication/walreceiver.h +340 -0
- data/ext/pg_query/include/replication/walsender.h +74 -0
- data/ext/pg_query/include/rewrite/prs2lock.h +46 -0
- data/ext/pg_query/include/rewrite/rewriteHandler.h +40 -0
- data/ext/pg_query/include/rewrite/rewriteManip.h +87 -0
- data/ext/pg_query/include/rewrite/rewriteSupport.h +26 -0
- data/ext/pg_query/include/storage/backendid.h +37 -0
- data/ext/pg_query/include/storage/block.h +121 -0
- data/ext/pg_query/include/storage/buf.h +46 -0
- data/ext/pg_query/include/storage/bufmgr.h +292 -0
- data/ext/pg_query/include/storage/bufpage.h +459 -0
- data/ext/pg_query/include/storage/condition_variable.h +62 -0
- data/ext/pg_query/include/storage/dsm.h +61 -0
- data/ext/pg_query/include/storage/dsm_impl.h +75 -0
- data/ext/pg_query/include/storage/fd.h +168 -0
- data/ext/pg_query/include/storage/ipc.h +81 -0
- data/ext/pg_query/include/storage/item.h +19 -0
- data/ext/pg_query/include/storage/itemid.h +184 -0
- data/ext/pg_query/include/storage/itemptr.h +206 -0
- data/ext/pg_query/include/storage/large_object.h +100 -0
- data/ext/pg_query/include/storage/latch.h +190 -0
- data/ext/pg_query/include/storage/lmgr.h +114 -0
- data/ext/pg_query/include/storage/lock.h +612 -0
- data/ext/pg_query/include/storage/lockdefs.h +59 -0
- data/ext/pg_query/include/storage/lwlock.h +232 -0
- data/ext/pg_query/include/storage/lwlocknames.h +51 -0
- data/ext/pg_query/include/storage/off.h +57 -0
- data/ext/pg_query/include/storage/pg_sema.h +61 -0
- data/ext/pg_query/include/storage/pg_shmem.h +90 -0
- data/ext/pg_query/include/storage/pmsignal.h +94 -0
- data/ext/pg_query/include/storage/predicate.h +87 -0
- data/ext/pg_query/include/storage/proc.h +333 -0
- data/ext/pg_query/include/storage/proclist_types.h +51 -0
- data/ext/pg_query/include/storage/procsignal.h +75 -0
- data/ext/pg_query/include/storage/relfilenode.h +99 -0
- data/ext/pg_query/include/storage/s_lock.h +1047 -0
- data/ext/pg_query/include/storage/sharedfileset.h +45 -0
- data/ext/pg_query/include/storage/shm_mq.h +85 -0
- data/ext/pg_query/include/storage/shm_toc.h +58 -0
- data/ext/pg_query/include/storage/shmem.h +81 -0
- data/ext/pg_query/include/storage/sinval.h +153 -0
- data/ext/pg_query/include/storage/sinvaladt.h +43 -0
- data/ext/pg_query/include/storage/smgr.h +109 -0
- data/ext/pg_query/include/storage/spin.h +77 -0
- data/ext/pg_query/include/storage/standby.h +91 -0
- data/ext/pg_query/include/storage/standbydefs.h +74 -0
- data/ext/pg_query/include/storage/sync.h +62 -0
- data/ext/pg_query/include/tcop/cmdtag.h +58 -0
- data/ext/pg_query/include/tcop/cmdtaglist.h +217 -0
- data/ext/pg_query/include/tcop/deparse_utility.h +108 -0
- data/ext/pg_query/include/tcop/dest.h +149 -0
- data/ext/pg_query/include/tcop/fastpath.h +21 -0
- data/ext/pg_query/include/tcop/pquery.h +45 -0
- data/ext/pg_query/include/tcop/tcopprot.h +89 -0
- data/ext/pg_query/include/tcop/utility.h +108 -0
- data/ext/pg_query/include/tsearch/ts_cache.h +98 -0
- data/ext/pg_query/include/utils/acl.h +312 -0
- data/ext/pg_query/include/utils/aclchk_internal.h +45 -0
- data/ext/pg_query/include/utils/array.h +458 -0
- data/ext/pg_query/include/utils/builtins.h +127 -0
- data/ext/pg_query/include/utils/bytea.h +27 -0
- data/ext/pg_query/include/utils/catcache.h +231 -0
- data/ext/pg_query/include/utils/date.h +90 -0
- data/ext/pg_query/include/utils/datetime.h +343 -0
- data/ext/pg_query/include/utils/datum.h +68 -0
- data/ext/pg_query/include/utils/dsa.h +123 -0
- data/ext/pg_query/include/utils/dynahash.h +19 -0
- data/ext/pg_query/include/utils/elog.h +439 -0
- data/ext/pg_query/include/utils/errcodes.h +352 -0
- data/ext/pg_query/include/utils/expandeddatum.h +159 -0
- data/ext/pg_query/include/utils/expandedrecord.h +231 -0
- data/ext/pg_query/include/utils/float.h +356 -0
- data/ext/pg_query/include/utils/fmgroids.h +2657 -0
- data/ext/pg_query/include/utils/fmgrprotos.h +2646 -0
- data/ext/pg_query/include/utils/fmgrtab.h +48 -0
- data/ext/pg_query/include/utils/guc.h +443 -0
- data/ext/pg_query/include/utils/guc_tables.h +272 -0
- data/ext/pg_query/include/utils/hsearch.h +149 -0
- data/ext/pg_query/include/utils/inval.h +64 -0
- data/ext/pg_query/include/utils/lsyscache.h +197 -0
- data/ext/pg_query/include/utils/memdebug.h +82 -0
- data/ext/pg_query/include/utils/memutils.h +225 -0
- data/ext/pg_query/include/utils/numeric.h +76 -0
- data/ext/pg_query/include/utils/palloc.h +136 -0
- data/ext/pg_query/include/utils/partcache.h +102 -0
- data/ext/pg_query/include/utils/pg_locale.h +119 -0
- data/ext/pg_query/include/utils/pg_lsn.h +29 -0
- data/ext/pg_query/include/utils/pidfile.h +56 -0
- data/ext/pg_query/include/utils/plancache.h +235 -0
- data/ext/pg_query/include/utils/portal.h +241 -0
- data/ext/pg_query/include/utils/probes.h +114 -0
- data/ext/pg_query/include/utils/ps_status.h +25 -0
- data/ext/pg_query/include/utils/queryenvironment.h +74 -0
- data/ext/pg_query/include/utils/regproc.h +28 -0
- data/ext/pg_query/include/utils/rel.h +644 -0
- data/ext/pg_query/include/utils/relcache.h +151 -0
- data/ext/pg_query/include/utils/reltrigger.h +81 -0
- data/ext/pg_query/include/utils/resowner.h +86 -0
- data/ext/pg_query/include/utils/rls.h +50 -0
- data/ext/pg_query/include/utils/ruleutils.h +44 -0
- data/ext/pg_query/include/utils/sharedtuplestore.h +61 -0
- data/ext/pg_query/include/utils/snapmgr.h +158 -0
- data/ext/pg_query/include/utils/snapshot.h +206 -0
- data/ext/pg_query/include/utils/sortsupport.h +276 -0
- data/ext/pg_query/include/utils/syscache.h +219 -0
- data/ext/pg_query/include/utils/timeout.h +88 -0
- data/ext/pg_query/include/utils/timestamp.h +116 -0
- data/ext/pg_query/include/utils/tuplesort.h +277 -0
- data/ext/pg_query/include/utils/tuplestore.h +91 -0
- data/ext/pg_query/include/utils/typcache.h +202 -0
- data/ext/pg_query/include/utils/tzparser.h +39 -0
- data/ext/pg_query/include/utils/varlena.h +39 -0
- data/ext/pg_query/include/utils/xml.h +84 -0
- data/ext/pg_query/include/xxhash.h +5445 -0
- data/ext/pg_query/include/xxhash/xxhash.h +5445 -0
- data/ext/pg_query/pg_query.c +104 -0
- data/ext/pg_query/pg_query.pb-c.c +37628 -0
- data/ext/pg_query/pg_query_deparse.c +9959 -0
- data/ext/pg_query/pg_query_fingerprint.c +295 -0
- data/ext/pg_query/pg_query_fingerprint.h +8 -0
- data/ext/pg_query/pg_query_internal.h +24 -0
- data/ext/pg_query/pg_query_json_plpgsql.c +738 -0
- data/ext/pg_query/pg_query_json_plpgsql.h +9 -0
- data/ext/pg_query/pg_query_normalize.c +439 -0
- data/ext/pg_query/pg_query_outfuncs.h +10 -0
- data/ext/pg_query/pg_query_outfuncs_json.c +297 -0
- data/ext/pg_query/pg_query_outfuncs_protobuf.c +237 -0
- data/ext/pg_query/pg_query_parse.c +148 -0
- data/ext/pg_query/pg_query_parse_plpgsql.c +460 -0
- data/ext/pg_query/pg_query_readfuncs.h +11 -0
- data/ext/pg_query/pg_query_readfuncs_protobuf.c +142 -0
- data/ext/pg_query/pg_query_ruby.c +108 -12
- data/ext/pg_query/pg_query_scan.c +173 -0
- data/ext/pg_query/pg_query_split.c +221 -0
- data/ext/pg_query/protobuf-c.c +3660 -0
- data/ext/pg_query/src_backend_catalog_namespace.c +1051 -0
- data/ext/pg_query/src_backend_catalog_pg_proc.c +142 -0
- data/ext/pg_query/src_backend_commands_define.c +117 -0
- data/ext/pg_query/src_backend_libpq_pqcomm.c +651 -0
- data/ext/pg_query/src_backend_nodes_bitmapset.c +513 -0
- data/ext/pg_query/src_backend_nodes_copyfuncs.c +6013 -0
- data/ext/pg_query/src_backend_nodes_equalfuncs.c +4003 -0
- data/ext/pg_query/src_backend_nodes_extensible.c +99 -0
- data/ext/pg_query/src_backend_nodes_list.c +922 -0
- data/ext/pg_query/src_backend_nodes_makefuncs.c +417 -0
- data/ext/pg_query/src_backend_nodes_nodeFuncs.c +1363 -0
- data/ext/pg_query/src_backend_nodes_value.c +84 -0
- data/ext/pg_query/src_backend_parser_gram.c +47456 -0
- data/ext/pg_query/src_backend_parser_parse_expr.c +313 -0
- data/ext/pg_query/src_backend_parser_parser.c +497 -0
- data/ext/pg_query/src_backend_parser_scan.c +7091 -0
- data/ext/pg_query/src_backend_parser_scansup.c +160 -0
- data/ext/pg_query/src_backend_postmaster_postmaster.c +2230 -0
- data/ext/pg_query/src_backend_storage_ipc_ipc.c +192 -0
- data/ext/pg_query/src_backend_storage_lmgr_s_lock.c +370 -0
- data/ext/pg_query/src_backend_tcop_postgres.c +776 -0
- data/ext/pg_query/src_backend_utils_adt_datum.c +326 -0
- data/ext/pg_query/src_backend_utils_adt_expandeddatum.c +98 -0
- data/ext/pg_query/src_backend_utils_adt_format_type.c +136 -0
- data/ext/pg_query/src_backend_utils_adt_ruleutils.c +1683 -0
- data/ext/pg_query/src_backend_utils_error_assert.c +74 -0
- data/ext/pg_query/src_backend_utils_error_elog.c +1748 -0
- data/ext/pg_query/src_backend_utils_fmgr_fmgr.c +570 -0
- data/ext/pg_query/src_backend_utils_hash_dynahash.c +1086 -0
- data/ext/pg_query/src_backend_utils_init_globals.c +168 -0
- data/ext/pg_query/src_backend_utils_mb_mbutils.c +839 -0
- data/ext/pg_query/src_backend_utils_misc_guc.c +1831 -0
- data/ext/pg_query/src_backend_utils_mmgr_aset.c +1560 -0
- data/ext/pg_query/src_backend_utils_mmgr_mcxt.c +1006 -0
- data/ext/pg_query/src_common_encnames.c +158 -0
- data/ext/pg_query/src_common_keywords.c +39 -0
- data/ext/pg_query/src_common_kwlist_d.h +1081 -0
- data/ext/pg_query/src_common_kwlookup.c +91 -0
- data/ext/pg_query/src_common_psprintf.c +158 -0
- data/ext/pg_query/src_common_string.c +86 -0
- data/ext/pg_query/src_common_stringinfo.c +336 -0
- data/ext/pg_query/src_common_wchar.c +1651 -0
- data/ext/pg_query/src_pl_plpgsql_src_pl_comp.c +1133 -0
- data/ext/pg_query/src_pl_plpgsql_src_pl_funcs.c +877 -0
- data/ext/pg_query/src_pl_plpgsql_src_pl_gram.c +6533 -0
- data/ext/pg_query/src_pl_plpgsql_src_pl_handler.c +107 -0
- data/ext/pg_query/src_pl_plpgsql_src_pl_reserved_kwlist_d.h +123 -0
- data/ext/pg_query/src_pl_plpgsql_src_pl_scanner.c +671 -0
- data/ext/pg_query/src_pl_plpgsql_src_pl_unreserved_kwlist_d.h +255 -0
- data/ext/pg_query/src_port_erand48.c +127 -0
- data/ext/pg_query/src_port_pg_bitutils.c +246 -0
- data/ext/pg_query/src_port_pgsleep.c +69 -0
- data/ext/pg_query/src_port_pgstrcasecmp.c +83 -0
- data/ext/pg_query/src_port_qsort.c +240 -0
- data/ext/pg_query/src_port_random.c +31 -0
- data/ext/pg_query/src_port_snprintf.c +1449 -0
- data/ext/pg_query/src_port_strerror.c +324 -0
- data/ext/pg_query/src_port_strnlen.c +39 -0
- data/ext/pg_query/xxhash.c +43 -0
- data/lib/pg_query.rb +7 -4
- data/lib/pg_query/constants.rb +21 -0
- data/lib/pg_query/deparse.rb +15 -1581
- data/lib/pg_query/filter_columns.rb +88 -85
- data/lib/pg_query/fingerprint.rb +122 -87
- data/lib/pg_query/json_field_names.rb +1402 -0
- data/lib/pg_query/node.rb +31 -0
- data/lib/pg_query/param_refs.rb +42 -37
- data/lib/pg_query/parse.rb +220 -203
- data/lib/pg_query/parse_error.rb +1 -1
- data/lib/pg_query/pg_query_pb.rb +3211 -0
- data/lib/pg_query/scan.rb +23 -0
- data/lib/pg_query/treewalker.rb +24 -40
- data/lib/pg_query/truncate.rb +71 -42
- data/lib/pg_query/version.rb +2 -2
- metadata +472 -11
- data/ext/pg_query/pg_query_ruby.h +0 -10
- data/lib/pg_query/deep_dup.rb +0 -16
- data/lib/pg_query/deparse/alter_table.rb +0 -42
- data/lib/pg_query/deparse/interval.rb +0 -105
- data/lib/pg_query/deparse/keywords.rb +0 -159
- data/lib/pg_query/deparse/rename.rb +0 -41
- data/lib/pg_query/legacy_parsetree.rb +0 -109
- data/lib/pg_query/node_types.rb +0 -296
@@ -0,0 +1,1683 @@
|
|
1
|
+
/*--------------------------------------------------------------------
|
2
|
+
* Symbols referenced in this file:
|
3
|
+
* - quote_identifier
|
4
|
+
* - quote_all_identifiers
|
5
|
+
*--------------------------------------------------------------------
|
6
|
+
*/
|
7
|
+
|
8
|
+
/*-------------------------------------------------------------------------
|
9
|
+
*
|
10
|
+
* ruleutils.c
|
11
|
+
* Functions to convert stored expressions/querytrees back to
|
12
|
+
* source text
|
13
|
+
*
|
14
|
+
* Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group
|
15
|
+
* Portions Copyright (c) 1994, Regents of the University of California
|
16
|
+
*
|
17
|
+
*
|
18
|
+
* IDENTIFICATION
|
19
|
+
* src/backend/utils/adt/ruleutils.c
|
20
|
+
*
|
21
|
+
*-------------------------------------------------------------------------
|
22
|
+
*/
|
23
|
+
#include "postgres.h"
|
24
|
+
|
25
|
+
#include <ctype.h>
|
26
|
+
#include <unistd.h>
|
27
|
+
#include <fcntl.h>
|
28
|
+
|
29
|
+
#include "access/amapi.h"
|
30
|
+
#include "access/htup_details.h"
|
31
|
+
#include "access/relation.h"
|
32
|
+
#include "access/sysattr.h"
|
33
|
+
#include "access/table.h"
|
34
|
+
#include "catalog/dependency.h"
|
35
|
+
#include "catalog/indexing.h"
|
36
|
+
#include "catalog/pg_aggregate.h"
|
37
|
+
#include "catalog/pg_am.h"
|
38
|
+
#include "catalog/pg_authid.h"
|
39
|
+
#include "catalog/pg_collation.h"
|
40
|
+
#include "catalog/pg_constraint.h"
|
41
|
+
#include "catalog/pg_depend.h"
|
42
|
+
#include "catalog/pg_language.h"
|
43
|
+
#include "catalog/pg_opclass.h"
|
44
|
+
#include "catalog/pg_operator.h"
|
45
|
+
#include "catalog/pg_partitioned_table.h"
|
46
|
+
#include "catalog/pg_proc.h"
|
47
|
+
#include "catalog/pg_statistic_ext.h"
|
48
|
+
#include "catalog/pg_trigger.h"
|
49
|
+
#include "catalog/pg_type.h"
|
50
|
+
#include "commands/defrem.h"
|
51
|
+
#include "commands/tablespace.h"
|
52
|
+
#include "common/keywords.h"
|
53
|
+
#include "executor/spi.h"
|
54
|
+
#include "funcapi.h"
|
55
|
+
#include "mb/pg_wchar.h"
|
56
|
+
#include "miscadmin.h"
|
57
|
+
#include "nodes/makefuncs.h"
|
58
|
+
#include "nodes/nodeFuncs.h"
|
59
|
+
#include "nodes/pathnodes.h"
|
60
|
+
#include "optimizer/optimizer.h"
|
61
|
+
#include "parser/parse_agg.h"
|
62
|
+
#include "parser/parse_func.h"
|
63
|
+
#include "parser/parse_node.h"
|
64
|
+
#include "parser/parse_oper.h"
|
65
|
+
#include "parser/parser.h"
|
66
|
+
#include "parser/parsetree.h"
|
67
|
+
#include "rewrite/rewriteHandler.h"
|
68
|
+
#include "rewrite/rewriteManip.h"
|
69
|
+
#include "rewrite/rewriteSupport.h"
|
70
|
+
#include "utils/array.h"
|
71
|
+
#include "utils/builtins.h"
|
72
|
+
#include "utils/fmgroids.h"
|
73
|
+
#include "utils/guc.h"
|
74
|
+
#include "utils/hsearch.h"
|
75
|
+
#include "utils/lsyscache.h"
|
76
|
+
#include "utils/partcache.h"
|
77
|
+
#include "utils/rel.h"
|
78
|
+
#include "utils/ruleutils.h"
|
79
|
+
#include "utils/snapmgr.h"
|
80
|
+
#include "utils/syscache.h"
|
81
|
+
#include "utils/typcache.h"
|
82
|
+
#include "utils/varlena.h"
|
83
|
+
#include "utils/xml.h"
|
84
|
+
|
85
|
+
/* ----------
|
86
|
+
* Pretty formatting constants
|
87
|
+
* ----------
|
88
|
+
*/
|
89
|
+
|
90
|
+
/* Indent counts */
|
91
|
+
#define PRETTYINDENT_STD 8
|
92
|
+
#define PRETTYINDENT_JOIN 4
|
93
|
+
#define PRETTYINDENT_VAR 4
|
94
|
+
|
95
|
+
#define PRETTYINDENT_LIMIT 40 /* wrap limit */
|
96
|
+
|
97
|
+
/* Pretty flags */
|
98
|
+
#define PRETTYFLAG_PAREN 0x0001
|
99
|
+
#define PRETTYFLAG_INDENT 0x0002
|
100
|
+
#define PRETTYFLAG_SCHEMA 0x0004
|
101
|
+
|
102
|
+
/* Default line length for pretty-print wrapping: 0 means wrap always */
|
103
|
+
#define WRAP_COLUMN_DEFAULT 0
|
104
|
+
|
105
|
+
/* macros to test if pretty action needed */
|
106
|
+
#define PRETTY_PAREN(context) ((context)->prettyFlags & PRETTYFLAG_PAREN)
|
107
|
+
#define PRETTY_INDENT(context) ((context)->prettyFlags & PRETTYFLAG_INDENT)
|
108
|
+
#define PRETTY_SCHEMA(context) ((context)->prettyFlags & PRETTYFLAG_SCHEMA)
|
109
|
+
|
110
|
+
|
111
|
+
/* ----------
|
112
|
+
* Local data types
|
113
|
+
* ----------
|
114
|
+
*/
|
115
|
+
|
116
|
+
/* Context info needed for invoking a recursive querytree display routine */
|
117
|
+
typedef struct
|
118
|
+
{
|
119
|
+
StringInfo buf; /* output buffer to append to */
|
120
|
+
List *namespaces; /* List of deparse_namespace nodes */
|
121
|
+
List *windowClause; /* Current query level's WINDOW clause */
|
122
|
+
List *windowTList; /* targetlist for resolving WINDOW clause */
|
123
|
+
int prettyFlags; /* enabling of pretty-print functions */
|
124
|
+
int wrapColumn; /* max line length, or -1 for no limit */
|
125
|
+
int indentLevel; /* current indent level for pretty-print */
|
126
|
+
bool varprefix; /* true to print prefixes on Vars */
|
127
|
+
ParseExprKind special_exprkind; /* set only for exprkinds needing special
|
128
|
+
* handling */
|
129
|
+
Bitmapset *appendparents; /* if not null, map child Vars of these relids
|
130
|
+
* back to the parent rel */
|
131
|
+
} deparse_context;
|
132
|
+
|
133
|
+
/*
|
134
|
+
* Each level of query context around a subtree needs a level of Var namespace.
|
135
|
+
* A Var having varlevelsup=N refers to the N'th item (counting from 0) in
|
136
|
+
* the current context's namespaces list.
|
137
|
+
*
|
138
|
+
* rtable is the list of actual RTEs from the Query or PlannedStmt.
|
139
|
+
* rtable_names holds the alias name to be used for each RTE (either a C
|
140
|
+
* string, or NULL for nameless RTEs such as unnamed joins).
|
141
|
+
* rtable_columns holds the column alias names to be used for each RTE.
|
142
|
+
*
|
143
|
+
* subplans is a list of Plan trees for SubPlans and CTEs (it's only used
|
144
|
+
* in the PlannedStmt case).
|
145
|
+
* ctes is a list of CommonTableExpr nodes (only used in the Query case).
|
146
|
+
* appendrels, if not null (it's only used in the PlannedStmt case), is an
|
147
|
+
* array of AppendRelInfo nodes, indexed by child relid. We use that to map
|
148
|
+
* child-table Vars to their inheritance parents.
|
149
|
+
*
|
150
|
+
* In some cases we need to make names of merged JOIN USING columns unique
|
151
|
+
* across the whole query, not only per-RTE. If so, unique_using is true
|
152
|
+
* and using_names is a list of C strings representing names already assigned
|
153
|
+
* to USING columns.
|
154
|
+
*
|
155
|
+
* When deparsing plan trees, there is always just a single item in the
|
156
|
+
* deparse_namespace list (since a plan tree never contains Vars with
|
157
|
+
* varlevelsup > 0). We store the Plan node that is the immediate
|
158
|
+
* parent of the expression to be deparsed, as well as a list of that
|
159
|
+
* Plan's ancestors. In addition, we store its outer and inner subplan nodes,
|
160
|
+
* as well as their targetlists, and the index tlist if the current plan node
|
161
|
+
* might contain INDEX_VAR Vars. (These fields could be derived on-the-fly
|
162
|
+
* from the current Plan node, but it seems notationally clearer to set them
|
163
|
+
* up as separate fields.)
|
164
|
+
*/
|
165
|
+
typedef struct
|
166
|
+
{
|
167
|
+
List *rtable; /* List of RangeTblEntry nodes */
|
168
|
+
List *rtable_names; /* Parallel list of names for RTEs */
|
169
|
+
List *rtable_columns; /* Parallel list of deparse_columns structs */
|
170
|
+
List *subplans; /* List of Plan trees for SubPlans */
|
171
|
+
List *ctes; /* List of CommonTableExpr nodes */
|
172
|
+
AppendRelInfo **appendrels; /* Array of AppendRelInfo nodes, or NULL */
|
173
|
+
/* Workspace for column alias assignment: */
|
174
|
+
bool unique_using; /* Are we making USING names globally unique */
|
175
|
+
List *using_names; /* List of assigned names for USING columns */
|
176
|
+
/* Remaining fields are used only when deparsing a Plan tree: */
|
177
|
+
Plan *plan; /* immediate parent of current expression */
|
178
|
+
List *ancestors; /* ancestors of plan */
|
179
|
+
Plan *outer_plan; /* outer subnode, or NULL if none */
|
180
|
+
Plan *inner_plan; /* inner subnode, or NULL if none */
|
181
|
+
List *outer_tlist; /* referent for OUTER_VAR Vars */
|
182
|
+
List *inner_tlist; /* referent for INNER_VAR Vars */
|
183
|
+
List *index_tlist; /* referent for INDEX_VAR Vars */
|
184
|
+
} deparse_namespace;
|
185
|
+
|
186
|
+
/*
|
187
|
+
* Per-relation data about column alias names.
|
188
|
+
*
|
189
|
+
* Selecting aliases is unreasonably complicated because of the need to dump
|
190
|
+
* rules/views whose underlying tables may have had columns added, deleted, or
|
191
|
+
* renamed since the query was parsed. We must nonetheless print the rule/view
|
192
|
+
* in a form that can be reloaded and will produce the same results as before.
|
193
|
+
*
|
194
|
+
* For each RTE used in the query, we must assign column aliases that are
|
195
|
+
* unique within that RTE. SQL does not require this of the original query,
|
196
|
+
* but due to factors such as *-expansion we need to be able to uniquely
|
197
|
+
* reference every column in a decompiled query. As long as we qualify all
|
198
|
+
* column references, per-RTE uniqueness is sufficient for that.
|
199
|
+
*
|
200
|
+
* However, we can't ensure per-column name uniqueness for unnamed join RTEs,
|
201
|
+
* since they just inherit column names from their input RTEs, and we can't
|
202
|
+
* rename the columns at the join level. Most of the time this isn't an issue
|
203
|
+
* because we don't need to reference the join's output columns as such; we
|
204
|
+
* can reference the input columns instead. That approach can fail for merged
|
205
|
+
* JOIN USING columns, however, so when we have one of those in an unnamed
|
206
|
+
* join, we have to make that column's alias globally unique across the whole
|
207
|
+
* query to ensure it can be referenced unambiguously.
|
208
|
+
*
|
209
|
+
* Another problem is that a JOIN USING clause requires the columns to be
|
210
|
+
* merged to have the same aliases in both input RTEs, and that no other
|
211
|
+
* columns in those RTEs or their children conflict with the USING names.
|
212
|
+
* To handle that, we do USING-column alias assignment in a recursive
|
213
|
+
* traversal of the query's jointree. When descending through a JOIN with
|
214
|
+
* USING, we preassign the USING column names to the child columns, overriding
|
215
|
+
* other rules for column alias assignment. We also mark each RTE with a list
|
216
|
+
* of all USING column names selected for joins containing that RTE, so that
|
217
|
+
* when we assign other columns' aliases later, we can avoid conflicts.
|
218
|
+
*
|
219
|
+
* Another problem is that if a JOIN's input tables have had columns added or
|
220
|
+
* deleted since the query was parsed, we must generate a column alias list
|
221
|
+
* for the join that matches the current set of input columns --- otherwise, a
|
222
|
+
* change in the number of columns in the left input would throw off matching
|
223
|
+
* of aliases to columns of the right input. Thus, positions in the printable
|
224
|
+
* column alias list are not necessarily one-for-one with varattnos of the
|
225
|
+
* JOIN, so we need a separate new_colnames[] array for printing purposes.
|
226
|
+
*/
|
227
|
+
typedef struct
|
228
|
+
{
|
229
|
+
/*
|
230
|
+
* colnames is an array containing column aliases to use for columns that
|
231
|
+
* existed when the query was parsed. Dropped columns have NULL entries.
|
232
|
+
* This array can be directly indexed by varattno to get a Var's name.
|
233
|
+
*
|
234
|
+
* Non-NULL entries are guaranteed unique within the RTE, *except* when
|
235
|
+
* this is for an unnamed JOIN RTE. In that case we merely copy up names
|
236
|
+
* from the two input RTEs.
|
237
|
+
*
|
238
|
+
* During the recursive descent in set_using_names(), forcible assignment
|
239
|
+
* of a child RTE's column name is represented by pre-setting that element
|
240
|
+
* of the child's colnames array. So at that stage, NULL entries in this
|
241
|
+
* array just mean that no name has been preassigned, not necessarily that
|
242
|
+
* the column is dropped.
|
243
|
+
*/
|
244
|
+
int num_cols; /* length of colnames[] array */
|
245
|
+
char **colnames; /* array of C strings and NULLs */
|
246
|
+
|
247
|
+
/*
|
248
|
+
* new_colnames is an array containing column aliases to use for columns
|
249
|
+
* that would exist if the query was re-parsed against the current
|
250
|
+
* definitions of its base tables. This is what to print as the column
|
251
|
+
* alias list for the RTE. This array does not include dropped columns,
|
252
|
+
* but it will include columns added since original parsing. Indexes in
|
253
|
+
* it therefore have little to do with current varattno values. As above,
|
254
|
+
* entries are unique unless this is for an unnamed JOIN RTE. (In such an
|
255
|
+
* RTE, we never actually print this array, but we must compute it anyway
|
256
|
+
* for possible use in computing column names of upper joins.) The
|
257
|
+
* parallel array is_new_col marks which of these columns are new since
|
258
|
+
* original parsing. Entries with is_new_col false must match the
|
259
|
+
* non-NULL colnames entries one-for-one.
|
260
|
+
*/
|
261
|
+
int num_new_cols; /* length of new_colnames[] array */
|
262
|
+
char **new_colnames; /* array of C strings */
|
263
|
+
bool *is_new_col; /* array of bool flags */
|
264
|
+
|
265
|
+
/* This flag tells whether we should actually print a column alias list */
|
266
|
+
bool printaliases;
|
267
|
+
|
268
|
+
/* This list has all names used as USING names in joins above this RTE */
|
269
|
+
List *parentUsing; /* names assigned to parent merged columns */
|
270
|
+
|
271
|
+
/*
|
272
|
+
* If this struct is for a JOIN RTE, we fill these fields during the
|
273
|
+
* set_using_names() pass to describe its relationship to its child RTEs.
|
274
|
+
*
|
275
|
+
* leftattnos and rightattnos are arrays with one entry per existing
|
276
|
+
* output column of the join (hence, indexable by join varattno). For a
|
277
|
+
* simple reference to a column of the left child, leftattnos[i] is the
|
278
|
+
* child RTE's attno and rightattnos[i] is zero; and conversely for a
|
279
|
+
* column of the right child. But for merged columns produced by JOIN
|
280
|
+
* USING/NATURAL JOIN, both leftattnos[i] and rightattnos[i] are nonzero.
|
281
|
+
* Note that a simple reference might be to a child RTE column that's been
|
282
|
+
* dropped; but that's OK since the column could not be used in the query.
|
283
|
+
*
|
284
|
+
* If it's a JOIN USING, usingNames holds the alias names selected for the
|
285
|
+
* merged columns (these might be different from the original USING list,
|
286
|
+
* if we had to modify names to achieve uniqueness).
|
287
|
+
*/
|
288
|
+
int leftrti; /* rangetable index of left child */
|
289
|
+
int rightrti; /* rangetable index of right child */
|
290
|
+
int *leftattnos; /* left-child varattnos of join cols, or 0 */
|
291
|
+
int *rightattnos; /* right-child varattnos of join cols, or 0 */
|
292
|
+
List *usingNames; /* names assigned to merged columns */
|
293
|
+
} deparse_columns;
|
294
|
+
|
295
|
+
/* This macro is analogous to rt_fetch(), but for deparse_columns structs */
|
296
|
+
#define deparse_columns_fetch(rangetable_index, dpns) \
|
297
|
+
((deparse_columns *) list_nth((dpns)->rtable_columns, (rangetable_index)-1))
|
298
|
+
|
299
|
+
/*
|
300
|
+
* Entry in set_rtable_names' hash table
|
301
|
+
*/
|
302
|
+
typedef struct
|
303
|
+
{
|
304
|
+
char name[NAMEDATALEN]; /* Hash key --- must be first */
|
305
|
+
int counter; /* Largest addition used so far for name */
|
306
|
+
} NameHashEntry;
|
307
|
+
|
308
|
+
/* Callback signature for resolve_special_varno() */
|
309
|
+
typedef void (*rsv_callback) (Node *node, deparse_context *context,
|
310
|
+
void *callback_arg);
|
311
|
+
|
312
|
+
|
313
|
+
/* ----------
|
314
|
+
* Global data
|
315
|
+
* ----------
|
316
|
+
*/
|
317
|
+
|
318
|
+
|
319
|
+
|
320
|
+
|
321
|
+
|
322
|
+
/* GUC parameters */
|
323
|
+
__thread bool quote_all_identifiers = false;
|
324
|
+
|
325
|
+
|
326
|
+
|
327
|
+
/* ----------
|
328
|
+
* Local functions
|
329
|
+
*
|
330
|
+
* Most of these functions used to use fixed-size buffers to build their
|
331
|
+
* results. Now, they take an (already initialized) StringInfo object
|
332
|
+
* as a parameter, and append their text output to its contents.
|
333
|
+
* ----------
|
334
|
+
*/
|
335
|
+
static char *deparse_expression_pretty(Node *expr, List *dpcontext,
|
336
|
+
bool forceprefix, bool showimplicit,
|
337
|
+
int prettyFlags, int startIndent);
|
338
|
+
static char *pg_get_viewdef_worker(Oid viewoid,
|
339
|
+
int prettyFlags, int wrapColumn);
|
340
|
+
static char *pg_get_triggerdef_worker(Oid trigid, bool pretty);
|
341
|
+
static int decompile_column_index_array(Datum column_index_array, Oid relId,
|
342
|
+
StringInfo buf);
|
343
|
+
static char *pg_get_ruledef_worker(Oid ruleoid, int prettyFlags);
|
344
|
+
static char *pg_get_indexdef_worker(Oid indexrelid, int colno,
|
345
|
+
const Oid *excludeOps,
|
346
|
+
bool attrsOnly, bool keysOnly,
|
347
|
+
bool showTblSpc, bool inherits,
|
348
|
+
int prettyFlags, bool missing_ok);
|
349
|
+
static char *pg_get_statisticsobj_worker(Oid statextid, bool missing_ok);
|
350
|
+
static char *pg_get_partkeydef_worker(Oid relid, int prettyFlags,
|
351
|
+
bool attrsOnly, bool missing_ok);
|
352
|
+
static char *pg_get_constraintdef_worker(Oid constraintId, bool fullCommand,
|
353
|
+
int prettyFlags, bool missing_ok);
|
354
|
+
static text *pg_get_expr_worker(text *expr, Oid relid, const char *relname,
|
355
|
+
int prettyFlags);
|
356
|
+
static int print_function_arguments(StringInfo buf, HeapTuple proctup,
|
357
|
+
bool print_table_args, bool print_defaults);
|
358
|
+
static void print_function_rettype(StringInfo buf, HeapTuple proctup);
|
359
|
+
static void print_function_trftypes(StringInfo buf, HeapTuple proctup);
|
360
|
+
static void set_rtable_names(deparse_namespace *dpns, List *parent_namespaces,
|
361
|
+
Bitmapset *rels_used);
|
362
|
+
static void set_deparse_for_query(deparse_namespace *dpns, Query *query,
|
363
|
+
List *parent_namespaces);
|
364
|
+
static void set_simple_column_names(deparse_namespace *dpns);
|
365
|
+
static bool has_dangerous_join_using(deparse_namespace *dpns, Node *jtnode);
|
366
|
+
static void set_using_names(deparse_namespace *dpns, Node *jtnode,
|
367
|
+
List *parentUsing);
|
368
|
+
static void set_relation_column_names(deparse_namespace *dpns,
|
369
|
+
RangeTblEntry *rte,
|
370
|
+
deparse_columns *colinfo);
|
371
|
+
static void set_join_column_names(deparse_namespace *dpns, RangeTblEntry *rte,
|
372
|
+
deparse_columns *colinfo);
|
373
|
+
static bool colname_is_unique(const char *colname, deparse_namespace *dpns,
|
374
|
+
deparse_columns *colinfo);
|
375
|
+
static char *make_colname_unique(char *colname, deparse_namespace *dpns,
|
376
|
+
deparse_columns *colinfo);
|
377
|
+
static void expand_colnames_array_to(deparse_columns *colinfo, int n);
|
378
|
+
static void identify_join_columns(JoinExpr *j, RangeTblEntry *jrte,
|
379
|
+
deparse_columns *colinfo);
|
380
|
+
static char *get_rtable_name(int rtindex, deparse_context *context);
|
381
|
+
static void set_deparse_plan(deparse_namespace *dpns, Plan *plan);
|
382
|
+
static void push_child_plan(deparse_namespace *dpns, Plan *plan,
|
383
|
+
deparse_namespace *save_dpns);
|
384
|
+
static void pop_child_plan(deparse_namespace *dpns,
|
385
|
+
deparse_namespace *save_dpns);
|
386
|
+
static void push_ancestor_plan(deparse_namespace *dpns, ListCell *ancestor_cell,
|
387
|
+
deparse_namespace *save_dpns);
|
388
|
+
static void pop_ancestor_plan(deparse_namespace *dpns,
|
389
|
+
deparse_namespace *save_dpns);
|
390
|
+
static void make_ruledef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc,
|
391
|
+
int prettyFlags);
|
392
|
+
static void make_viewdef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc,
|
393
|
+
int prettyFlags, int wrapColumn);
|
394
|
+
static void get_query_def(Query *query, StringInfo buf, List *parentnamespace,
|
395
|
+
TupleDesc resultDesc,
|
396
|
+
int prettyFlags, int wrapColumn, int startIndent);
|
397
|
+
static void get_values_def(List *values_lists, deparse_context *context);
|
398
|
+
static void get_with_clause(Query *query, deparse_context *context);
|
399
|
+
static void get_select_query_def(Query *query, deparse_context *context,
|
400
|
+
TupleDesc resultDesc);
|
401
|
+
static void get_insert_query_def(Query *query, deparse_context *context);
|
402
|
+
static void get_update_query_def(Query *query, deparse_context *context);
|
403
|
+
static void get_update_query_targetlist_def(Query *query, List *targetList,
|
404
|
+
deparse_context *context,
|
405
|
+
RangeTblEntry *rte);
|
406
|
+
static void get_delete_query_def(Query *query, deparse_context *context);
|
407
|
+
static void get_utility_query_def(Query *query, deparse_context *context);
|
408
|
+
static void get_basic_select_query(Query *query, deparse_context *context,
|
409
|
+
TupleDesc resultDesc);
|
410
|
+
static void get_target_list(List *targetList, deparse_context *context,
|
411
|
+
TupleDesc resultDesc);
|
412
|
+
static void get_setop_query(Node *setOp, Query *query,
|
413
|
+
deparse_context *context,
|
414
|
+
TupleDesc resultDesc);
|
415
|
+
static Node *get_rule_sortgroupclause(Index ref, List *tlist,
|
416
|
+
bool force_colno,
|
417
|
+
deparse_context *context);
|
418
|
+
static void get_rule_groupingset(GroupingSet *gset, List *targetlist,
|
419
|
+
bool omit_parens, deparse_context *context);
|
420
|
+
static void get_rule_orderby(List *orderList, List *targetList,
|
421
|
+
bool force_colno, deparse_context *context);
|
422
|
+
static void get_rule_windowclause(Query *query, deparse_context *context);
|
423
|
+
static void get_rule_windowspec(WindowClause *wc, List *targetList,
|
424
|
+
deparse_context *context);
|
425
|
+
static char *get_variable(Var *var, int levelsup, bool istoplevel,
|
426
|
+
deparse_context *context);
|
427
|
+
static void get_special_variable(Node *node, deparse_context *context,
|
428
|
+
void *callback_arg);
|
429
|
+
static void resolve_special_varno(Node *node, deparse_context *context,
|
430
|
+
rsv_callback callback, void *callback_arg);
|
431
|
+
static Node *find_param_referent(Param *param, deparse_context *context,
|
432
|
+
deparse_namespace **dpns_p, ListCell **ancestor_cell_p);
|
433
|
+
static void get_parameter(Param *param, deparse_context *context);
|
434
|
+
static const char *get_simple_binary_op_name(OpExpr *expr);
|
435
|
+
static bool isSimpleNode(Node *node, Node *parentNode, int prettyFlags);
|
436
|
+
static void appendContextKeyword(deparse_context *context, const char *str,
|
437
|
+
int indentBefore, int indentAfter, int indentPlus);
|
438
|
+
static void removeStringInfoSpaces(StringInfo str);
|
439
|
+
static void get_rule_expr(Node *node, deparse_context *context,
|
440
|
+
bool showimplicit);
|
441
|
+
static void get_rule_expr_toplevel(Node *node, deparse_context *context,
|
442
|
+
bool showimplicit);
|
443
|
+
static void get_rule_expr_funccall(Node *node, deparse_context *context,
|
444
|
+
bool showimplicit);
|
445
|
+
static bool looks_like_function(Node *node);
|
446
|
+
static void get_oper_expr(OpExpr *expr, deparse_context *context);
|
447
|
+
static void get_func_expr(FuncExpr *expr, deparse_context *context,
|
448
|
+
bool showimplicit);
|
449
|
+
static void get_agg_expr(Aggref *aggref, deparse_context *context,
|
450
|
+
Aggref *original_aggref);
|
451
|
+
static void get_agg_combine_expr(Node *node, deparse_context *context,
|
452
|
+
void *callback_arg);
|
453
|
+
static void get_windowfunc_expr(WindowFunc *wfunc, deparse_context *context);
|
454
|
+
static void get_coercion_expr(Node *arg, deparse_context *context,
|
455
|
+
Oid resulttype, int32 resulttypmod,
|
456
|
+
Node *parentNode);
|
457
|
+
static void get_const_expr(Const *constval, deparse_context *context,
|
458
|
+
int showtype);
|
459
|
+
static void get_const_collation(Const *constval, deparse_context *context);
|
460
|
+
static void simple_quote_literal(StringInfo buf, const char *val);
|
461
|
+
static void get_sublink_expr(SubLink *sublink, deparse_context *context);
|
462
|
+
static void get_tablefunc(TableFunc *tf, deparse_context *context,
|
463
|
+
bool showimplicit);
|
464
|
+
static void get_from_clause(Query *query, const char *prefix,
|
465
|
+
deparse_context *context);
|
466
|
+
static void get_from_clause_item(Node *jtnode, Query *query,
|
467
|
+
deparse_context *context);
|
468
|
+
static void get_column_alias_list(deparse_columns *colinfo,
|
469
|
+
deparse_context *context);
|
470
|
+
static void get_from_clause_coldeflist(RangeTblFunction *rtfunc,
|
471
|
+
deparse_columns *colinfo,
|
472
|
+
deparse_context *context);
|
473
|
+
static void get_tablesample_def(TableSampleClause *tablesample,
|
474
|
+
deparse_context *context);
|
475
|
+
static void get_opclass_name(Oid opclass, Oid actual_datatype,
|
476
|
+
StringInfo buf);
|
477
|
+
static Node *processIndirection(Node *node, deparse_context *context);
|
478
|
+
static void printSubscripts(SubscriptingRef *sbsref, deparse_context *context);
|
479
|
+
static char *get_relation_name(Oid relid);
|
480
|
+
static char *generate_relation_name(Oid relid, List *namespaces);
|
481
|
+
static char *generate_qualified_relation_name(Oid relid);
|
482
|
+
static char *generate_function_name(Oid funcid, int nargs,
|
483
|
+
List *argnames, Oid *argtypes,
|
484
|
+
bool has_variadic, bool *use_variadic_p,
|
485
|
+
ParseExprKind special_exprkind);
|
486
|
+
static char *generate_operator_name(Oid operid, Oid arg1, Oid arg2);
|
487
|
+
static void add_cast_to(StringInfo buf, Oid typid);
|
488
|
+
static char *generate_qualified_type_name(Oid typid);
|
489
|
+
static text *string_to_text(char *str);
|
490
|
+
static char *flatten_reloptions(Oid relid);
|
491
|
+
static void get_reloptions(StringInfo buf, Datum reloptions);
|
492
|
+
|
493
|
+
#define only_marker(rte) ((rte)->inh ? "" : "ONLY ")
|
494
|
+
|
495
|
+
|
496
|
+
/* ----------
|
497
|
+
* pg_get_ruledef - Do it all and return a text
|
498
|
+
* that could be used as a statement
|
499
|
+
* to recreate the rule
|
500
|
+
* ----------
|
501
|
+
*/
|
502
|
+
|
503
|
+
|
504
|
+
|
505
|
+
|
506
|
+
|
507
|
+
|
508
|
+
|
509
|
+
|
510
|
+
|
511
|
+
/* ----------
|
512
|
+
* pg_get_viewdef - Mainly the same thing, but we
|
513
|
+
* only return the SELECT part of a view
|
514
|
+
* ----------
|
515
|
+
*/
|
516
|
+
|
517
|
+
|
518
|
+
|
519
|
+
|
520
|
+
|
521
|
+
|
522
|
+
|
523
|
+
|
524
|
+
|
525
|
+
|
526
|
+
|
527
|
+
|
528
|
+
/*
|
529
|
+
* Common code for by-OID and by-name variants of pg_get_viewdef
|
530
|
+
*/
|
531
|
+
|
532
|
+
|
533
|
+
/* ----------
|
534
|
+
* pg_get_triggerdef - Get the definition of a trigger
|
535
|
+
* ----------
|
536
|
+
*/
|
537
|
+
|
538
|
+
|
539
|
+
|
540
|
+
|
541
|
+
|
542
|
+
|
543
|
+
/* ----------
|
544
|
+
* pg_get_indexdef - Get the definition of an index
|
545
|
+
*
|
546
|
+
* In the extended version, there is a colno argument as well as pretty bool.
|
547
|
+
* if colno == 0, we want a complete index definition.
|
548
|
+
* if colno > 0, we only want the Nth index key's variable or expression.
|
549
|
+
*
|
550
|
+
* Note that the SQL-function versions of this omit any info about the
|
551
|
+
* index tablespace; this is intentional because pg_dump wants it that way.
|
552
|
+
* However pg_get_indexdef_string() includes the index tablespace.
|
553
|
+
* ----------
|
554
|
+
*/
|
555
|
+
|
556
|
+
|
557
|
+
|
558
|
+
|
559
|
+
/*
|
560
|
+
* Internal version for use by ALTER TABLE.
|
561
|
+
* Includes a tablespace clause in the result.
|
562
|
+
* Returns a palloc'd C string; no pretty-printing.
|
563
|
+
*/
|
564
|
+
|
565
|
+
|
566
|
+
/* Internal version that just reports the key-column definitions */
|
567
|
+
|
568
|
+
|
569
|
+
/*
|
570
|
+
* Internal workhorse to decompile an index definition.
|
571
|
+
*
|
572
|
+
* This is now used for exclusion constraints as well: if excludeOps is not
|
573
|
+
* NULL then it points to an array of exclusion operator OIDs.
|
574
|
+
*/
|
575
|
+
|
576
|
+
|
577
|
+
/*
|
578
|
+
* pg_get_statisticsobjdef
|
579
|
+
* Get the definition of an extended statistics object
|
580
|
+
*/
|
581
|
+
|
582
|
+
|
583
|
+
/*
|
584
|
+
* Internal workhorse to decompile an extended statistics object.
|
585
|
+
*/
|
586
|
+
|
587
|
+
|
588
|
+
/*
|
589
|
+
* pg_get_partkeydef
|
590
|
+
*
|
591
|
+
* Returns the partition key specification, ie, the following:
|
592
|
+
*
|
593
|
+
* PARTITION BY { RANGE | LIST | HASH } (column opt_collation opt_opclass [, ...])
|
594
|
+
*/
|
595
|
+
|
596
|
+
|
597
|
+
/* Internal version that just reports the column definitions */
|
598
|
+
|
599
|
+
|
600
|
+
/*
|
601
|
+
* Internal workhorse to decompile a partition key definition.
|
602
|
+
*/
|
603
|
+
|
604
|
+
|
605
|
+
/*
|
606
|
+
* pg_get_partition_constraintdef
|
607
|
+
*
|
608
|
+
* Returns partition constraint expression as a string for the input relation
|
609
|
+
*/
|
610
|
+
|
611
|
+
|
612
|
+
/*
|
613
|
+
* pg_get_partconstrdef_string
|
614
|
+
*
|
615
|
+
* Returns the partition constraint as a C-string for the input relation, with
|
616
|
+
* the given alias. No pretty-printing.
|
617
|
+
*/
|
618
|
+
|
619
|
+
|
620
|
+
/*
|
621
|
+
* pg_get_constraintdef
|
622
|
+
*
|
623
|
+
* Returns the definition for the constraint, ie, everything that needs to
|
624
|
+
* appear after "ALTER TABLE ... ADD CONSTRAINT <constraintname>".
|
625
|
+
*/
|
626
|
+
|
627
|
+
|
628
|
+
|
629
|
+
|
630
|
+
/*
|
631
|
+
* Internal version that returns a full ALTER TABLE ... ADD CONSTRAINT command
|
632
|
+
*/
|
633
|
+
|
634
|
+
|
635
|
+
/*
|
636
|
+
* As of 9.4, we now use an MVCC snapshot for this.
|
637
|
+
*/
|
638
|
+
|
639
|
+
|
640
|
+
|
641
|
+
/*
|
642
|
+
* Convert an int16[] Datum into a comma-separated list of column names
|
643
|
+
* for the indicated relation; append the list to buf. Returns the number
|
644
|
+
* of keys.
|
645
|
+
*/
|
646
|
+
|
647
|
+
|
648
|
+
|
649
|
+
/* ----------
|
650
|
+
* pg_get_expr - Decompile an expression tree
|
651
|
+
*
|
652
|
+
* Input: an expression tree in nodeToString form, and a relation OID
|
653
|
+
*
|
654
|
+
* Output: reverse-listed expression
|
655
|
+
*
|
656
|
+
* Currently, the expression can only refer to a single relation, namely
|
657
|
+
* the one specified by the second parameter. This is sufficient for
|
658
|
+
* partial indexes, column default expressions, etc. We also support
|
659
|
+
* Var-free expressions, for which the OID can be InvalidOid.
|
660
|
+
* ----------
|
661
|
+
*/
|
662
|
+
|
663
|
+
|
664
|
+
|
665
|
+
|
666
|
+
|
667
|
+
|
668
|
+
|
669
|
+
/* ----------
|
670
|
+
* pg_get_userbyid - Get a user name by roleid and
|
671
|
+
* fallback to 'unknown (OID=n)'
|
672
|
+
* ----------
|
673
|
+
*/
|
674
|
+
|
675
|
+
|
676
|
+
|
677
|
+
/*
|
678
|
+
* pg_get_serial_sequence
|
679
|
+
* Get the name of the sequence used by an identity or serial column,
|
680
|
+
* formatted suitably for passing to setval, nextval or currval.
|
681
|
+
* First parameter is not treated as double-quoted, second parameter
|
682
|
+
* is --- see documentation for reason.
|
683
|
+
*/
|
684
|
+
|
685
|
+
|
686
|
+
|
687
|
+
/*
|
688
|
+
* pg_get_functiondef
|
689
|
+
* Returns the complete "CREATE OR REPLACE FUNCTION ..." statement for
|
690
|
+
* the specified function.
|
691
|
+
*
|
692
|
+
* Note: if you change the output format of this function, be careful not
|
693
|
+
* to break psql's rules (in \ef and \sf) for identifying the start of the
|
694
|
+
* function body. To wit: the function body starts on a line that begins
|
695
|
+
* with "AS ", and no preceding line will look like that.
|
696
|
+
*/
|
697
|
+
|
698
|
+
|
699
|
+
/*
|
700
|
+
* pg_get_function_arguments
|
701
|
+
* Get a nicely-formatted list of arguments for a function.
|
702
|
+
* This is everything that would go between the parentheses in
|
703
|
+
* CREATE FUNCTION.
|
704
|
+
*/
|
705
|
+
|
706
|
+
|
707
|
+
/*
|
708
|
+
* pg_get_function_identity_arguments
|
709
|
+
* Get a formatted list of arguments for a function.
|
710
|
+
* This is everything that would go between the parentheses in
|
711
|
+
* ALTER FUNCTION, etc. In particular, don't print defaults.
|
712
|
+
*/
|
713
|
+
|
714
|
+
|
715
|
+
/*
|
716
|
+
* pg_get_function_result
|
717
|
+
* Get a nicely-formatted version of the result type of a function.
|
718
|
+
* This is what would appear after RETURNS in CREATE FUNCTION.
|
719
|
+
*/
|
720
|
+
|
721
|
+
|
722
|
+
/*
|
723
|
+
* Guts of pg_get_function_result: append the function's return type
|
724
|
+
* to the specified buffer.
|
725
|
+
*/
|
726
|
+
|
727
|
+
|
728
|
+
/*
|
729
|
+
* Common code for pg_get_function_arguments and pg_get_function_result:
|
730
|
+
* append the desired subset of arguments to buf. We print only TABLE
|
731
|
+
* arguments when print_table_args is true, and all the others when it's false.
|
732
|
+
* We print argument defaults only if print_defaults is true.
|
733
|
+
* Function return value is the number of arguments printed.
|
734
|
+
*/
|
735
|
+
|
736
|
+
|
737
|
+
|
738
|
+
|
739
|
+
/*
|
740
|
+
* Append used transformed types to specified buffer
|
741
|
+
*/
|
742
|
+
|
743
|
+
|
744
|
+
/*
|
745
|
+
* Get textual representation of a function argument's default value. The
|
746
|
+
* second argument of this function is the argument number among all arguments
|
747
|
+
* (i.e. proallargtypes, *not* proargtypes), starting with 1, because that's
|
748
|
+
* how information_schema.sql uses it.
|
749
|
+
*/
|
750
|
+
|
751
|
+
|
752
|
+
|
753
|
+
/*
|
754
|
+
* deparse_expression - General utility for deparsing expressions
|
755
|
+
*
|
756
|
+
* calls deparse_expression_pretty with all prettyPrinting disabled
|
757
|
+
*/
|
758
|
+
|
759
|
+
|
760
|
+
/* ----------
|
761
|
+
* deparse_expression_pretty - General utility for deparsing expressions
|
762
|
+
*
|
763
|
+
* expr is the node tree to be deparsed. It must be a transformed expression
|
764
|
+
* tree (ie, not the raw output of gram.y).
|
765
|
+
*
|
766
|
+
* dpcontext is a list of deparse_namespace nodes representing the context
|
767
|
+
* for interpreting Vars in the node tree. It can be NIL if no Vars are
|
768
|
+
* expected.
|
769
|
+
*
|
770
|
+
* forceprefix is true to force all Vars to be prefixed with their table names.
|
771
|
+
*
|
772
|
+
* showimplicit is true to force all implicit casts to be shown explicitly.
|
773
|
+
*
|
774
|
+
* Tries to pretty up the output according to prettyFlags and startIndent.
|
775
|
+
*
|
776
|
+
* The result is a palloc'd string.
|
777
|
+
* ----------
|
778
|
+
*/
|
779
|
+
|
780
|
+
|
781
|
+
/* ----------
|
782
|
+
* deparse_context_for - Build deparse context for a single relation
|
783
|
+
*
|
784
|
+
* Given the reference name (alias) and OID of a relation, build deparsing
|
785
|
+
* context for an expression referencing only that relation (as varno 1,
|
786
|
+
* varlevelsup 0). This is sufficient for many uses of deparse_expression.
|
787
|
+
* ----------
|
788
|
+
*/
|
789
|
+
|
790
|
+
|
791
|
+
/*
|
792
|
+
* deparse_context_for_plan_tree - Build deparse context for a Plan tree
|
793
|
+
*
|
794
|
+
* When deparsing an expression in a Plan tree, we use the plan's rangetable
|
795
|
+
* to resolve names of simple Vars. The initialization of column names for
|
796
|
+
* this is rather expensive if the rangetable is large, and it'll be the same
|
797
|
+
* for every expression in the Plan tree; so we do it just once and re-use
|
798
|
+
* the result of this function for each expression. (Note that the result
|
799
|
+
* is not usable until set_deparse_context_plan() is applied to it.)
|
800
|
+
*
|
801
|
+
* In addition to the PlannedStmt, pass the per-RTE alias names
|
802
|
+
* assigned by a previous call to select_rtable_names_for_explain.
|
803
|
+
*/
|
804
|
+
|
805
|
+
|
806
|
+
/*
|
807
|
+
* set_deparse_context_plan - Specify Plan node containing expression
|
808
|
+
*
|
809
|
+
* When deparsing an expression in a Plan tree, we might have to resolve
|
810
|
+
* OUTER_VAR, INNER_VAR, or INDEX_VAR references. To do this, the caller must
|
811
|
+
* provide the parent Plan node. Then OUTER_VAR and INNER_VAR references
|
812
|
+
* can be resolved by drilling down into the left and right child plans.
|
813
|
+
* Similarly, INDEX_VAR references can be resolved by reference to the
|
814
|
+
* indextlist given in a parent IndexOnlyScan node, or to the scan tlist in
|
815
|
+
* ForeignScan and CustomScan nodes. (Note that we don't currently support
|
816
|
+
* deparsing of indexquals in regular IndexScan or BitmapIndexScan nodes;
|
817
|
+
* for those, we can only deparse the indexqualorig fields, which won't
|
818
|
+
* contain INDEX_VAR Vars.)
|
819
|
+
*
|
820
|
+
* The ancestors list is a list of the Plan's parent Plan and SubPlan nodes,
|
821
|
+
* the most-closely-nested first. This is needed to resolve PARAM_EXEC
|
822
|
+
* Params. Note we assume that all the Plan nodes share the same rtable.
|
823
|
+
*
|
824
|
+
* Once this function has been called, deparse_expression() can be called on
|
825
|
+
* subsidiary expression(s) of the specified Plan node. To deparse
|
826
|
+
* expressions of a different Plan node in the same Plan tree, re-call this
|
827
|
+
* function to identify the new parent Plan node.
|
828
|
+
*
|
829
|
+
* The result is the same List passed in; this is a notational convenience.
|
830
|
+
*/
|
831
|
+
|
832
|
+
|
833
|
+
/*
|
834
|
+
* select_rtable_names_for_explain - Select RTE aliases for EXPLAIN
|
835
|
+
*
|
836
|
+
* Determine the relation aliases we'll use during an EXPLAIN operation.
|
837
|
+
* This is just a frontend to set_rtable_names. We have to expose the aliases
|
838
|
+
* to EXPLAIN because EXPLAIN needs to know the right alias names to print.
|
839
|
+
*/
|
840
|
+
|
841
|
+
|
842
|
+
/*
|
843
|
+
* set_rtable_names: select RTE aliases to be used in printing a query
|
844
|
+
*
|
845
|
+
* We fill in dpns->rtable_names with a list of names that is one-for-one with
|
846
|
+
* the already-filled dpns->rtable list. Each RTE name is unique among those
|
847
|
+
* in the new namespace plus any ancestor namespaces listed in
|
848
|
+
* parent_namespaces.
|
849
|
+
*
|
850
|
+
* If rels_used isn't NULL, only RTE indexes listed in it are given aliases.
|
851
|
+
*
|
852
|
+
* Note that this function is only concerned with relation names, not column
|
853
|
+
* names.
|
854
|
+
*/
|
855
|
+
|
856
|
+
|
857
|
+
/*
|
858
|
+
* set_deparse_for_query: set up deparse_namespace for deparsing a Query tree
|
859
|
+
*
|
860
|
+
* For convenience, this is defined to initialize the deparse_namespace struct
|
861
|
+
* from scratch.
|
862
|
+
*/
|
863
|
+
|
864
|
+
|
865
|
+
/*
|
866
|
+
* set_simple_column_names: fill in column aliases for non-query situations
|
867
|
+
*
|
868
|
+
* This handles EXPLAIN and cases where we only have relation RTEs. Without
|
869
|
+
* a join tree, we can't do anything smart about join RTEs, but we don't
|
870
|
+
* need to (note that EXPLAIN should never see join alias Vars anyway).
|
871
|
+
* If we do hit a join RTE we'll just process it like a non-table base RTE.
|
872
|
+
*/
|
873
|
+
|
874
|
+
|
875
|
+
/*
|
876
|
+
* has_dangerous_join_using: search jointree for unnamed JOIN USING
|
877
|
+
*
|
878
|
+
* Merged columns of a JOIN USING may act differently from either of the input
|
879
|
+
* columns, either because they are merged with COALESCE (in a FULL JOIN) or
|
880
|
+
* because an implicit coercion of the underlying input column is required.
|
881
|
+
* In such a case the column must be referenced as a column of the JOIN not as
|
882
|
+
* a column of either input. And this is problematic if the join is unnamed
|
883
|
+
* (alias-less): we cannot qualify the column's name with an RTE name, since
|
884
|
+
* there is none. (Forcibly assigning an alias to the join is not a solution,
|
885
|
+
* since that will prevent legal references to tables below the join.)
|
886
|
+
* To ensure that every column in the query is unambiguously referenceable,
|
887
|
+
* we must assign such merged columns names that are globally unique across
|
888
|
+
* the whole query, aliasing other columns out of the way as necessary.
|
889
|
+
*
|
890
|
+
* Because the ensuing re-aliasing is fairly damaging to the readability of
|
891
|
+
* the query, we don't do this unless we have to. So, we must pre-scan
|
892
|
+
* the join tree to see if we have to, before starting set_using_names().
|
893
|
+
*/
|
894
|
+
|
895
|
+
|
896
|
+
/*
|
897
|
+
* set_using_names: select column aliases to be used for merged USING columns
|
898
|
+
*
|
899
|
+
* We do this during a recursive descent of the query jointree.
|
900
|
+
* dpns->unique_using must already be set to determine the global strategy.
|
901
|
+
*
|
902
|
+
* Column alias info is saved in the dpns->rtable_columns list, which is
|
903
|
+
* assumed to be filled with pre-zeroed deparse_columns structs.
|
904
|
+
*
|
905
|
+
* parentUsing is a list of all USING aliases assigned in parent joins of
|
906
|
+
* the current jointree node. (The passed-in list must not be modified.)
|
907
|
+
*/
|
908
|
+
|
909
|
+
|
910
|
+
/*
|
911
|
+
* set_relation_column_names: select column aliases for a non-join RTE
|
912
|
+
*
|
913
|
+
* Column alias info is saved in *colinfo, which is assumed to be pre-zeroed.
|
914
|
+
* If any colnames entries are already filled in, those override local
|
915
|
+
* choices.
|
916
|
+
*/
|
917
|
+
|
918
|
+
|
919
|
+
/*
|
920
|
+
* set_join_column_names: select column aliases for a join RTE
|
921
|
+
*
|
922
|
+
* Column alias info is saved in *colinfo, which is assumed to be pre-zeroed.
|
923
|
+
* If any colnames entries are already filled in, those override local
|
924
|
+
* choices. Also, names for USING columns were already chosen by
|
925
|
+
* set_using_names(). We further expect that column alias selection has been
|
926
|
+
* completed for both input RTEs.
|
927
|
+
*/
|
928
|
+
#ifdef USE_ASSERT_CHECKING
|
929
|
+
#endif
|
930
|
+
|
931
|
+
/*
|
932
|
+
* colname_is_unique: is colname distinct from already-chosen column names?
|
933
|
+
*
|
934
|
+
* dpns is query-wide info, colinfo is for the column's RTE
|
935
|
+
*/
|
936
|
+
|
937
|
+
|
938
|
+
/*
|
939
|
+
* make_colname_unique: modify colname if necessary to make it unique
|
940
|
+
*
|
941
|
+
* dpns is query-wide info, colinfo is for the column's RTE
|
942
|
+
*/
|
943
|
+
|
944
|
+
|
945
|
+
/*
|
946
|
+
* expand_colnames_array_to: make colinfo->colnames at least n items long
|
947
|
+
*
|
948
|
+
* Any added array entries are initialized to zero.
|
949
|
+
*/
|
950
|
+
|
951
|
+
|
952
|
+
/*
|
953
|
+
* identify_join_columns: figure out where columns of a join come from
|
954
|
+
*
|
955
|
+
* Fills the join-specific fields of the colinfo struct, except for
|
956
|
+
* usingNames which is filled later.
|
957
|
+
*/
|
958
|
+
|
959
|
+
|
960
|
+
/*
|
961
|
+
* get_rtable_name: convenience function to get a previously assigned RTE alias
|
962
|
+
*
|
963
|
+
* The RTE must belong to the topmost namespace level in "context".
|
964
|
+
*/
|
965
|
+
|
966
|
+
|
967
|
+
/*
|
968
|
+
* set_deparse_plan: set up deparse_namespace to parse subexpressions
|
969
|
+
* of a given Plan node
|
970
|
+
*
|
971
|
+
* This sets the plan, outer_plan, inner_plan, outer_tlist, inner_tlist,
|
972
|
+
* and index_tlist fields. Caller is responsible for adjusting the ancestors
|
973
|
+
* list if necessary. Note that the rtable, subplans, and ctes fields do
|
974
|
+
* not need to change when shifting attention to different plan nodes in a
|
975
|
+
* single plan tree.
|
976
|
+
*/
|
977
|
+
|
978
|
+
|
979
|
+
/*
|
980
|
+
* push_child_plan: temporarily transfer deparsing attention to a child plan
|
981
|
+
*
|
982
|
+
* When expanding an OUTER_VAR or INNER_VAR reference, we must adjust the
|
983
|
+
* deparse context in case the referenced expression itself uses
|
984
|
+
* OUTER_VAR/INNER_VAR. We modify the top stack entry in-place to avoid
|
985
|
+
* affecting levelsup issues (although in a Plan tree there really shouldn't
|
986
|
+
* be any).
|
987
|
+
*
|
988
|
+
* Caller must provide a local deparse_namespace variable to save the
|
989
|
+
* previous state for pop_child_plan.
|
990
|
+
*/
|
991
|
+
|
992
|
+
|
993
|
+
/*
|
994
|
+
* pop_child_plan: undo the effects of push_child_plan
|
995
|
+
*/
|
996
|
+
|
997
|
+
|
998
|
+
/*
|
999
|
+
* push_ancestor_plan: temporarily transfer deparsing attention to an
|
1000
|
+
* ancestor plan
|
1001
|
+
*
|
1002
|
+
* When expanding a Param reference, we must adjust the deparse context
|
1003
|
+
* to match the plan node that contains the expression being printed;
|
1004
|
+
* otherwise we'd fail if that expression itself contains a Param or
|
1005
|
+
* OUTER_VAR/INNER_VAR/INDEX_VAR variable.
|
1006
|
+
*
|
1007
|
+
* The target ancestor is conveniently identified by the ListCell holding it
|
1008
|
+
* in dpns->ancestors.
|
1009
|
+
*
|
1010
|
+
* Caller must provide a local deparse_namespace variable to save the
|
1011
|
+
* previous state for pop_ancestor_plan.
|
1012
|
+
*/
|
1013
|
+
|
1014
|
+
|
1015
|
+
/*
|
1016
|
+
* pop_ancestor_plan: undo the effects of push_ancestor_plan
|
1017
|
+
*/
|
1018
|
+
|
1019
|
+
|
1020
|
+
|
1021
|
+
/* ----------
|
1022
|
+
* make_ruledef - reconstruct the CREATE RULE command
|
1023
|
+
* for a given pg_rewrite tuple
|
1024
|
+
* ----------
|
1025
|
+
*/
|
1026
|
+
|
1027
|
+
|
1028
|
+
|
1029
|
+
/* ----------
|
1030
|
+
* make_viewdef - reconstruct the SELECT part of a
|
1031
|
+
* view rewrite rule
|
1032
|
+
* ----------
|
1033
|
+
*/
|
1034
|
+
|
1035
|
+
|
1036
|
+
|
1037
|
+
/* ----------
|
1038
|
+
* get_query_def - Parse back one query parsetree
|
1039
|
+
*
|
1040
|
+
* If resultDesc is not NULL, then it is the output tuple descriptor for
|
1041
|
+
* the view represented by a SELECT query.
|
1042
|
+
* ----------
|
1043
|
+
*/
|
1044
|
+
|
1045
|
+
|
1046
|
+
/* ----------
|
1047
|
+
* get_values_def - Parse back a VALUES list
|
1048
|
+
* ----------
|
1049
|
+
*/
|
1050
|
+
|
1051
|
+
|
1052
|
+
/* ----------
|
1053
|
+
* get_with_clause - Parse back a WITH clause
|
1054
|
+
* ----------
|
1055
|
+
*/
|
1056
|
+
|
1057
|
+
|
1058
|
+
/* ----------
|
1059
|
+
* get_select_query_def - Parse back a SELECT parsetree
|
1060
|
+
* ----------
|
1061
|
+
*/
|
1062
|
+
|
1063
|
+
|
1064
|
+
/*
|
1065
|
+
* Detect whether query looks like SELECT ... FROM VALUES(),
|
1066
|
+
* with no need to rename the output columns of the VALUES RTE.
|
1067
|
+
* If so, return the VALUES RTE. Otherwise return NULL.
|
1068
|
+
*/
|
1069
|
+
|
1070
|
+
|
1071
|
+
|
1072
|
+
|
1073
|
+
/* ----------
|
1074
|
+
* get_target_list - Parse back a SELECT target list
|
1075
|
+
*
|
1076
|
+
* This is also used for RETURNING lists in INSERT/UPDATE/DELETE.
|
1077
|
+
* ----------
|
1078
|
+
*/
|
1079
|
+
|
1080
|
+
|
1081
|
+
|
1082
|
+
|
1083
|
+
/*
|
1084
|
+
* Display a sort/group clause.
|
1085
|
+
*
|
1086
|
+
* Also returns the expression tree, so caller need not find it again.
|
1087
|
+
*/
|
1088
|
+
|
1089
|
+
|
1090
|
+
/*
|
1091
|
+
* Display a GroupingSet
|
1092
|
+
*/
|
1093
|
+
|
1094
|
+
|
1095
|
+
/*
|
1096
|
+
* Display an ORDER BY list.
|
1097
|
+
*/
|
1098
|
+
|
1099
|
+
|
1100
|
+
/*
|
1101
|
+
* Display a WINDOW clause.
|
1102
|
+
*
|
1103
|
+
* Note that the windowClause list might contain only anonymous window
|
1104
|
+
* specifications, in which case we should print nothing here.
|
1105
|
+
*/
|
1106
|
+
|
1107
|
+
|
1108
|
+
/*
|
1109
|
+
* Display a window definition
|
1110
|
+
*/
|
1111
|
+
|
1112
|
+
|
1113
|
+
/* ----------
|
1114
|
+
* get_insert_query_def - Parse back an INSERT parsetree
|
1115
|
+
* ----------
|
1116
|
+
*/
|
1117
|
+
|
1118
|
+
|
1119
|
+
|
1120
|
+
/* ----------
|
1121
|
+
* get_update_query_def - Parse back an UPDATE parsetree
|
1122
|
+
* ----------
|
1123
|
+
*/
|
1124
|
+
|
1125
|
+
|
1126
|
+
|
1127
|
+
/* ----------
|
1128
|
+
* get_update_query_targetlist_def - Parse back an UPDATE targetlist
|
1129
|
+
* ----------
|
1130
|
+
*/
|
1131
|
+
|
1132
|
+
|
1133
|
+
|
1134
|
+
/* ----------
|
1135
|
+
* get_delete_query_def - Parse back a DELETE parsetree
|
1136
|
+
* ----------
|
1137
|
+
*/
|
1138
|
+
|
1139
|
+
|
1140
|
+
|
1141
|
+
/* ----------
|
1142
|
+
* get_utility_query_def - Parse back a UTILITY parsetree
|
1143
|
+
* ----------
|
1144
|
+
*/
|
1145
|
+
|
1146
|
+
|
1147
|
+
/*
|
1148
|
+
* Display a Var appropriately.
|
1149
|
+
*
|
1150
|
+
* In some cases (currently only when recursing into an unnamed join)
|
1151
|
+
* the Var's varlevelsup has to be interpreted with respect to a context
|
1152
|
+
* above the current one; levelsup indicates the offset.
|
1153
|
+
*
|
1154
|
+
* If istoplevel is true, the Var is at the top level of a SELECT's
|
1155
|
+
* targetlist, which means we need special treatment of whole-row Vars.
|
1156
|
+
* Instead of the normal "tab.*", we'll print "tab.*::typename", which is a
|
1157
|
+
* dirty hack to prevent "tab.*" from being expanded into multiple columns.
|
1158
|
+
* (The parser will strip the useless coercion, so no inefficiency is added in
|
1159
|
+
* dump and reload.) We used to print just "tab" in such cases, but that is
|
1160
|
+
* ambiguous and will yield the wrong result if "tab" is also a plain column
|
1161
|
+
* name in the query.
|
1162
|
+
*
|
1163
|
+
* Returns the attname of the Var, or NULL if the Var has no attname (because
|
1164
|
+
* it is a whole-row Var or a subplan output reference).
|
1165
|
+
*/
|
1166
|
+
|
1167
|
+
|
1168
|
+
/*
|
1169
|
+
* Deparse a Var which references OUTER_VAR, INNER_VAR, or INDEX_VAR. This
|
1170
|
+
* routine is actually a callback for resolve_special_varno, which handles
|
1171
|
+
* finding the correct TargetEntry. We get the expression contained in that
|
1172
|
+
* TargetEntry and just need to deparse it, a job we can throw back on
|
1173
|
+
* get_rule_expr.
|
1174
|
+
*/
|
1175
|
+
|
1176
|
+
|
1177
|
+
/*
|
1178
|
+
* Chase through plan references to special varnos (OUTER_VAR, INNER_VAR,
|
1179
|
+
* INDEX_VAR) until we find a real Var or some kind of non-Var node; then,
|
1180
|
+
* invoke the callback provided.
|
1181
|
+
*/
|
1182
|
+
|
1183
|
+
|
1184
|
+
/*
|
1185
|
+
* Get the name of a field of an expression of composite type. The
|
1186
|
+
* expression is usually a Var, but we handle other cases too.
|
1187
|
+
*
|
1188
|
+
* levelsup is an extra offset to interpret the Var's varlevelsup correctly.
|
1189
|
+
*
|
1190
|
+
* This is fairly straightforward when the expression has a named composite
|
1191
|
+
* type; we need only look up the type in the catalogs. However, the type
|
1192
|
+
* could also be RECORD. Since no actual table or view column is allowed to
|
1193
|
+
* have type RECORD, a Var of type RECORD must refer to a JOIN or FUNCTION RTE
|
1194
|
+
* or to a subquery output. We drill down to find the ultimate defining
|
1195
|
+
* expression and attempt to infer the field name from it. We ereport if we
|
1196
|
+
* can't determine the name.
|
1197
|
+
*
|
1198
|
+
* Similarly, a PARAM of type RECORD has to refer to some expression of
|
1199
|
+
* a determinable composite type.
|
1200
|
+
*/
|
1201
|
+
|
1202
|
+
|
1203
|
+
/*
|
1204
|
+
* Try to find the referenced expression for a PARAM_EXEC Param that might
|
1205
|
+
* reference a parameter supplied by an upper NestLoop or SubPlan plan node.
|
1206
|
+
*
|
1207
|
+
* If successful, return the expression and set *dpns_p and *ancestor_cell_p
|
1208
|
+
* appropriately for calling push_ancestor_plan(). If no referent can be
|
1209
|
+
* found, return NULL.
|
1210
|
+
*/
|
1211
|
+
|
1212
|
+
|
1213
|
+
/*
|
1214
|
+
* Display a Param appropriately.
|
1215
|
+
*/
|
1216
|
+
|
1217
|
+
|
1218
|
+
/*
|
1219
|
+
* get_simple_binary_op_name
|
1220
|
+
*
|
1221
|
+
* helper function for isSimpleNode
|
1222
|
+
* will return single char binary operator name, or NULL if it's not
|
1223
|
+
*/
|
1224
|
+
|
1225
|
+
|
1226
|
+
|
1227
|
+
/*
|
1228
|
+
* isSimpleNode - check if given node is simple (doesn't need parenthesizing)
|
1229
|
+
*
|
1230
|
+
* true : simple in the context of parent node's type
|
1231
|
+
* false : not simple
|
1232
|
+
*/
|
1233
|
+
|
1234
|
+
|
1235
|
+
|
1236
|
+
/*
|
1237
|
+
* appendContextKeyword - append a keyword to buffer
|
1238
|
+
*
|
1239
|
+
* If prettyPrint is enabled, perform a line break, and adjust indentation.
|
1240
|
+
* Otherwise, just append the keyword.
|
1241
|
+
*/
|
1242
|
+
|
1243
|
+
|
1244
|
+
/*
|
1245
|
+
* removeStringInfoSpaces - delete trailing spaces from a buffer.
|
1246
|
+
*
|
1247
|
+
* Possibly this should move to stringinfo.c at some point.
|
1248
|
+
*/
|
1249
|
+
|
1250
|
+
|
1251
|
+
|
1252
|
+
/*
|
1253
|
+
* get_rule_expr_paren - deparse expr using get_rule_expr,
|
1254
|
+
* embracing the string with parentheses if necessary for prettyPrint.
|
1255
|
+
*
|
1256
|
+
* Never embrace if prettyFlags=0, because it's done in the calling node.
|
1257
|
+
*
|
1258
|
+
* Any node that does *not* embrace its argument node by sql syntax (with
|
1259
|
+
* parentheses, non-operator keywords like CASE/WHEN/ON, or comma etc) should
|
1260
|
+
* use get_rule_expr_paren instead of get_rule_expr so parentheses can be
|
1261
|
+
* added.
|
1262
|
+
*/
|
1263
|
+
|
1264
|
+
|
1265
|
+
|
1266
|
+
/* ----------
|
1267
|
+
* get_rule_expr - Parse back an expression
|
1268
|
+
*
|
1269
|
+
* Note: showimplicit determines whether we display any implicit cast that
|
1270
|
+
* is present at the top of the expression tree. It is a passed argument,
|
1271
|
+
* not a field of the context struct, because we change the value as we
|
1272
|
+
* recurse down into the expression. In general we suppress implicit casts
|
1273
|
+
* when the result type is known with certainty (eg, the arguments of an
|
1274
|
+
* OR must be boolean). We display implicit casts for arguments of functions
|
1275
|
+
* and operators, since this is needed to be certain that the same function
|
1276
|
+
* or operator will be chosen when the expression is re-parsed.
|
1277
|
+
* ----------
|
1278
|
+
*/
|
1279
|
+
|
1280
|
+
|
1281
|
+
/*
|
1282
|
+
* get_rule_expr_toplevel - Parse back a toplevel expression
|
1283
|
+
*
|
1284
|
+
* Same as get_rule_expr(), except that if the expr is just a Var, we pass
|
1285
|
+
* istoplevel = true not false to get_variable(). This causes whole-row Vars
|
1286
|
+
* to get printed with decoration that will prevent expansion of "*".
|
1287
|
+
* We need to use this in contexts such as ROW() and VALUES(), where the
|
1288
|
+
* parser would expand "foo.*" appearing at top level. (In principle we'd
|
1289
|
+
* use this in get_target_list() too, but that has additional worries about
|
1290
|
+
* whether to print AS, so it needs to invoke get_variable() directly anyway.)
|
1291
|
+
*/
|
1292
|
+
|
1293
|
+
|
1294
|
+
/*
|
1295
|
+
* get_rule_expr_funccall - Parse back a function-call expression
|
1296
|
+
*
|
1297
|
+
* Same as get_rule_expr(), except that we guarantee that the output will
|
1298
|
+
* look like a function call, or like one of the things the grammar treats as
|
1299
|
+
* equivalent to a function call (see the func_expr_windowless production).
|
1300
|
+
* This is needed in places where the grammar uses func_expr_windowless and
|
1301
|
+
* you can't substitute a parenthesized a_expr. If what we have isn't going
|
1302
|
+
* to look like a function call, wrap it in a dummy CAST() expression, which
|
1303
|
+
* will satisfy the grammar --- and, indeed, is likely what the user wrote to
|
1304
|
+
* produce such a thing.
|
1305
|
+
*/
|
1306
|
+
|
1307
|
+
|
1308
|
+
/*
|
1309
|
+
* Helper function to identify node types that satisfy func_expr_windowless.
|
1310
|
+
* If in doubt, "false" is always a safe answer.
|
1311
|
+
*/
|
1312
|
+
|
1313
|
+
|
1314
|
+
|
1315
|
+
/*
|
1316
|
+
* get_oper_expr - Parse back an OpExpr node
|
1317
|
+
*/
|
1318
|
+
|
1319
|
+
|
1320
|
+
/*
|
1321
|
+
* get_func_expr - Parse back a FuncExpr node
|
1322
|
+
*/
|
1323
|
+
|
1324
|
+
|
1325
|
+
/*
|
1326
|
+
* get_agg_expr - Parse back an Aggref node
|
1327
|
+
*/
|
1328
|
+
|
1329
|
+
|
1330
|
+
/*
|
1331
|
+
* This is a helper function for get_agg_expr(). It's used when we deparse
|
1332
|
+
* a combining Aggref; resolve_special_varno locates the corresponding partial
|
1333
|
+
* Aggref and then calls this.
|
1334
|
+
*/
|
1335
|
+
|
1336
|
+
|
1337
|
+
/*
|
1338
|
+
* get_windowfunc_expr - Parse back a WindowFunc node
|
1339
|
+
*/
|
1340
|
+
|
1341
|
+
|
1342
|
+
/* ----------
|
1343
|
+
* get_coercion_expr
|
1344
|
+
*
|
1345
|
+
* Make a string representation of a value coerced to a specific type
|
1346
|
+
* ----------
|
1347
|
+
*/
|
1348
|
+
|
1349
|
+
|
1350
|
+
/* ----------
|
1351
|
+
* get_const_expr
|
1352
|
+
*
|
1353
|
+
* Make a string representation of a Const
|
1354
|
+
*
|
1355
|
+
* showtype can be -1 to never show "::typename" decoration, or +1 to always
|
1356
|
+
* show it, or 0 to show it only if the constant wouldn't be assumed to be
|
1357
|
+
* the right type by default.
|
1358
|
+
*
|
1359
|
+
* If the Const's collation isn't default for its type, show that too.
|
1360
|
+
* We mustn't do this when showtype is -1 (since that means the caller will
|
1361
|
+
* print "::typename", and we can't put a COLLATE clause in between). It's
|
1362
|
+
* caller's responsibility that collation isn't missed in such cases.
|
1363
|
+
* ----------
|
1364
|
+
*/
|
1365
|
+
|
1366
|
+
|
1367
|
+
/*
|
1368
|
+
* helper for get_const_expr: append COLLATE if needed
|
1369
|
+
*/
|
1370
|
+
|
1371
|
+
|
1372
|
+
/*
|
1373
|
+
* simple_quote_literal - Format a string as a SQL literal, append to buf
|
1374
|
+
*/
|
1375
|
+
|
1376
|
+
|
1377
|
+
|
1378
|
+
/* ----------
|
1379
|
+
* get_sublink_expr - Parse back a sublink
|
1380
|
+
* ----------
|
1381
|
+
*/
|
1382
|
+
|
1383
|
+
|
1384
|
+
|
1385
|
+
/* ----------
|
1386
|
+
* get_tablefunc - Parse back a table function
|
1387
|
+
* ----------
|
1388
|
+
*/
|
1389
|
+
|
1390
|
+
|
1391
|
+
/* ----------
|
1392
|
+
* get_from_clause - Parse back a FROM clause
|
1393
|
+
*
|
1394
|
+
* "prefix" is the keyword that denotes the start of the list of FROM
|
1395
|
+
* elements. It is FROM when used to parse back SELECT and UPDATE, but
|
1396
|
+
* is USING when parsing back DELETE.
|
1397
|
+
* ----------
|
1398
|
+
*/
|
1399
|
+
|
1400
|
+
|
1401
|
+
|
1402
|
+
|
1403
|
+
/*
|
1404
|
+
* get_column_alias_list - print column alias list for an RTE
|
1405
|
+
*
|
1406
|
+
* Caller must already have printed the relation's alias name.
|
1407
|
+
*/
|
1408
|
+
|
1409
|
+
|
1410
|
+
/*
|
1411
|
+
* get_from_clause_coldeflist - reproduce FROM clause coldeflist
|
1412
|
+
*
|
1413
|
+
* When printing a top-level coldeflist (which is syntactically also the
|
1414
|
+
* relation's column alias list), use column names from colinfo. But when
|
1415
|
+
* printing a coldeflist embedded inside ROWS FROM(), we prefer to use the
|
1416
|
+
* original coldeflist's names, which are available in rtfunc->funccolnames.
|
1417
|
+
* Pass NULL for colinfo to select the latter behavior.
|
1418
|
+
*
|
1419
|
+
* The coldeflist is appended immediately (no space) to buf. Caller is
|
1420
|
+
* responsible for ensuring that an alias or AS is present before it.
|
1421
|
+
*/
|
1422
|
+
|
1423
|
+
|
1424
|
+
/*
|
1425
|
+
* get_tablesample_def - print a TableSampleClause
|
1426
|
+
*/
|
1427
|
+
|
1428
|
+
|
1429
|
+
/*
|
1430
|
+
* get_opclass_name - fetch name of an index operator class
|
1431
|
+
*
|
1432
|
+
* The opclass name is appended (after a space) to buf.
|
1433
|
+
*
|
1434
|
+
* Output is suppressed if the opclass is the default for the given
|
1435
|
+
* actual_datatype. (If you don't want this behavior, just pass
|
1436
|
+
* InvalidOid for actual_datatype.)
|
1437
|
+
*/
|
1438
|
+
|
1439
|
+
|
1440
|
+
/*
|
1441
|
+
* generate_opclass_name
|
1442
|
+
* Compute the name to display for a opclass specified by OID
|
1443
|
+
*
|
1444
|
+
* The result includes all necessary quoting and schema-prefixing.
|
1445
|
+
*/
|
1446
|
+
|
1447
|
+
|
1448
|
+
/*
|
1449
|
+
* processIndirection - take care of array and subfield assignment
|
1450
|
+
*
|
1451
|
+
* We strip any top-level FieldStore or assignment SubscriptingRef nodes that
|
1452
|
+
* appear in the input, printing them as decoration for the base column
|
1453
|
+
* name (which we assume the caller just printed). We might also need to
|
1454
|
+
* strip CoerceToDomain nodes, but only ones that appear above assignment
|
1455
|
+
* nodes.
|
1456
|
+
*
|
1457
|
+
* Returns the subexpression that's to be assigned.
|
1458
|
+
*/
|
1459
|
+
|
1460
|
+
|
1461
|
+
|
1462
|
+
|
1463
|
+
/*
|
1464
|
+
* quote_identifier - Quote an identifier only if needed
|
1465
|
+
*
|
1466
|
+
* When quotes are needed, we palloc the required space; slightly
|
1467
|
+
* space-wasteful but well worth it for notational simplicity.
|
1468
|
+
*/
|
1469
|
+
const char *
|
1470
|
+
quote_identifier(const char *ident)
|
1471
|
+
{
|
1472
|
+
/*
|
1473
|
+
* Can avoid quoting if ident starts with a lowercase letter or underscore
|
1474
|
+
* and contains only lowercase letters, digits, and underscores, *and* is
|
1475
|
+
* not any SQL keyword. Otherwise, supply quotes.
|
1476
|
+
*/
|
1477
|
+
int nquotes = 0;
|
1478
|
+
bool safe;
|
1479
|
+
const char *ptr;
|
1480
|
+
char *result;
|
1481
|
+
char *optr;
|
1482
|
+
|
1483
|
+
/*
|
1484
|
+
* would like to use <ctype.h> macros here, but they might yield unwanted
|
1485
|
+
* locale-specific results...
|
1486
|
+
*/
|
1487
|
+
safe = ((ident[0] >= 'a' && ident[0] <= 'z') || ident[0] == '_');
|
1488
|
+
|
1489
|
+
for (ptr = ident; *ptr; ptr++)
|
1490
|
+
{
|
1491
|
+
char ch = *ptr;
|
1492
|
+
|
1493
|
+
if ((ch >= 'a' && ch <= 'z') ||
|
1494
|
+
(ch >= '0' && ch <= '9') ||
|
1495
|
+
(ch == '_'))
|
1496
|
+
{
|
1497
|
+
/* okay */
|
1498
|
+
}
|
1499
|
+
else
|
1500
|
+
{
|
1501
|
+
safe = false;
|
1502
|
+
if (ch == '"')
|
1503
|
+
nquotes++;
|
1504
|
+
}
|
1505
|
+
}
|
1506
|
+
|
1507
|
+
if (quote_all_identifiers)
|
1508
|
+
safe = false;
|
1509
|
+
|
1510
|
+
if (safe)
|
1511
|
+
{
|
1512
|
+
/*
|
1513
|
+
* Check for keyword. We quote keywords except for unreserved ones.
|
1514
|
+
* (In some cases we could avoid quoting a col_name or type_func_name
|
1515
|
+
* keyword, but it seems much harder than it's worth to tell that.)
|
1516
|
+
*
|
1517
|
+
* Note: ScanKeywordLookup() does case-insensitive comparison, but
|
1518
|
+
* that's fine, since we already know we have all-lower-case.
|
1519
|
+
*/
|
1520
|
+
int kwnum = ScanKeywordLookup(ident, &ScanKeywords);
|
1521
|
+
|
1522
|
+
if (kwnum >= 0 && ScanKeywordCategories[kwnum] != UNRESERVED_KEYWORD)
|
1523
|
+
safe = false;
|
1524
|
+
}
|
1525
|
+
|
1526
|
+
if (safe)
|
1527
|
+
return ident; /* no change needed */
|
1528
|
+
|
1529
|
+
result = (char *) palloc(strlen(ident) + nquotes + 2 + 1);
|
1530
|
+
|
1531
|
+
optr = result;
|
1532
|
+
*optr++ = '"';
|
1533
|
+
for (ptr = ident; *ptr; ptr++)
|
1534
|
+
{
|
1535
|
+
char ch = *ptr;
|
1536
|
+
|
1537
|
+
if (ch == '"')
|
1538
|
+
*optr++ = '"';
|
1539
|
+
*optr++ = ch;
|
1540
|
+
}
|
1541
|
+
*optr++ = '"';
|
1542
|
+
*optr = '\0';
|
1543
|
+
|
1544
|
+
return result;
|
1545
|
+
}
|
1546
|
+
|
1547
|
+
/*
|
1548
|
+
* quote_qualified_identifier - Quote a possibly-qualified identifier
|
1549
|
+
*
|
1550
|
+
* Return a name of the form qualifier.ident, or just ident if qualifier
|
1551
|
+
* is NULL, quoting each component if necessary. The result is palloc'd.
|
1552
|
+
*/
|
1553
|
+
|
1554
|
+
|
1555
|
+
/*
|
1556
|
+
* get_relation_name
|
1557
|
+
* Get the unqualified name of a relation specified by OID
|
1558
|
+
*
|
1559
|
+
* This differs from the underlying get_rel_name() function in that it will
|
1560
|
+
* throw error instead of silently returning NULL if the OID is bad.
|
1561
|
+
*/
|
1562
|
+
|
1563
|
+
|
1564
|
+
/*
|
1565
|
+
* generate_relation_name
|
1566
|
+
* Compute the name to display for a relation specified by OID
|
1567
|
+
*
|
1568
|
+
* The result includes all necessary quoting and schema-prefixing.
|
1569
|
+
*
|
1570
|
+
* If namespaces isn't NIL, it must be a list of deparse_namespace nodes.
|
1571
|
+
* We will forcibly qualify the relation name if it equals any CTE name
|
1572
|
+
* visible in the namespace list.
|
1573
|
+
*/
|
1574
|
+
|
1575
|
+
|
1576
|
+
/*
|
1577
|
+
* generate_qualified_relation_name
|
1578
|
+
* Compute the name to display for a relation specified by OID
|
1579
|
+
*
|
1580
|
+
* As above, but unconditionally schema-qualify the name.
|
1581
|
+
*/
|
1582
|
+
|
1583
|
+
|
1584
|
+
/*
|
1585
|
+
* generate_function_name
|
1586
|
+
* Compute the name to display for a function specified by OID,
|
1587
|
+
* given that it is being called with the specified actual arg names and
|
1588
|
+
* types. (Those matter because of ambiguous-function resolution rules.)
|
1589
|
+
*
|
1590
|
+
* If we're dealing with a potentially variadic function (in practice, this
|
1591
|
+
* means a FuncExpr or Aggref, not some other way of calling a function), then
|
1592
|
+
* has_variadic must specify whether variadic arguments have been merged,
|
1593
|
+
* and *use_variadic_p will be set to indicate whether to print VARIADIC in
|
1594
|
+
* the output. For non-FuncExpr cases, has_variadic should be false and
|
1595
|
+
* use_variadic_p can be NULL.
|
1596
|
+
*
|
1597
|
+
* The result includes all necessary quoting and schema-prefixing.
|
1598
|
+
*/
|
1599
|
+
|
1600
|
+
|
1601
|
+
/*
|
1602
|
+
* generate_operator_name
|
1603
|
+
* Compute the name to display for an operator specified by OID,
|
1604
|
+
* given that it is being called with the specified actual arg types.
|
1605
|
+
* (Arg types matter because of ambiguous-operator resolution rules.
|
1606
|
+
* Pass InvalidOid for unused arg of a unary operator.)
|
1607
|
+
*
|
1608
|
+
* The result includes all necessary quoting and schema-prefixing,
|
1609
|
+
* plus the OPERATOR() decoration needed to use a qualified operator name
|
1610
|
+
* in an expression.
|
1611
|
+
*/
|
1612
|
+
|
1613
|
+
|
1614
|
+
/*
|
1615
|
+
* generate_operator_clause --- generate a binary-operator WHERE clause
|
1616
|
+
*
|
1617
|
+
* This is used for internally-generated-and-executed SQL queries, where
|
1618
|
+
* precision is essential and readability is secondary. The basic
|
1619
|
+
* requirement is to append "leftop op rightop" to buf, where leftop and
|
1620
|
+
* rightop are given as strings and are assumed to yield types leftoptype
|
1621
|
+
* and rightoptype; the operator is identified by OID. The complexity
|
1622
|
+
* comes from needing to be sure that the parser will select the desired
|
1623
|
+
* operator when the query is parsed. We always name the operator using
|
1624
|
+
* OPERATOR(schema.op) syntax, so as to avoid search-path uncertainties.
|
1625
|
+
* We have to emit casts too, if either input isn't already the input type
|
1626
|
+
* of the operator; else we are at the mercy of the parser's heuristics for
|
1627
|
+
* ambiguous-operator resolution. The caller must ensure that leftop and
|
1628
|
+
* rightop are suitable arguments for a cast operation; it's best to insert
|
1629
|
+
* parentheses if they aren't just variables or parameters.
|
1630
|
+
*/
|
1631
|
+
|
1632
|
+
|
1633
|
+
/*
|
1634
|
+
* Add a cast specification to buf. We spell out the type name the hard way,
|
1635
|
+
* intentionally not using format_type_be(). This is to avoid corner cases
|
1636
|
+
* for CHARACTER, BIT, and perhaps other types, where specifying the type
|
1637
|
+
* using SQL-standard syntax results in undesirable data truncation. By
|
1638
|
+
* doing it this way we can be certain that the cast will have default (-1)
|
1639
|
+
* target typmod.
|
1640
|
+
*/
|
1641
|
+
|
1642
|
+
|
1643
|
+
/*
|
1644
|
+
* generate_qualified_type_name
|
1645
|
+
* Compute the name to display for a type specified by OID
|
1646
|
+
*
|
1647
|
+
* This is different from format_type_be() in that we unconditionally
|
1648
|
+
* schema-qualify the name. That also means no special syntax for
|
1649
|
+
* SQL-standard type names ... although in current usage, this should
|
1650
|
+
* only get used for domains, so such cases wouldn't occur anyway.
|
1651
|
+
*/
|
1652
|
+
|
1653
|
+
|
1654
|
+
/*
|
1655
|
+
* generate_collation_name
|
1656
|
+
* Compute the name to display for a collation specified by OID
|
1657
|
+
*
|
1658
|
+
* The result includes all necessary quoting and schema-prefixing.
|
1659
|
+
*/
|
1660
|
+
|
1661
|
+
|
1662
|
+
/*
|
1663
|
+
* Given a C string, produce a TEXT datum.
|
1664
|
+
*
|
1665
|
+
* We assume that the input was palloc'd and may be freed.
|
1666
|
+
*/
|
1667
|
+
|
1668
|
+
|
1669
|
+
/*
|
1670
|
+
* Generate a C string representing a relation options from text[] datum.
|
1671
|
+
*/
|
1672
|
+
|
1673
|
+
|
1674
|
+
/*
|
1675
|
+
* Generate a C string representing a relation's reloptions, or NULL if none.
|
1676
|
+
*/
|
1677
|
+
|
1678
|
+
|
1679
|
+
/*
|
1680
|
+
* get_range_partbound_string
|
1681
|
+
* A C string representation of one range partition bound
|
1682
|
+
*/
|
1683
|
+
|