Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8d9e025

Browse files
committed
Instead of storing pg_statistic stavalues entries as text strings, store
them as arrays of the internal datatype. This requires treating thestavalues columns as 'anyarray' rather than 'text[]', which is not 100%kosher but seems to work fine for the purposes we need for pg_statistic.Perhaps in the future 'anyarray' will be allowed more generally.
1 parentefeffae commit8d9e025

File tree

8 files changed

+67
-88
lines changed

8 files changed

+67
-88
lines changed

‎doc/src/sgml/catalogs.sgml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!--
22
Documentation of the system catalogs, directed toward PostgreSQL developers
3-
$Header: /cvsroot/pgsql/doc/src/sgml/catalogs.sgml,v 2.66 2003/02/22 00:45:03 tgl Exp $
3+
$Header: /cvsroot/pgsql/doc/src/sgml/catalogs.sgml,v 2.67 2003/03/23 05:14:36 tgl Exp $
44
-->
55

66
<chapter id="catalogs">
@@ -3050,12 +3050,14 @@
30503050

30513051
<row>
30523052
<entry>stavaluesN</entry>
3053-
<entry><type>text[]</type></entry>
3053+
<entry><type>anyarray</type></entry>
30543054
<entry></entry>
30553055
<entry>Column data values of the appropriate kind for the Nth
3056-
<quote>slot</quote>, or NULL if the slot kind does not store any data values.
3057-
For data-type independence, all column data values are converted
3058-
to external textual form and stored as TEXT datums.
3056+
<quote>slot</quote>, or NULL if the slot kind does not store any data
3057+
values.
3058+
Each array's element values are actually of the specific column's
3059+
datatype, so there is no way to define these columns' type more
3060+
specifically than <quote>anyarray</>.
30593061
</entry>
30603062
</row>
30613063
</tbody>

‎src/backend/catalog/heap.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.240 2003/03/20 03:34:55 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.241 2003/03/23 05:14:36 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -421,8 +421,12 @@ CheckAttributeType(const char *attname, Oid atttypid)
421421
"\n\tProceeding with relation creation anyway",
422422
attname);
423423
elseif (att_typtype=='p')
424-
elog(ERROR,"Attribute \"%s\" has pseudo-type %s",
425-
attname,format_type_be(atttypid));
424+
{
425+
/* Special hack for pg_statistic: allow ANYARRAY during initdb */
426+
if (atttypid!=ANYARRAYOID||IsUnderPostmaster)
427+
elog(ERROR,"Attribute \"%s\" has pseudo-type %s",
428+
attname,format_type_be(atttypid));
429+
}
426430
elseif (att_typtype=='c')
427431
{
428432
Oidtyprelid=get_typ_typrelid(atttypid);

‎src/backend/commands/analyze.c

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/commands/analyze.c,v 1.51 2002/11/29 21:39:10 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/commands/analyze.c,v 1.52 2003/03/23 05:14:36 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1694,7 +1694,6 @@ update_attstats(Oid relid, int natts, VacAttrStats **vacattrstats)
16941694
for (attno=0;attno<natts;attno++)
16951695
{
16961696
VacAttrStats*stats=vacattrstats[attno];
1697-
FmgrInfoout_function;
16981697
HeapTuplestup,
16991698
oldtup;
17001699
inti,
@@ -1708,8 +1707,6 @@ update_attstats(Oid relid, int natts, VacAttrStats **vacattrstats)
17081707
if (!stats->stats_valid)
17091708
continue;
17101709

1711-
fmgr_info(stats->attrtype->typoutput,&out_function);
1712-
17131710
/*
17141711
* Construct a new pg_statistic tuple
17151712
*/
@@ -1758,33 +1755,16 @@ update_attstats(Oid relid, int natts, VacAttrStats **vacattrstats)
17581755
}
17591756
for (k=0;k<STATISTIC_NUM_SLOTS;k++)
17601757
{
1761-
intntxt=stats->numvalues[k];
1762-
1763-
if (ntxt>0)
1758+
if (stats->numvalues[k]>0)
17641759
{
1765-
Datum*txtdatums= (Datum*)palloc(ntxt*sizeof(Datum));
17661760
ArrayType*arry;
17671761

1768-
for (n=0;n<ntxt;n++)
1769-
{
1770-
/*
1771-
* Convert data values to a text string to be inserted
1772-
* into the text array.
1773-
*/
1774-
Datumstringdatum;
1775-
1776-
stringdatum=
1777-
FunctionCall3(&out_function,
1778-
stats->stavalues[k][n],
1779-
ObjectIdGetDatum(stats->attrtype->typelem),
1780-
Int32GetDatum(stats->attr->atttypmod));
1781-
txtdatums[n]=DirectFunctionCall1(textin,stringdatum);
1782-
pfree(DatumGetPointer(stringdatum));
1783-
}
1784-
/* XXX knows more than it should about type text: */
1785-
arry=construct_array(txtdatums,ntxt,
1786-
TEXTOID,
1787-
-1, false,'i');
1762+
arry=construct_array(stats->stavalues[k],
1763+
stats->numvalues[k],
1764+
stats->attr->atttypid,
1765+
stats->attrtype->typlen,
1766+
stats->attrtype->typbyval,
1767+
stats->attrtype->typalign);
17881768
values[i++]=PointerGetDatum(arry);/* stavaluesN */
17891769
}
17901770
else

‎src/backend/utils/adt/selfuncs.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*
1717
* IDENTIFICATION
18-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.133 2003/03/2301:49:02 tgl Exp $
18+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.134 2003/03/2305:14:36 tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -1826,16 +1826,11 @@ mergejoinscansel(Query *root, Node *clause,
18261826
/*
18271827
* Now skip any binary-compatible relabeling; there can only be one level
18281828
* since constant-expression folder eliminates adjacent RelabelTypes.
1829-
*
1830-
* XXX can't enable this quite yet, it exposes regproc uncertainty problems
1831-
* in regression tests. FIXME soon.
18321829
*/
1833-
#if0
18341830
if (IsA(left,RelabelType))
18351831
left= (Var*) ((RelabelType*)left)->arg;
18361832
if (IsA(right,RelabelType))
18371833
right= (Var*) ((RelabelType*)right)->arg;
1838-
#endif
18391834

18401835
/* Can't do anything if inputs are not Vars */
18411836
if (!IsA(left,Var)||

‎src/backend/utils/cache/lsyscache.c

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/cache/lsyscache.c,v 1.90 2003/02/03 21:15:44 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/cache/lsyscache.c,v 1.91 2003/03/23 05:14:36 tgl Exp $
1111
*
1212
* NOTES
1313
* Eventually, the index information should go through here, too.
@@ -28,6 +28,7 @@
2828
#include"nodes/makefuncs.h"
2929
#include"utils/array.h"
3030
#include"utils/builtins.h"
31+
#include"utils/datum.h"
3132
#include"utils/lsyscache.h"
3233
#include"utils/syscache.h"
3334

@@ -1387,8 +1388,7 @@ get_attstatsslot(HeapTuple statstuple,
13871388
ArrayType*statarray;
13881389
intnarrayelem;
13891390
HeapTupletypeTuple;
1390-
FmgrInfoinputproc;
1391-
Oidtypelem;
1391+
Form_pg_typetypeForm;
13921392

13931393
for (i=0;i<STATISTIC_NUM_SLOTS;i++)
13941394
{
@@ -1408,48 +1408,40 @@ get_attstatsslot(HeapTuple statstuple,
14081408
elog(ERROR,"get_attstatsslot: stavalues is null");
14091409
statarray=DatumGetArrayTypeP(val);
14101410

1411-
/*
1412-
* Do initial examination of the array. This produces a list of
1413-
* text Datums --- ie, pointers into the text array value.
1414-
*/
1415-
deconstruct_array(statarray,
1416-
TEXTOID,-1, false,'i',
1417-
values,nvalues);
1418-
narrayelem=*nvalues;
1419-
1420-
/*
1421-
* We now need to replace each text Datum by its internal
1422-
* equivalent.
1423-
*
1424-
* Get the type input proc and typelem for the column datatype.
1425-
*/
1411+
/* Need to get info about the array element type */
14261412
typeTuple=SearchSysCache(TYPEOID,
14271413
ObjectIdGetDatum(atttype),
14281414
0,0,0);
14291415
if (!HeapTupleIsValid(typeTuple))
14301416
elog(ERROR,"get_attstatsslot: Cache lookup failed for type %u",
14311417
atttype);
1432-
fmgr_info(((Form_pg_type)GETSTRUCT(typeTuple))->typinput,&inputproc);
1433-
typelem= ((Form_pg_type)GETSTRUCT(typeTuple))->typelem;
1434-
ReleaseSysCache(typeTuple);
1418+
typeForm= (Form_pg_type)GETSTRUCT(typeTuple);
1419+
1420+
/* Deconstruct array into Datum elements */
1421+
deconstruct_array(statarray,
1422+
atttype,
1423+
typeForm->typlen,
1424+
typeForm->typbyval,
1425+
typeForm->typalign,
1426+
values,nvalues);
14351427

14361428
/*
1437-
* Do the conversions.The palloc'd array of Datums is reused in
1438-
* place.
1429+
* If the element type is pass-by-reference, we now have a bunch
1430+
* of Datums that are pointers into the syscache value. Copy them
1431+
* to avoid problems if syscache decides to drop the entry.
14391432
*/
1440-
for (j=0;j<narrayelem;j++)
1433+
if (!typeForm->typbyval)
14411434
{
1442-
char*strval;
1443-
1444-
strval=DatumGetCString(DirectFunctionCall1(textout,
1445-
(*values)[j]));
1446-
(*values)[j]=FunctionCall3(&inputproc,
1447-
CStringGetDatum(strval),
1448-
ObjectIdGetDatum(typelem),
1449-
Int32GetDatum(atttypmod));
1450-
pfree(strval);
1435+
for (j=0;j<*nvalues;j++)
1436+
{
1437+
(*values)[j]=datumCopy((*values)[j],
1438+
typeForm->typbyval,
1439+
typeForm->typlen);
1440+
}
14511441
}
14521442

1443+
ReleaseSysCache(typeTuple);
1444+
14531445
/*
14541446
* Free statarray if it's a detoasted copy.
14551447
*/

‎src/include/catalog/catversion.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
3838
* Portions Copyright (c) 1994, Regents of the University of California
3939
*
40-
* $Id: catversion.h,v 1.182 2003/03/21 01:58:04 tgl Exp $
40+
* $Id: catversion.h,v 1.183 2003/03/23 05:14:37 tgl Exp $
4141
*
4242
*-------------------------------------------------------------------------
4343
*/
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/*yyyymmddN */
56-
#defineCATALOG_VERSION_NO200303201
56+
#defineCATALOG_VERSION_NO200303221
5757

5858
#endif

‎src/include/catalog/pg_statistic.h

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
99
* Portions Copyright (c) 1994, Regents of the University of California
1010
*
11-
* $Id: pg_statistic.h,v 1.19 2003/03/10 22:28:21 tgl Exp $
11+
* $Id: pg_statistic.h,v 1.20 2003/03/23 05:14:37 tgl Exp $
1212
*
1313
* NOTES
1414
* the genbki.sh script reads this file and generates .bki
@@ -26,6 +26,12 @@
2626
* ----------------
2727
*/
2828

29+
/*
30+
* Keep C compiler happy with anyarray, below. This will need to go elsewhere
31+
* if we ever use anyarray for more than pg_statistic.
32+
*/
33+
typedefstructvarlenaanyarray;
34+
2935
/* ----------------
3036
*pg_statistic definition. cpp turns this into
3137
*typedef struct FormData_pg_statistic
@@ -109,14 +115,14 @@ CATALOG(pg_statistic) BKI_WITHOUT_OIDS
109115
float4stanumbers4[1];
110116

111117
/*
112-
* Values in thesetextarrays areexternal representationsofvalues
113-
*of the column's data type. To re-create the actual Datum, do
114-
*datatypein(textout(arrayelement)).
118+
* Values in these arrays arevaluesofthe column's data type. We
119+
*presently have to cheat quite a bit to allow polymorphic arrays
120+
*of this kind, but perhaps someday it'll be a less bogus facility.
115121
*/
116-
textstavalues1[1];
117-
textstavalues2[1];
118-
textstavalues3[1];
119-
textstavalues4[1];
122+
anyarraystavalues1;
123+
anyarraystavalues2;
124+
anyarraystavalues3;
125+
anyarraystavalues4;
120126
}FormData_pg_statistic;
121127

122128
#defineSTATISTIC_NUM_SLOTS 4

‎src/test/regress/expected/rules.out

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,8 +1267,8 @@ drop table cchild;
12671267
-- Check that ruleutils are working
12681268
--
12691269
SELECT viewname, definition FROM pg_views WHERE schemaname <> 'information_schema' ORDER BY viewname;
1270-
viewname | definition
1271-
--------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1270+
viewname | definition
1271+
--------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
12721272
iexit | SELECT ih.name, ih.thepath, interpt_pp(ih.thepath, r.thepath) AS exit FROM ihighway ih, ramp r WHERE (ih.thepath ## r.thepath);
12731273
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"));
12741274
pg_locks | SELECT l.relation, l."database", l."transaction", l.pid, l."mode", l.granted FROM pg_lock_status() l(relation oid, "database" oid, "transaction" xid, pid integer, "mode" text, granted boolean);
@@ -1291,7 +1291,7 @@ SELECT viewname, definition FROM pg_views WHERE schemaname <> 'information_schem
12911291
pg_statio_user_indexes | SELECT pg_statio_all_indexes.relid, pg_statio_all_indexes.indexrelid, pg_statio_all_indexes.schemaname, pg_statio_all_indexes.relname, pg_statio_all_indexes.indexrelname, pg_statio_all_indexes.idx_blks_read, pg_statio_all_indexes.idx_blks_hit FROM pg_statio_all_indexes WHERE ((pg_statio_all_indexes.schemaname <> 'pg_catalog'::name) AND (pg_statio_all_indexes.schemaname <> 'pg_toast'::name));
12921292
pg_statio_user_sequences | SELECT pg_statio_all_sequences.relid, pg_statio_all_sequences.schemaname, pg_statio_all_sequences.relname, pg_statio_all_sequences.blks_read, pg_statio_all_sequences.blks_hit FROM pg_statio_all_sequences WHERE ((pg_statio_all_sequences.schemaname <> 'pg_catalog'::name) AND (pg_statio_all_sequences.schemaname <> 'pg_toast'::name));
12931293
pg_statio_user_tables | SELECT pg_statio_all_tables.relid, pg_statio_all_tables.schemaname, pg_statio_all_tables.relname, pg_statio_all_tables.heap_blks_read, pg_statio_all_tables.heap_blks_hit, pg_statio_all_tables.idx_blks_read, pg_statio_all_tables.idx_blks_hit, pg_statio_all_tables.toast_blks_read, pg_statio_all_tables.toast_blks_hit, pg_statio_all_tables.tidx_blks_read, pg_statio_all_tables.tidx_blks_hit FROM pg_statio_all_tables WHERE ((pg_statio_all_tables.schemaname <> 'pg_catalog'::name) AND (pg_statio_all_tables.schemaname <> 'pg_toast'::name));
1294-
pg_stats | SELECT nspname AS schemaname, relname AS tablename, attname, stanullfrac AS null_frac, stawidth AS avg_width, stadistinct AS n_distinct, CASE WHEN (1 = stakind1) THEN stavalues1 WHEN (1 = stakind2) THEN stavalues2 WHEN (1 = stakind3) THEN stavalues3 WHEN (1 = stakind4) THEN stavalues4 ELSE NULL::text[] END AS most_common_vals, CASE WHEN (1 = stakind1) THEN stanumbers1 WHEN (1 = stakind2) THEN stanumbers2 WHEN (1 = stakind3) THEN stanumbers3 WHEN (1 = stakind4) THEN stanumbers4 ELSE NULL::real[] END AS most_common_freqs, CASE WHEN (2 = stakind1) THEN stavalues1 WHEN (2 = stakind2) THEN stavalues2 WHEN (2 = stakind3) THEN stavalues3 WHEN (2 = stakind4) THEN stavalues4 ELSE NULL::text[] END AS histogram_bounds, CASE WHEN (3 = stakind1) THEN stanumbers1[1] WHEN (3 = stakind2) THEN stanumbers2[1] WHEN (3 = stakind3) THEN stanumbers3[1] WHEN (3 = stakind4) THEN stanumbers4[1] ELSE NULL::real END AS correlation FROM (((pg_statistic s JOIN pg_class c ON ((c.oid = s.starelid))) JOIN pg_attribute a ON (((c.oid = a.attrelid) AND (a.attnum = s.staattnum)))) LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) WHERE has_table_privilege(c.oid, 'select'::text);
1294+
pg_stats | SELECT nspname AS schemaname, relname AS tablename, attname, stanullfrac AS null_frac, stawidth AS avg_width, stadistinct AS n_distinct, CASE WHEN (1 = stakind1) THEN stavalues1 WHEN (1 = stakind2) THEN stavalues2 WHEN (1 = stakind3) THEN stavalues3 WHEN (1 = stakind4) THEN stavalues4 ELSE NULL::anyarray END AS most_common_vals, CASE WHEN (1 = stakind1) THEN stanumbers1 WHEN (1 = stakind2) THEN stanumbers2 WHEN (1 = stakind3) THEN stanumbers3 WHEN (1 = stakind4) THEN stanumbers4 ELSE NULL::real[] END AS most_common_freqs, CASE WHEN (2 = stakind1) THEN stavalues1 WHEN (2 = stakind2) THEN stavalues2 WHEN (2 = stakind3) THEN stavalues3 WHEN (2 = stakind4) THEN stavalues4 ELSE NULL::anyarray END AS histogram_bounds, CASE WHEN (3 = stakind1) THEN stanumbers1[1] WHEN (3 = stakind2) THEN stanumbers2[1] WHEN (3 = stakind3) THEN stanumbers3[1] WHEN (3 = stakind4) THEN stanumbers4[1] ELSE NULL::real END AS correlation FROM (((pg_statistic s JOIN pg_class c ON ((c.oid = s.starelid))) JOIN pg_attribute a ON (((c.oid = a.attrelid) AND (a.attnum = s.staattnum)))) LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) WHERE has_table_privilege(c.oid, 'select'::text);
12951295
pg_tables | SELECT n.nspname AS schemaname, c.relname AS tablename, pg_get_userbyid(c.relowner) AS tableowner, c.relhasindex AS hasindexes, c.relhasrules AS hasrules, (c.reltriggers > 0) AS hastriggers FROM (pg_class c LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) WHERE ((c.relkind = 'r'::"char") OR (c.relkind = 's'::"char"));
12961296
pg_user | SELECT pg_shadow.usename, pg_shadow.usesysid, pg_shadow.usecreatedb, pg_shadow.usesuper, pg_shadow.usecatupd, '********'::text AS passwd, pg_shadow.valuntil, pg_shadow.useconfig FROM pg_shadow;
12971297
pg_views | SELECT n.nspname AS schemaname, c.relname AS viewname, pg_get_userbyid(c.relowner) AS viewowner, pg_get_viewdef(c.oid) AS definition FROM (pg_class c LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) WHERE (c.relkind = 'v'::"char");

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp