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

Commit6994641

Browse files
committed
Add hooks for type-specific calculation of ANALYZE statistics. Idea and
coding by Mark Cave-Ayland, some kibitzing by Tom Lane. initdb forceddue to new column in pg_type.
1 parentd27471f commit6994641

File tree

13 files changed

+759
-520
lines changed

13 files changed

+759
-520
lines changed

‎doc/src/sgml/catalogs.sgml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!--
22
Documentation of the system catalogs, directed toward PostgreSQL developers
3-
$PostgreSQL: pgsql/doc/src/sgml/catalogs.sgml,v 2.82 2004/01/06 23:55:18 tgl Exp $
3+
$PostgreSQL: pgsql/doc/src/sgml/catalogs.sgml,v 2.83 2004/02/12 23:41:00 tgl Exp $
44
-->
55

66
<chapter id="catalogs">
@@ -3524,6 +3524,13 @@
35243524
<entry>Output conversion function (binary format), or 0 if none</entry>
35253525
</row>
35263526

3527+
<row>
3528+
<entry><structfield>typanalyze</structfield></entry>
3529+
<entry><type>regproc</type></entry>
3530+
<entry><literal><link linkend="catalog-pg-proc"><structname>pg_proc</structname></link>.oid</literal></entry>
3531+
<entry>Custom ANALYZE function, or 0 to use the standard function</entry>
3532+
</row>
3533+
35273534
<row>
35283535
<entry><structfield>typalign</structfield></entry>
35293536
<entry><type>char</type></entry>

