Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit b7b78d2

Browse files
committed
Code review for FILLFACTOR patch. Change WITH grammar as per earlier
discussion (including making def_arg allow reserved words), add missed opt_definition for UNIQUE case. Put the reloptions support code in a less random place (I chose to make a new file access/common/reloptions.c). Eliminate header inclusion creep. Make the index options functions safely user-callable (seems like client apps might like to be able to test validity of options before trying to make an index). Reduce overhead for normal case with no options by allowing rd_options to be NULL. Fix some unmaintainably klugy code, including getting rid of Natts_pg_class_fixed at long last. Some stylistic cleanup too, and pay attention to keeping comments in sync with code. Documentation still needs work, though I did fix the omissions in catalogs.sgml and indexam.sgml.
1 parent feed073 commit b7b78d2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1133
-1093
lines changed

doc/src/sgml/catalogs.sgml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/catalogs.sgml,v 2.124 2006/06/03 02:53:04 tgl Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/catalogs.sgml,v 2.125 2006/07/03 22:45:36 tgl Exp $ -->
22
<!--
33
Documentation of the system catalogs, directed toward PostgreSQL developers
44
-->
@@ -499,6 +499,13 @@
499499
<entry>Function to estimate cost of an index scan</entry>
500500
</row>
501501

502+
<row>
503+
<entry><structfield>amoptions</structfield></entry>
504+
<entry><type>regproc</type></entry>
505+
<entry><literal><link linkend="catalog-pg-proc"><structname>pg_proc</structname></link>.oid</literal></entry>
506+
<entry>Function to parse and validate reloptions for an index</entry>
507+
</row>
508+
502509
</tbody>
503510
</tgroup>
504511
</table>
@@ -1643,6 +1650,15 @@
16431650
for details
16441651
</entry>
16451652
</row>
1653+
1654+
<row>
1655+
<entry><structfield>reloptions</structfield></entry>
1656+
<entry><type>text[]</type></entry>
1657+
<entry></entry>
1658+
<entry>
1659+
Access-method-specific options, as <quote>keyword=value</> strings
1660+
</entry>
1661+
</row>
16461662
</tbody>
16471663
</tgroup>
16481664
</table>

doc/src/sgml/indexam.sgml

Lines changed: 47 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/indexam.sgml,v 2.14 2006/06/06 17:59:57 tgl Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/indexam.sgml,v 2.15 2006/07/03 22:45:36 tgl Exp $ -->
22

