Skip to content

Commit 74c1723

Browse files
committed
Remove user-selectable ANALYZE option for range types.
It's not clear that a per-datatype typanalyze function would be any more useful than a generic typanalyze for ranges. What *is* clear is that letting unprivileged users select typanalyze functions is a crash risk or worse. So remove the option from CREATE TYPE AS RANGE, and instead put in a generic typanalyze function for ranges. The generic function does nothing as yet, but hopefully we'll improve that before 9.2 release.
1 parent df73584 commit 74c1723

File tree

8 files changed

+36
-40
lines changed

8 files changed

+36
-40
lines changed

doc/src/sgml/ref/create_type.sgml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ CREATE TYPE <replaceable class="parameter">name</replaceable> AS RANGE (
3333
[ , COLLATION = <replaceable class="parameter">collation</replaceable> ]
3434
[ , CANONICAL = <replaceable class="parameter">canonical_function</replaceable> ]
3535
[ , SUBTYPE_DIFF = <replaceable class="parameter">subtype_diff_function</replaceable> ]
36-
[ , ANALYZE = <replaceable class="parameter">analyze_function</replaceable> ]
3736
)
3837

3938
CREATE TYPE <replaceable class="parameter">name</replaceable> (
@@ -167,12 +166,6 @@ CREATE TYPE <replaceable class="parameter">name</replaceable>
167166
that is, its result should be positive whenever its first argument is
168167
greater than its second according to the sort ordering.
169168
</para>
170-
171-
<para>
172-
The optional <replaceable class="parameter">analyze</replaceable>
173-
function performs type-specific statistics collection for columns of the
174-
range type. This is defined the same as for base types; see below.
175-
</para>
176169
</refsect2>
177170

178171
<refsect2>

src/backend/commands/typecmds.c

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,12 +1225,10 @@ DefineRange(CreateRangeStmt *stmt)
12251225
List *rangeCollationName = NIL;
12261226
List *rangeCanonicalName = NIL;
12271227
List *rangeSubtypeDiffName = NIL;
1228-
List *rangeAnalyzeName = NIL;
12291228
Oid rangeSubOpclass;
12301229
Oid rangeCollation;
12311230
regproc rangeCanonical;
12321231
regproc rangeSubtypeDiff;
1233-
regproc rangeAnalyze;
12341232
int16 subtyplen;
12351233
bool subtypbyval;
12361234
char subtypalign;
@@ -1326,14 +1324,6 @@ DefineRange(CreateRangeStmt *stmt)
13261324
errmsg("conflicting or redundant options")));
13271325
rangeSubtypeDiffName = defGetQualifiedName(defel);
13281326
}
1329-
else if (pg_strcasecmp(defel->defname, "analyze") == 0)
1330-
{
1331-
if (rangeAnalyzeName != NIL)
1332-
ereport(ERROR,
1333-
(errcode(ERRCODE_SYNTAX_ERROR),
1334-
errmsg("conflicting or redundant options")));
1335-
rangeAnalyzeName = defGetQualifiedName(defel);
1336-
}
13371327
else
13381328
ereport(ERROR,
13391329
(errcode(ERRCODE_SYNTAX_ERROR),
@@ -1386,12 +1376,6 @@ DefineRange(CreateRangeStmt *stmt)
13861376
else
13871377
rangeSubtypeDiff = InvalidOid;
13881378

1389-
if (rangeAnalyzeName != NIL)
1390-
rangeAnalyze = findTypeAnalyzeFunction(rangeAnalyzeName,
1391-
typoid);
1392-
else
1393-
rangeAnalyze = InvalidOid;
1394-
13951379
get_typlenbyvalalign(rangeSubtype,
13961380
&subtyplen, &subtypbyval, &subtypalign);
13971381

@@ -1420,7 +1404,7 @@ DefineRange(CreateRangeStmt *stmt)
14201404
F_RANGE_SEND, /* send procedure */
14211405
InvalidOid, /* typmodin procedure - none */
14221406
InvalidOid, /* typmodout procedure - none */
1423-
rangeAnalyze, /* analyze procedure */
1407+
F_RANGE_TYPANALYZE, /* analyze procedure */
14241408
InvalidOid, /* element type ID - none */
14251409
false, /* this is not an array type */
14261410
rangeArrayOid, /* array type we are about to create */

src/backend/utils/adt/rangetypes.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,6 +1135,23 @@ hash_range(PG_FUNCTION_ARGS)
11351135
PG_RETURN_INT32(result);
11361136
}
11371137

1138+
/* ANALYZE support */
1139+
1140+
/* typanalyze function for range datatypes */
1141+
Datum
1142+
range_typanalyze(PG_FUNCTION_ARGS)
1143+
{
1144+
/*
1145+
* For the moment, just punt and don't analyze range columns. If we
1146+
* get close to release without having a better answer, we could
1147+
* consider letting std_typanalyze do what it can ... but those stats
1148+
* are probably next door to useless for most activity with range
1149+
* columns, so it's not clear it's worth gathering them.
1150+
*/
1151+
PG_RETURN_BOOL(false);
1152+
}
1153+
1154+
11381155
/*
11391156
*----------------------------------------------------------
11401157
* CANONICAL FUNCTIONS

src/bin/pg_dump/pg_dump.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7482,11 +7482,11 @@ dumpRangeType(Archive *fout, TypeInfo *tyinfo)
74827482
"opc.opcdefault, "
74837483
"CASE WHEN rngcollation = st.typcollation THEN 0 "
74847484
" ELSE rngcollation END AS collation, "
7485-
"rngcanonical, rngsubdiff, t.typanalyze "
7486-
"FROM pg_catalog.pg_type t, pg_catalog.pg_type st, "
7487-
" pg_catalog.pg_opclass opc, pg_catalog.pg_range r "
7488-
"WHERE t.oid = rngtypid AND st.oid = rngsubtype AND "
7489-
" opc.oid = rngsubopc AND rngtypid = '%u'",
7485+
"rngcanonical, rngsubdiff "
7486+
"FROM pg_catalog.pg_range r, pg_catalog.pg_type st, "
7487+
" pg_catalog.pg_opclass opc "
7488+
"WHERE st.oid = rngsubtype AND opc.oid = rngsubopc AND "
7489+
"rngtypid = '%u'",
74907490
tyinfo->dobj.catId.oid);
74917491

74927492
res = PQexec(g_conn, query->data);
@@ -7552,10 +7552,6 @@ dumpRangeType(Archive *fout, TypeInfo *tyinfo)
75527552
if (strcmp(procname, "-") != 0)
75537553
appendPQExpBuffer(q, ",\n subtype_diff = %s", procname);
75547554

7555-
procname = PQgetvalue(res, 0, PQfnumber(res, "typanalyze"));
7556-
if (strcmp(procname, "-") != 0)
7557-
appendPQExpBuffer(q, ",\n analyze = %s", procname);
7558-
75597555
appendPQExpBuffer(q, "\n);\n");
75607556

75617557
appendPQExpBuffer(labelq, "TYPE %s", fmtId(tyinfo->dobj.name));

src/include/catalog/catversion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/* yyyymmddN */
56-
#define CATALOG_VERSION_NO 201111222
56+
#define CATALOG_VERSION_NO 201111231
5757

5858
#endif

src/include/catalog/pg_proc.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4413,6 +4413,9 @@ DATA(insert OID = 3881 ( range_gist_same PGNSP PGUID 12 1 0 0 0 f f f t f i 3
44134413
DESCR("GiST support");
44144414
DATA(insert OID = 3902 ( hash_range PGNSP PGUID 12 1 0 0 0 f f f t f i 1 0 23 "3831" _null_ _null_ _null_ _null_ hash_range _null_ _null_ _null_ ));
44154415
DESCR("hash a range");
4416+
DATA(insert OID = 3916 ( range_typanalyze PGNSP PGUID 12 1 0 0 0 f f f t f s 1 0 16 "2281" _null_ _null_ _null_ _null_ range_typanalyze _null_ _null_ _null_ ));
4417+
DESCR("range typanalyze");
4418+
44164419
DATA(insert OID = 3914 ( int4range_canonical PGNSP PGUID 12 1 0 0 0 f f f t f i 1 0 3904 "3904" _null_ _null_ _null_ _null_ int4range_canonical _null_ _null_ _null_ ));
44174420
DESCR("convert an int4 range to canonical form");
44184421
DATA(insert OID = 3928 ( int8range_canonical PGNSP PGUID 12 1 0 0 0 f f f t f i 1 0 3926 "3926" _null_ _null_ _null_ _null_ int8range_canonical _null_ _null_ _null_ ));

src/include/catalog/pg_type.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -593,23 +593,23 @@ DESCR("txid snapshot");
593593
DATA(insert OID = 2949 ( _txid_snapshot PGNSP PGUID -1 f b A f t \054 0 2970 0 array_in array_out array_recv array_send - - - d x f 0 -1 0 0 _null_ _null_ ));
594594

595595
/* range types */
596-
DATA(insert OID = 3904 ( int4range PGNSP PGUID -1 f r R f t \054 0 0 3905 range_in range_out range_recv range_send - - - i x f 0 -1 0 0 _null_ _null_ ));
596+
DATA(insert OID = 3904 ( int4range PGNSP PGUID -1 f r R f t \054 0 0 3905 range_in range_out range_recv range_send - - range_typanalyze i x f 0 -1 0 0 _null_ _null_ ));
597597
DESCR("range of integers");
598598
#define INT4RANGEOID 3904
599599
DATA(insert OID = 3905 ( _int4range PGNSP PGUID -1 f b A f t \054 0 3904 0 array_in array_out array_recv array_send - - - i x f 0 -1 0 0 _null_ _null_ ));
600-
DATA(insert OID = 3906 ( numrange PGNSP PGUID -1 f r R f t \054 0 0 3907 range_in range_out range_recv range_send - - - i x f 0 -1 0 0 _null_ _null_ ));
600+
DATA(insert OID = 3906 ( numrange PGNSP PGUID -1 f r R f t \054 0 0 3907 range_in range_out range_recv range_send - - range_typanalyze i x f 0 -1 0 0 _null_ _null_ ));
601601
DESCR("range of numerics");
602602
DATA(insert OID = 3907 ( _numrange PGNSP PGUID -1 f b A f t \054 0 3906 0 array_in array_out array_recv array_send - - - i x f 0 -1 0 0 _null_ _null_ ));
603-
DATA(insert OID = 3908 ( tsrange PGNSP PGUID -1 f r R f t \054 0 0 3909 range_in range_out range_recv range_send - - - d x f 0 -1 0 0 _null_ _null_ ));
603+
DATA(insert OID = 3908 ( tsrange PGNSP PGUID -1 f r R f t \054 0 0 3909 range_in range_out range_recv range_send - - range_typanalyze d x f 0 -1 0 0 _null_ _null_ ));
604604
DESCR("range of timestamps without time zone");
605605
DATA(insert OID = 3909 ( _tsrange PGNSP PGUID -1 f b A f t \054 0 3908 0 array_in array_out array_recv array_send - - - d x f 0 -1 0 0 _null_ _null_ ));
606-
DATA(insert OID = 3910 ( tstzrange PGNSP PGUID -1 f r R f t \054 0 0 3911 range_in range_out range_recv range_send - - - d x f 0 -1 0 0 _null_ _null_ ));
606+
DATA(insert OID = 3910 ( tstzrange PGNSP PGUID -1 f r R f t \054 0 0 3911 range_in range_out range_recv range_send - - range_typanalyze d x f 0 -1 0 0 _null_ _null_ ));
607607
DESCR("range of timestamps with time zone");
608608
DATA(insert OID = 3911 ( _tstzrange PGNSP PGUID -1 f b A f t \054 0 3910 0 array_in array_out array_recv array_send - - - d x f 0 -1 0 0 _null_ _null_ ));
609-
DATA(insert OID = 3912 ( daterange PGNSP PGUID -1 f r R f t \054 0 0 3913 range_in range_out range_recv range_send - - - i x f 0 -1 0 0 _null_ _null_ ));
609+
DATA(insert OID = 3912 ( daterange PGNSP PGUID -1 f r R f t \054 0 0 3913 range_in range_out range_recv range_send - - range_typanalyze i x f 0 -1 0 0 _null_ _null_ ));
610610
DESCR("range of dates");
611611
DATA(insert OID = 3913 ( _daterange PGNSP PGUID -1 f b A f t \054 0 3912 0 array_in array_out array_recv array_send - - - i x f 0 -1 0 0 _null_ _null_ ));
612-
DATA(insert OID = 3926 ( int8range PGNSP PGUID -1 f r R f t \054 0 0 3927 range_in range_out range_recv range_send - - - d x f 0 -1 0 0 _null_ _null_ ));
612+
DATA(insert OID = 3926 ( int8range PGNSP PGUID -1 f r R f t \054 0 0 3927 range_in range_out range_recv range_send - - range_typanalyze d x f 0 -1 0 0 _null_ _null_ ));
613613
DESCR("range of bigints");
614614
DATA(insert OID = 3927 ( _int8range PGNSP PGUID -1 f b A f t \054 0 3926 0 array_in array_out array_recv array_send - - - d x f 0 -1 0 0 _null_ _null_ ));
615615

src/include/utils/rangetypes.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ extern Datum range_gt(PG_FUNCTION_ARGS);
127127
/* Hash support */
128128
extern Datum hash_range(PG_FUNCTION_ARGS);
129129

130+
/* ANALYZE support */
131+
extern Datum range_typanalyze(PG_FUNCTION_ARGS);
132+
130133
/* Canonical functions */
131134
extern Datum int4range_canonical(PG_FUNCTION_ARGS);
132135
extern Datum int8range_canonical(PG_FUNCTION_ARGS);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy