From: | Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> |
---|---|
To: | Joe Conway <mail(at)joeconway(dot)com> |
Cc: | PostgreSQL Patches <pgsql-patches(at)postgresql(dot)org>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Subject: | Re: Anonymous-record-types omission |
Date: | 2002-08-28 21:16:27 |
Message-ID: | 200208282116.g7SLGRp04057@candle.pha.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-patches |
Your patch has been added to the PostgreSQL unapplied patches list at:
http://candle.pha.pa.us/cgi-bin/pgpatches
I will try to apply it within the next 48 hours.
---------------------------------------------------------------------------
Joe Conway wrote:
> Tom Lane found an omission in the committed anonymous type code. The
> coldeflist in the FROM clause was not being dumped by ruleutils.c. The
> attached patch fixes this. Example:
>
> -- before --
>
> regression=# \d pg_settings
> View "pg_catalog.pg_settings"
> Column | Type | Modifiers
> ---------+------+-----------
> name | text |
> setting | text |
> View definition: SELECT a.name, a.setting FROM pg_show_all_settings() a;
> Rules: pg_settings_u,
> pg_settings_n
>
> -- and after --
>
> test=# \d pg_settings
> View "pg_catalog.pg_settings"
> Column | Type | Modifiers
> ---------+------+-----------
> name | text |
> setting | text |
> View definition: SELECT a.name, a.setting FROM pg_show_all_settings()
> a(name text, setting text);
> Rules: pg_settings_u,
> pg_settings_n
>
>
> Also included is the related adjustment to expected/rules.out. If there
> are no objections, please apply.
>
> Thanks,
>
> Joe
> Index: src/backend/utils/adt/ruleutils.c
> ===================================================================
> RCS file: /opt/src/cvs/pgsql-server/src/backend/utils/adt/ruleutils.c,v
> retrieving revision 1.118
> diff -c -r1.118 ruleutils.c
> *** src/backend/utils/adt/ruleutils.c 26 Aug 2002 17:53:58 -0000 1.118
> --- src/backend/utils/adt/ruleutils.c 28 Aug 2002 04:11:54 -0000
> ***************
> *** 61,66 ****
> --- 61,67 ----
> #include "parser/parse_expr.h"
> #include "parser/parse_func.h"
> #include "parser/parse_oper.h"
> + #include "parser/parse_type.h"
> #include "parser/parsetree.h"
> #include "rewrite/rewriteManip.h"
> #include "rewrite/rewriteSupport.h"
> ***************
> *** 157,162 ****
> --- 158,164 ----
> static void get_from_clause(Query *query, deparse_context *context);
> static void get_from_clause_item(Node *jtnode, Query *query,
> deparse_context *context);
> + static void get_from_clause_coldeflist(List *coldeflist, deparse_context *context);
> static void get_opclass_name(Oid opclass, Oid actual_datatype,
> StringInfo buf);
> static bool tleIsArrayAssign(TargetEntry *tle);
> ***************
> *** 2720,2725 ****
> --- 2722,2728 ----
> foreach(l, query->jointree->fromlist)
> {
> Node *jtnode = (Node *) lfirst(l);
> + List *coldeflist = NIL;
>
> if (IsA(jtnode, RangeTblRef))
> {
> ***************
> *** 2732,2741 ****
> --- 2735,2757 ----
> continue;
> if (strcmp(rte->eref->aliasname, "*OLD*") == 0)
> continue;
> +
> + /*
> + * Check to see if we have a function returning a RECORD
> + * pseudo-type. If so, we need grab the coldeflist here.
> + */
> + if (rte->rtekind == RTE_FUNCTION &&
> + get_typtype(exprType(rte->funcexpr)) == 'p' &&
> + exprType(rte->funcexpr) == RECORDOID)
> + coldeflist = rte->coldeflist;
> }
>
> appendStringInfo(buf, sep);
> get_from_clause_item(jtnode, query, context);
> +
> + if (coldeflist != NIL)
> + get_from_clause_coldeflist(coldeflist, context);
> +
> sep = ", ";
> }
> }
> ***************
> *** 2885,2890 ****
> --- 2901,2950 ----
> else
> elog(ERROR, "get_from_clause_item: unexpected node type %d",
> nodeTag(jtnode));
> + }
> +
> + /*
> + * get_from_clause_coldeflist - reproduce FROM clause coldeflist
> + *
> + * The coldeflist is appended immediately (no space) to buf.
> + *
> + */
> + static void
> + get_from_clause_coldeflist(List *coldeflist, deparse_context *context)
> + {
> + StringInfo buf = context->buf;
> + char *attname;
> + Oid atttypeid;
> + text *atttypename_text;
> + char *atttypename;
> + List *col;
> + int i = 0;
> +
> + appendStringInfoChar(buf, '(');
> +
> + foreach(col, coldeflist)
> + {
> + ColumnDef *n = lfirst(col);
> +
> + /* get the column alias */
> + attname = n->colname;
> +
> + /* get a nicely formated column data type name */
> + atttypeid = typenameTypeId(n->typename);
> + atttypename_text = DatumGetTextP(DirectFunctionCall2(format_type,
> + ObjectIdGetDatum(atttypeid), (Datum) NULL));
> + atttypename = DatumGetCString(DirectFunctionCall1(textout,
> + PointerGetDatum(atttypename_text)));
> +
> + if (i > 0)
> + appendStringInfo(buf, ", %s %s", attname, atttypename);
> + else
> + appendStringInfo(buf, "%s %s", attname, atttypename);
> +
> + i++;
> + }
> +
> + appendStringInfoChar(buf, ')');
> }
>
> /*
> Index: src/test/regress/expected/rules.out
> ===================================================================
> RCS file: /opt/src/cvs/pgsql-server/src/test/regress/expected/rules.out,v
> retrieving revision 1.59
> diff -c -r1.59 rules.out
> *** src/test/regress/expected/rules.out 27 Aug 2002 18:06:00 -0000 1.59
> --- src/test/regress/expected/rules.out 28 Aug 2002 04:23:25 -0000
> ***************
> *** 1268,1276 ****
> --------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
> iexit | SELECT ih.name, ih.thepath, interpt_pp(ih.thepath, r.thepath) AS exit FROM ihighway ih, ramp r WHERE (ih.thepath ## r.thepath);
> pg_indexes | SELECT n.nspname AS schemaname, c.relname AS tablename, i.relname AS indexname, pg_get_indexdef(i.oid) AS indexdef FROM (((pg_index x JOIN pg_class c ON ((c.oid = x.indrelid))) JOIN pg_class i ON ((i.oid = x.indexrelid))) LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) WHERE ((c.relkind = 'r'::"char") AND (i.relkind = 'i'::"char"));
> ! pg_locks | SELECT l.relation, l."database", l.backendpid, l."mode", l.isgranted FROM pg_lock_status() l;
> pg_rules | SELECT n.nspname AS schemaname, c.relname AS tablename, r.rulename, pg_get_ruledef(r.oid) AS definition FROM ((pg_rewrite r JOIN pg_class c ON ((c.oid = r.ev_class))) LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) WHERE (r.rulename <> '_RETURN'::name);
> ! pg_settings | SELECT a.name, a.setting FROM pg_show_all_settings() a;
> pg_stat_activity | SELECT d.oid AS datid, d.datname, pg_stat_get_backend_pid(s.backendid) AS procpid, pg_stat_get_backend_userid(s.backendid) AS usesysid, u.usename, pg_stat_get_backend_activity(s.backendid) AS current_query FROM pg_database d, (SELECT pg_stat_get_backend_idset() AS backendid) s, pg_shadow u WHERE ((pg_stat_get_backend_dbid(s.backendid) = d.oid) AND (pg_stat_get_backend_userid(s.backendid) = u.usesysid));
> pg_stat_all_indexes | SELECT c.oid AS relid, i.oid AS indexrelid, n.nspname AS schemaname, c.relname, i.relname AS indexrelname, pg_stat_get_numscans(i.oid) AS idx_scan, pg_stat_get_tuples_returned(i.oid) AS idx_tup_read, pg_stat_get_tuples_fetched(i.oid) AS idx_tup_fetch FROM (((pg_class c JOIN pg_index x ON ((c.oid = x.indrelid))) JOIN pg_class i ON ((i.oid = x.indexrelid))) LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) WHERE (c.relkind = 'r'::"char");
> pg_stat_all_tables | SELECT c.oid AS relid, n.nspname AS schemaname, c.relname, pg_stat_get_numscans(c.oid) AS seq_scan, pg_stat_get_tuples_returned(c.oid) AS seq_tup_read, sum(pg_stat_get_numscans(i.indexrelid)) AS idx_scan, sum(pg_stat_get_tuples_fetched(i.indexrelid)) AS idx_tup_fetch, pg_stat_get_tuples_inserted(c.oid) AS n_tup_ins, pg_stat_get_tuples_updated(c.oid) AS n_tup_upd, pg_stat_get_tuples_deleted(c.oid) AS n_tup_del FROM ((pg_class c LEFT JOIN pg_index i ON ((c.oid = i.indrelid))) LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) WHERE (c.relkind = 'r'::"char") GROUP BY c.oid, n.nspname, c.relname;
> --- 1268,1276 ----
> --------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
> iexit | SELECT ih.name, ih.thepath, interpt_pp(ih.thepath, r.thepath) AS exit FROM ihighway ih, ramp r WHERE (ih.thepath ## r.thepath);
> pg_indexes | SELECT n.nspname AS schemaname, c.relname AS tablename, i.relname AS indexname, pg_get_indexdef(i.oid) AS indexdef FROM (((pg_index x JOIN pg_class c ON ((c.oid = x.indrelid))) JOIN pg_class i ON ((i.oid = x.indexrelid))) LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) WHERE ((c.relkind = 'r'::"char") AND (i.relkind = 'i'::"char"));
> ! pg_locks | SELECT l.relation, l."database", l.backendpid, l."mode", l.isgranted FROM pg_lock_status() l(relation oid, database oid, backendpid integer, mode text, isgranted boolean);
> pg_rules | SELECT n.nspname AS schemaname, c.relname AS tablename, r.rulename, pg_get_ruledef(r.oid) AS definition FROM ((pg_rewrite r JOIN pg_class c ON ((c.oid = r.ev_class))) LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) WHERE (r.rulename <> '_RETURN'::name);
> ! pg_settings | SELECT a.name, a.setting FROM pg_show_all_settings() a(name text, setting text);
> pg_stat_activity | SELECT d.oid AS datid, d.datname, pg_stat_get_backend_pid(s.backendid) AS procpid, pg_stat_get_backend_userid(s.backendid) AS usesysid, u.usename, pg_stat_get_backend_activity(s.backendid) AS current_query FROM pg_database d, (SELECT pg_stat_get_backend_idset() AS backendid) s, pg_shadow u WHERE ((pg_stat_get_backend_dbid(s.backendid) = d.oid) AND (pg_stat_get_backend_userid(s.backendid) = u.usesysid));
> pg_stat_all_indexes | SELECT c.oid AS relid, i.oid AS indexrelid, n.nspname AS schemaname, c.relname, i.relname AS indexrelname, pg_stat_get_numscans(i.oid) AS idx_scan, pg_stat_get_tuples_returned(i.oid) AS idx_tup_read, pg_stat_get_tuples_fetched(i.oid) AS idx_tup_fetch FROM (((pg_class c JOIN pg_index x ON ((c.oid = x.indrelid))) JOIN pg_class i ON ((i.oid = x.indexrelid))) LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) WHERE (c.relkind = 'r'::"char");
> pg_stat_all_tables | SELECT c.oid AS relid, n.nspname AS schemaname, c.relname, pg_stat_get_numscans(c.oid) AS seq_scan, pg_stat_get_tuples_returned(c.oid) AS seq_tup_read, sum(pg_stat_get_numscans(i.indexrelid)) AS idx_scan, sum(pg_stat_get_tuples_fetched(i.indexrelid)) AS idx_tup_fetch, pg_stat_get_tuples_inserted(c.oid) AS n_tup_ins, pg_stat_get_tuples_updated(c.oid) AS n_tup_upd, pg_stat_get_tuples_deleted(c.oid) AS n_tup_del FROM ((pg_class c LEFT JOIN pg_index i ON ((c.oid = i.indrelid))) LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) WHERE (c.relkind = 'r'::"char") GROUP BY c.oid, n.nspname, c.relname;
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
> (send "unregister YourEmailAddressHere" to majordomo(at)postgresql(dot)org)
--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073
From | Date | Subject | |
---|---|---|---|
Next Message | Bruce Momjian | 2002-08-28 21:17:55 | Re: contrib/cube patches |
Previous Message | Bruce Momjian | 2002-08-28 21:15:53 | Re: fix for palloc() of user-supplied length |