33
<chapter id="indexam">
44
<title>Index Access Method Interface Definition</title>
@@ -233,6 +233,47 @@ amvacuumcleanup (IndexVacuumInfo *info,
233233
be returned.
234234
</para>
235235

236+
<para>
237+
<programlisting>
238+
void
239+
amcostestimate (PlannerInfo *root,
240+
IndexOptInfo *index,
241+
List *indexQuals,
242+
RelOptInfo *outer_rel,
243+
Cost *indexStartupCost,
244+
Cost *indexTotalCost,
245+
Selectivity *indexSelectivity,
246+
double *indexCorrelation);
247+
</programlisting>
248+
Estimate the costs of an index scan. This function is described fully
249+
in <xref linkend="index-cost-estimation">, below.
250+
</para>
251+
252+
<para>
253+
<programlisting>
254+
bytea *
255+
amoptions (ArrayType *reloptions,
256+
bool validate);
257+
</programlisting>
258+
Parse and validate the reloptions array for an index. This is called only
259+
when a non-null reloptions array exists for the index.
260+
<parameter>reloptions</> is a <type>text</> array containing entries of the
261+
form <replaceable>name</><literal>=</><replaceable>value</>.
262+
The function should construct a <type>bytea</> value, which will be copied
263+
into the <structfield>rd_options</> field of the index's relcache entry.
264+
The data contents of the <type>bytea</> value are open for the access
265+
method to define, but the standard access methods currently all use struct
266+
<structname>StdRdOptions</>.
267+
When <parameter>validate</> is true, the function should report a suitable
268+
error message if any of the options are unrecognized or have invalid
269+
values; when <parameter>validate</> is false, invalid entries should be
270+
silently ignored. (<parameter>validate</> is false when loading options
271+
already stored in <structname>pg_catalog</>; an invalid entry could only
272+
be found if the access method has changed its rules for options, and in
273+
that case ignoring obsolete entries is appropriate.)
274+
It is OK to return NULL if default behavior is wanted.
275+
</para>
276+
236277
<para>
237278
The purpose of an index, of course, is to support scans for tuples matching
238279
an indexable <literal>WHERE</> condition, often called a
@@ -339,28 +380,16 @@ amrestrpos (IndexScanDesc scan);
339380
</para>
340381

341382
<para>
342-
<programlisting>
343-
void
344-
amcostestimate (PlannerInfo *root,
345-
IndexOptInfo *index,
346-
List *indexQuals,
347-
RelOptInfo *outer_rel,
348-
Cost *indexStartupCost,
349-
Cost *indexTotalCost,
350-
Selectivity *indexSelectivity,
351-
double *indexCorrelation);
352-
</programlisting>
353-
Estimate the costs of an index scan. This function is described fully
354-
in <xref linkend="index-cost-estimation">, below.
355-
</para>
356-
357-
<para>
358-
By convention, the <literal>pg_proc</literal> entry for any index
383+
By convention, the <literal>pg_proc</literal> entry for an index
359384
access method function should show the correct number of arguments,
360385
but declare them all as type <type>internal</> (since most of the arguments
361386
have types that are not known to SQL, and we don't want users calling
362387
the functions directly anyway). The return type is declared as
363388
<type>void</>, <type>internal</>, or <type>boolean</> as appropriate.
389+
The only exception is <function>amoptions</>, which should be correctly
390+
declared as taking <type>text[]</> and <type>bool</> and returning
391+
<type>bytea</>. This provision allows client code to execute
392+
<function>amoptions</> to test validity of options settings.
364393
</para>
365394

366395
</sect1>

src/backend/access/common/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
# Makefile for access/common
55
#
66
# IDENTIFICATION
7-
# $PostgreSQL: pgsql/src/backend/access/common/Makefile,v 1.21 2006/01/14 22:03:35 tgl Exp $
7+
# $PostgreSQL: pgsql/src/backend/access/common/Makefile,v 1.22 2006/07/03 22:45:36 tgl Exp $
88
#
99
#-------------------------------------------------------------------------
1010

1111
subdir = src/backend/access/common
1212
top_builddir = ../../../..
1313
include $(top_builddir)/src/Makefile.global
1414

15-
OBJS = heaptuple.o indextuple.o printtup.o scankey.o tupdesc.o
15+
OBJS = heaptuple.o indextuple.o printtup.o reloptions.o scankey.o tupdesc.o
1616

1717
all: SUBSYS.o
1818

src/backend/access/common/heaptuple.c

Lines changed: 3 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*
1717
*
1818
* IDENTIFICATION
19-
* $PostgreSQL: pgsql/src/backend/access/common/heaptuple.c,v 1.108 2006/07/02 02:23:18 momjian Exp $
19+
* $PostgreSQL: pgsql/src/backend/access/common/heaptuple.c,v 1.109 2006/07/03 22:45:36 tgl Exp $
2020
*
2121
*-------------------------------------------------------------------------
2222
*/
@@ -1694,9 +1694,8 @@ minimal_tuple_from_heap_tuple(HeapTuple htup)
16941694
* presumed to contain no null fields and no varlena fields.
16951695
*
16961696
* This routine is really only useful for certain system tables that are
1697-
* known to be fixed-width and null-free. It is used in some places for
1698-
* pg_class, but that is a gross hack (it only works because relacl can
1699-
* be omitted from the tuple entirely in those places).
1697+
* known to be fixed-width and null-free. Currently it is only used for
1698+
* pg_attribute tuples.
17001699
* ----------------
17011700
*/
17021701
HeapTuple
@@ -1738,54 +1737,3 @@ heap_addheader(int natts, /* max domain index */
17381737

17391738
return tuple;
17401739
}
1741-
1742-
/*
1743-
* build_class_tuple
1744-
*
1745-
* XXX Natts_pg_class_fixed is a hack - see pg_class.h
1746-
*/
1747-
HeapTuple
1748-
build_class_tuple(Form_pg_class pgclass, ArrayType *options)
1749-
{
1750-
HeapTuple tuple;
1751-
HeapTupleHeader td;
1752-
Form_pg_class data; /* contents of tuple */
1753-
Size len;
1754-
Size size;
1755-
int hoff;
1756-
1757-
/* size of pg_class tuple with options */
1758-
if (options)
1759-
size = offsetof(FormData_pg_class, reloptions) + VARATT_SIZE(options);
1760-
else
1761-
size = CLASS_TUPLE_SIZE;
1762-
1763-
/* header needs no null bitmap */
1764-
hoff = offsetof(HeapTupleHeaderData, t_bits);
1765-
hoff += sizeof(Oid);
1766-
hoff = MAXALIGN(hoff);
1767-
len = hoff + size;
1768-
1769-
tuple = (HeapTuple) palloc0(HEAPTUPLESIZE + len);
1770-
tuple->t_data = td = (HeapTupleHeader) ((char *) tuple + HEAPTUPLESIZE);
1771-
1772-
tuple->t_len = len;
1773-
ItemPointerSetInvalid(&(tuple->t_self));
1774-
tuple->t_tableOid = InvalidOid;
1775-
1776-
/* we don't bother to fill the Datum fields */
1777-
1778-
td->t_natts = Natts_pg_class_fixed;
1779-
td->t_hoff = hoff;
1780-
td->t_infomask = HEAP_HASOID;
1781-
1782-
data = (Form_pg_class) ((char *) td + hoff);
1783-
memcpy(data, pgclass, CLASS_TUPLE_SIZE);
1784-
if (options)
1785-
{
1786-
td->t_natts++;
1787-
memcpy(data->reloptions, options, VARATT_SIZE(options));
1788-
}
1789-
1790-
return tuple;
1791-
}

0 commit comments

Comments
 (0)