‎doc/src/sgml/ref/create_type.sgml

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/create_type.sgml,v 1.48 2003/11/29 19:51:38 pgsql Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/create_type.sgml,v 1.49 2004/02/12 23:41:02 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -28,6 +28,7 @@ CREATE TYPE <replaceable class="parameter">name</replaceable> (
2828
OUTPUT = <replaceable class="parameter">output_function</replaceable>
2929
[ , RECEIVE = <replaceable class="parameter">receive_function</replaceable> ]
3030
[ , SEND = <replaceable class="parameter">send_function</replaceable> ]
31+
[ , ANALYZE = <replaceable class="parameter">analyze_function</replaceable> ]
3132
[ , INTERNALLENGTH = { <replaceable class="parameter">internallength</replaceable> | VARIABLE } ]
3233
[ , PASSEDBYVALUE ]
3334
[ , ALIGNMENT = <replaceable class="parameter">alignment</replaceable> ]
@@ -83,8 +84,9 @@ CREATE TYPE <replaceable class="parameter">name</replaceable> (
8384
<replaceable class="parameter">input_function</replaceable> and
8485
<replaceable class="parameter">output_function</replaceable>
8586
are required, while the functions
86-
<replaceable class="parameter">receive_function</replaceable> and
87-
<replaceable class="parameter">send_function</replaceable>
87+
<replaceable class="parameter">receive_function</replaceable>,
88+
<replaceable class="parameter">send_function</replaceable> and
89+
<replaceable class="parameter">analyze_function</replaceable>
8890
are optional. Generally these functions have to be coded in C
8991
or another low-level language.
9092
</para>
@@ -152,6 +154,19 @@ CREATE TYPE <replaceable class="parameter">name</replaceable> (
152154
shell entry with a complete type definition, and the new type can be used.
153155
</para>
154156

157+
<para>
158+
The optional <replaceable class="parameter">analyze_function</replaceable>
159+
performs type-specific statistics collection for columns of the data type.
160+
By default, <command>ANALYZE</> will attempt to gather statistics using
161+
the type's <quote>equals</> and <quote>less-than</> operators, if there
162+
is a default b-tree operator class for the type. For non-scalar types
163+
this behavior is likely to be unsuitable, so it can be overridden by
164+
specifying a custom analysis function. The analysis function must be
165+
declared to take a single argument of type <type>internal</>, and return
166+
a <type>boolean</> result. The detailed API for analysis functions appears
167+
in <filename>src/include/commands/vacuum.h</>.
168+
</para>
169+
155170
<para>
156171
While the details of the new type's internal representation are only
157172
known to the I/O functions and other functions you create to work with
@@ -341,6 +356,16 @@ CREATE TYPE <replaceable class="parameter">name</replaceable> (
341356
</listitem>
342357
</varlistentry>
343358

359+
<varlistentry>
360+
<term><replaceable class="parameter">analyze_function</replaceable></term>
361+
<listitem>
362+
<para>
363+
The name of a function that performs statistical analysis for the
364+
data type.
365+
</para>
366+
</listitem>
367+
</varlistentry>
368+
344369
<varlistentry>
345370
<term><replaceable class="parameter">internallength</replaceable></term>
346371
<listitem>

‎src/backend/catalog/heap.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/catalog/heap.c,v 1.258 2004/02/10 01:55:24 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/catalog/heap.c,v 1.259 2004/02/12 23:41:02 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -689,6 +689,7 @@ AddNewRelationType(const char *typeName,
689689
F_RECORD_OUT,/* output procedure */
690690
F_RECORD_RECV,/* receive procedure */
691691
F_RECORD_SEND,/* send procedure */
692+
InvalidOid,/* analyze procedure - default */
692693
InvalidOid,/* array element type - irrelevant */
693694
InvalidOid,/* domain base type - irrelevant */
694695
NULL,/* default type value - none */

‎src/backend/catalog/pg_type.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/catalog/pg_type.c,v 1.92 2004/01/07 18:56:25 neilc Exp $
11+
* $PostgreSQL: pgsql/src/backend/catalog/pg_type.c,v 1.93 2004/02/12 23:41:02 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -86,6 +86,7 @@ TypeShellMake(const char *typeName, Oid typeNamespace)
8686
values[i++]=ObjectIdGetDatum(InvalidOid);/* typoutput */
8787
values[i++]=ObjectIdGetDatum(InvalidOid);/* typreceive */
8888
values[i++]=ObjectIdGetDatum(InvalidOid);/* typsend */
89+
values[i++]=ObjectIdGetDatum(InvalidOid);/* typanalyze */
8990
values[i++]=CharGetDatum('i');/* typalign */
9091
values[i++]=CharGetDatum('p');/* typstorage */
9192
values[i++]=BoolGetDatum(false);/* typnotnull */
@@ -121,6 +122,7 @@ TypeShellMake(const char *typeName, Oid typeNamespace)
121122
InvalidOid,
122123
InvalidOid,
123124
InvalidOid,
125+
InvalidOid,
124126
NULL,
125127
false);
126128

@@ -157,6 +159,7 @@ TypeCreate(const char *typeName,
157159
OidoutputProcedure,
158160
OidreceiveProcedure,
159161
OidsendProcedure,
162+
OidanalyzeProcedure,
160163
OidelementType,
161164
OidbaseType,
162165
constchar*defaultTypeValue,/* human readable rep */
@@ -236,6 +239,7 @@ TypeCreate(const char *typeName,
236239
values[i++]=ObjectIdGetDatum(outputProcedure);/* typoutput */
237240
values[i++]=ObjectIdGetDatum(receiveProcedure);/* typreceive */
238241
values[i++]=ObjectIdGetDatum(sendProcedure);/* typsend */
242+
values[i++]=ObjectIdGetDatum(analyzeProcedure);/* typanalyze */
239243
values[i++]=CharGetDatum(alignment);/* typalign */
240244
values[i++]=CharGetDatum(storage);/* typstorage */
241245
values[i++]=BoolGetDatum(typeNotNull);/* typnotnull */
@@ -332,6 +336,7 @@ TypeCreate(const char *typeName,
332336
outputProcedure,
333337
receiveProcedure,
334338
sendProcedure,
339+
analyzeProcedure,
335340
elementType,
336341
baseType,
337342
(defaultTypeBin ?
@@ -366,6 +371,7 @@ GenerateTypeDependencies(Oid typeNamespace,
366371
OidoutputProcedure,
367372
OidreceiveProcedure,
368373
OidsendProcedure,
374+
OidanalyzeProcedure,
369375
OidelementType,
370376
OidbaseType,
371377
Node*defaultExpr,
@@ -425,6 +431,14 @@ GenerateTypeDependencies(Oid typeNamespace,
425431
recordDependencyOn(&myself,&referenced,DEPENDENCY_NORMAL);
426432
}
427433

434+
if (OidIsValid(analyzeProcedure))
435+
{
436+
referenced.classId=RelOid_pg_proc;
437+
referenced.objectId=analyzeProcedure;
438+
referenced.objectSubId=0;
439+
recordDependencyOn(&myself,&referenced,DEPENDENCY_NORMAL);
440+
}
441+
428442
/*
429443
* If the type is a rowtype for a relation, mark it as internally
430444
* dependent on the relation, *unless* it is a stand-alone composite

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp