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

Commitcdbf9b3

Browse files
committed
Move docs about index cost estimation functions and writing a procedural
language handler to the 'Internals' area, per my proposal of yesterday.Clean up the trigger documentation a bit. Push SPI chapter to the endof its part, and reorder the Internals chapters into what seems a moresensible order (at the moment anyway).
1 parentb8400c7 commitcdbf9b3

File tree

7 files changed

+339
-286
lines changed

7 files changed

+339
-286
lines changed

‎doc/src/sgml/filelist.sgml

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $Header: /cvsroot/pgsql/doc/src/sgml/filelist.sgml,v 1.31 2003/10/17 18:57:01 tgl Exp $ -->
1+
<!-- $Header: /cvsroot/pgsql/doc/src/sgml/filelist.sgml,v 1.32 2003/10/22 22:28:10 tgl Exp $ -->
22

33
<!entity history SYSTEM "history.sgml">
44
<!entity info SYSTEM "info.sgml">
@@ -7,8 +7,6 @@
77
<!entity notation SYSTEM "notation.sgml">
88
<!entity problems SYSTEM "problems.sgml">
99

10-
<!entity bookindex SYSTEM "bookindex.sgml">
11-
1210
<!-- tutorial -->
1311
<!entity advanced SYSTEM "advanced.sgml">
1412
<!entity query SYSTEM "query.sgml">
@@ -20,27 +18,16 @@
2018
<!-- user's guide -->
2119
<!entity array SYSTEM "array.sgml">
2220
<!entity datatype SYSTEM "datatype.sgml">
23-
<!entity datetime SYSTEM "datetime.sgml">
2421
<!entity ddl SYSTEM "ddl.sgml">
2522
<!entity dml SYSTEM "dml.sgml">
26-
<!entity errcodes SYSTEM "errcodes.sgml">
27-
<!entity features SYSTEM "features.sgml">
2823
<!entity func SYSTEM "func.sgml">
2924
<!entity indices SYSTEM "indices.sgml">
30-
<!entity keywords SYSTEM "keywords.sgml">
3125
<!entity mvcc SYSTEM "mvcc.sgml">
3226
<!entity perform SYSTEM "perform.sgml">
3327
<!entity queries SYSTEM "queries.sgml">
3428
<!entity syntax SYSTEM "syntax.sgml">
3529
<!entity typeconv SYSTEM "typeconv.sgml">
3630

37-
<!entity features-supported SYSTEM "features-supported.sgml">
38-
<!entity features-unsupported SYSTEM "features-unsupported.sgml">
39-
40-
<!-- reference pages -->
41-
<!entity % allfiles SYSTEM "ref/allfiles.sgml">
42-
%allfiles;
43-
4431
<!-- administrator's guide -->
4532
<!entity backup SYSTEM "backup.sgml">
4633
<!entity charset SYSTEM "charset.sgml">
@@ -52,7 +39,6 @@
5239
<!entity manage-ag SYSTEM "manage-ag.sgml">
5340
<!entity monitoring SYSTEM "monitoring.sgml">
5441
<!entity regress SYSTEM "regress.sgml">
55-
<!entity release SYSTEM "release.sgml">
5642
<!entity runtime SYSTEM "runtime.sgml">
5743
<!entity user-manag SYSTEM "user-manag.sgml">
5844
<!entity wal SYSTEM "wal.sgml">
@@ -62,8 +48,6 @@
6248
<!entity ecpg SYSTEM "ecpg.sgml">
6349
<!entity extend SYSTEM "extend.sgml">
6450
<!entity func-ref SYSTEM "func-ref.sgml">
65-
<!entity gist SYSTEM "gist.sgml">
66-
<!entity indexcost SYSTEM "indexcost.sgml">
6751
<!entity infoschema SYSTEM "information_schema.sgml">
6852
<!entity jdbc SYSTEM "jdbc.sgml">
6953
<!entity libpgeasy SYSTEM "libpgeasy.sgml">
@@ -85,21 +69,40 @@
8569
<!entity plsql SYSTEM "plpgsql.sgml">
8670
<!entity pltcl SYSTEM "pltcl.sgml">
8771

72+
<!-- reference pages -->
73+
<!entity % allfiles SYSTEM "ref/allfiles.sgml">
74+
%allfiles;
75+
8876
<!-- developer's guide -->
8977
<!entity arch-dev SYSTEM "arch-dev.sgml">
90-
<!entity biblio SYSTEM "biblio.sgml">
9178
<!entity bki SYSTEM "bki.sgml">
9279
<!entity catalogs SYSTEM "catalogs.sgml">
9380
<!entity compiler SYSTEM "compiler.sgml">
94-
<!entity contacts SYSTEM "contacts.sgml">
95-
<!entity cvs SYSTEM "cvs.sgml">
96-
<!entity docguide SYSTEM "docguide.sgml">
9781
<!entity geqo SYSTEM "geqo.sgml">
98-
<!entity index SYSTEM "index.sgml">
82+
<!entity gist SYSTEM "gist.sgml">
83+
<!entity indexcost SYSTEM "indexcost.sgml">
84+
<!entity nls SYSTEM "nls.sgml">
9985
<!entity page SYSTEM "page.sgml">
86+
<!entity plhandler SYSTEM "plhandler.sgml">
10087
<!entity protocol SYSTEM "protocol.sgml">
10188
<!entity sources SYSTEM "sources.sgml">
102-
<!entity nls SYSTEM "nls.sgml">
89+
90+
<!-- appendixes -->
91+
<!entity contacts SYSTEM "contacts.sgml">
92+
<!entity cvs SYSTEM "cvs.sgml">
93+
<!entity datetime SYSTEM "datetime.sgml">
94+
<!entity docguide SYSTEM "docguide.sgml">
95+
<!entity errcodes SYSTEM "errcodes.sgml">
96+
<!entity features SYSTEM "features.sgml">
97+
<!entity keywords SYSTEM "keywords.sgml">
98+
<!entity release SYSTEM "release.sgml">
99+
100+
<!entity features-supported SYSTEM "features-supported.sgml">
101+
<!entity features-unsupported SYSTEM "features-unsupported.sgml">
102+
103+
<!-- back matter -->
104+
<!entity biblio SYSTEM "biblio.sgml">
105+
<!entity bookindex SYSTEM "bookindex.sgml">
103106

104107
<!--
105108
Some parts of the documentation are also source for some plain-text

‎doc/src/sgml/plhandler.sgml

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
<!--
2+
$Header: /cvsroot/pgsql/doc/src/sgml/plhandler.sgml,v 1.1 2003/10/22 22:28:10 tgl Exp $
3+
-->
4+
5+
<chapter id="plhandler">
6+
<title>Writing A Procedural Language Handler</title>
7+
8+
<indexterm zone="plhandler">
9+
<primary>procedural language</primary>
10+
<secondary>handler for</secondary>
11+
</indexterm>
12+
13+
<para>
14+
All calls to functions that are written in a language other than
15+
the current <quote>version 1</quote> interface for compiled
16+
languages (this includes functions in user-defined procedural languages,
17+
functions written in SQL, and functions using the version 0 compiled
18+
language interface), go through a <firstterm>call handler</firstterm>
19+
function for the specific language. It is the responsibility of
20+
the call handler to execute the function in a meaningful way, such
21+
as by interpreting the supplied source text. This chapter outlines
22+
how a new procedural language's call handler can be written.
23+
</para>
24+
25+
<para>
26+
The call handler for a procedural language is a
27+
<quote>normal</quote> function that must be written in a compiled
28+
language such as C, using the version-1 interface, and registered
29+
with <productname>PostgreSQL</productname> as taking no arguments
30+
and returning the type <type>language_handler</type>. This
31+
special pseudotype identifies the function as a call handler and
32+
prevents it from being called directly in SQL commands.
33+
</para>
34+
35+
<para>
36+
The call handler is called in the same way as any other function:
37+
It receives a pointer to a
38+
<structname>FunctionCallInfoData</structname> <type>struct</> containing
39+
argument values and information about the called function, and it
40+
is expected to return a <type>Datum</type> result (and possibly
41+
set the <structfield>isnull</structfield> field of the
42+
<structname>FunctionCallInfoData</structname> structure, if it wishes
43+
to return an SQL null result). The difference between a call
44+
handler and an ordinary callee function is that the
45+
<structfield>flinfo-&gt;fn_oid</structfield> field of the
46+
<structname>FunctionCallInfoData</structname> structure will contain
47+
the OID of the actual function to be called, not of the call
48+
handler itself. The call handler must use this field to determine
49+
which function to execute. Also, the passed argument list has
50+
been set up according to the declaration of the target function,
51+
not of the call handler.
52+
</para>
53+
54+
<para>
55+
It's up to the call handler to fetch the entry of the function from the
56+
system table
57+
<classname>pg_proc</classname> and to analyze the argument
58+
and return types of the called function. The <literal>AS</> clause from the
59+
<command>CREATE FUNCTION</command> of the function will be found
60+
in the <literal>prosrc</literal> column of the
61+
<classname>pg_proc</classname> row. This may be the source
62+
text in the procedural language itself (like for PL/Tcl), a
63+
path name to a file, or anything else that tells the call handler
64+
what to do in detail.
65+
</para>
66+
67+
<para>
68+
Often, the same function is called many times per SQL statement.
69+
A call handler can avoid repeated lookups of information about the
70+
called function by using the
71+
<structfield>flinfo-&gt;fn_extra</structfield> field. This will
72+
initially be <symbol>NULL</>, but can be set by the call handler to point at
73+
information about the called function. On subsequent calls, if
74+
<structfield>flinfo-&gt;fn_extra</structfield> is already non-<symbol>NULL</>
75+
then it can be used and the information lookup step skipped. The
76+
call handler must make sure that
77+
<structfield>flinfo-&gt;fn_extra</structfield> is made to point at
78+
memory that will live at least until the end of the current query,
79+
since an <structname>FmgrInfo</structname> data structure could be
80+
kept that long. One way to do this is to allocate the extra data
81+
in the memory context specified by
82+
<structfield>flinfo-&gt;fn_mcxt</structfield>; such data will
83+
normally have the same lifespan as the
84+
<structname>FmgrInfo</structname> itself. But the handler could
85+
also choose to use a longer-lived memory context so that it can cache
86+
function definition information across queries.
87+
</para>
88+
89+
<para>
90+
When a procedural-language function is invoked as a trigger, no arguments
91+
are passed in the usual way, but the
92+
<structname>FunctionCallInfoData</structname>'s
93+
<structfield>context</structfield> field points at a
94+
<structname>TriggerData</structname> structure, rather than being <symbol>NULL</>
95+
as it is in a plain function call. A language handler should
96+
provide mechanisms for procedural-language functions to get at the trigger
97+
information.
98+
</para>
99+
100+
<para>
101+
This is a template for a procedural-language handler written in C:
102+
<programlisting>
103+
#include "postgres.h"
104+
#include "executor/spi.h"
105+
#include "commands/trigger.h"
106+
#include "fmgr.h"
107+
#include "access/heapam.h"
108+
#include "utils/syscache.h"
109+
#include "catalog/pg_proc.h"
110+
#include "catalog/pg_type.h"
111+
112+
PG_FUNCTION_INFO_V1(plsample_call_handler);
113+
114+
Datum
115+
plsample_call_handler(PG_FUNCTION_ARGS)
116+
{
117+
Datum retval;
118+
119+
if (CALLED_AS_TRIGGER(fcinfo))
120+
{
121+
/*
122+
* Called as a trigger procedure
123+
*/
124+
TriggerData *trigdata = (TriggerData *) fcinfo->context;
125+
126+
retval = ...
127+
}
128+
else
129+
{
130+
/*
131+
* Called as a function
132+
*/
133+
134+
retval = ...
135+
}
136+
137+
return retval;
138+
}
139+
</programlisting>
140+
Only a few thousand lines of code have to be added instead of the
141+
dots to complete the call handler.
142+
</para>
143+
144+
<para>
145+
After having compiled the handler function into a loadable module
146+
(see <xref linkend="dfunc">), the following commands then
147+
register the sample procedural language:
148+
<programlisting>
149+
CREATE FUNCTION plsample_call_handler() RETURNS language_handler
150+
AS '<replaceable>filename</replaceable>'
151+
LANGUAGE C;
152+
CREATE LANGUAGE plsample
153+
HANDLER plsample_call_handler;
154+
</programlisting>
155+
</para>
156+
157+
</chapter>
158+
159+
<!-- Keep this comment at the end of the file
160+
Local variables:
161+
mode:sgml
162+
sgml-omittag:nil
163+
sgml-shorttag:t
164+
sgml-minimize-attributes:nil
165+
sgml-always-quote-attributes:t
166+
sgml-indent-step:1
167+
sgml-indent-data:t
168+
sgml-parent-document:nil
169+
sgml-default-dtd-file:"./reference.ced"
170+
sgml-exposed-tags:nil
171+
sgml-local-catalogs:("/usr/lib/sgml/catalog")
172+
sgml-local-ecat-files:nil
173+
End:
174+
-->

‎doc/src/sgml/postgres.sgml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/postgres.sgml,v 1.57 2003/10/17 18:57:01 tgl Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/postgres.sgml,v 1.58 2003/10/22 22:28:10 tgl Exp $
33
-->
44

55
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook V3.1//EN" [
@@ -203,17 +203,17 @@ $Header: /cvsroot/pgsql/doc/src/sgml/postgres.sgml,v 1.57 2003/10/17 18:57:01 tg
203203
</partintro>
204204

205205
&extend;
206-
&indexcost;
207206
&rules;
208207
&trigger;
209-
&spi;
210208

211209
&xplang;
212210
&plsql;
213211
&pltcl;
214212
&plperl;
215213
&plpython;
216214

215+
&spi;
216+
217217
</part>
218218

219219
&reference;
@@ -231,13 +231,15 @@ $Header: /cvsroot/pgsql/doc/src/sgml/postgres.sgml,v 1.57 2003/10/17 18:57:01 tg
231231
&arch-dev;
232232
&catalogs;
233233
&protocol;
234-
&page;
234+
&sources;
235+
&nls;
236+
&plhandler;
235237
&geqo;
238+
&indexcost;
236239
&gist;
240+
&page;
237241
&bki;
238-
&sources;
239242
&compiler;
240-
&nls;
241243

242244
</part>
243245

‎doc/src/sgml/spi.sgml

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/spi.sgml,v 1.27 2003/08/31 17:32:20 petere Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/spi.sgml,v 1.28 2003/10/22 22:28:10 tgl Exp $
33
-->
44

55
<chapter id="spi">
@@ -11,18 +11,28 @@ $Header: /cvsroot/pgsql/doc/src/sgml/spi.sgml,v 1.27 2003/08/31 17:32:20 petere
1111

1212
<para>
1313
The <firstterm>Server Programming Interface</firstterm>
14-
(<acronym>SPI</acronym>) gives users the ability to run
15-
<acronym>SQL</acronym> commands inside user-defined
16-
<acronym>C</acronym> functions. <acronym>SPI</acronym> is a set of
14+
(<acronym>SPI</acronym>) gives writers of user-defined
15+
<acronym>C</acronym> functions the ability to run
16+
<acronym>SQL</acronym> commands inside their functions.
17+
<acronym>SPI</acronym> is a set of
1718
interface functions to simplify access to the parser, planner,
1819
optimizer, and executor. <acronym>SPI</acronym> also does some
1920
memory management.
2021
</para>
2122

23+
<note>
24+
<para>
25+
The available procedural languages provide various means to
26+
execute SQL commands from procedures. Some of these are based on or
27+
modelled after SPI, so this documentation might be of use for users
28+
of those languages as well.
29+
</para>
30+
</note>
31+
2232
<para>
2333
To avoid misunderstanding we'll use the term <quote>function</quote>
2434
when we speak of <acronym>SPI</acronym> interface functions and
25-
<quote>procedure</quote> for user-defined C-functions, which may be
35+
<quote>procedure</quote> forauser-defined C-function that is
2636
using <acronym>SPI</acronym>.
2737
</para>
2838

@@ -50,15 +60,6 @@ $Header: /cvsroot/pgsql/doc/src/sgml/spi.sgml,v 1.27 2003/08/31 17:32:20 petere
5060
<filename>executor/spi.h</filename>.
5161
</para>
5262

53-
<note>
54-
<para>
55-
The available procedural languages provide different means to
56-
execute SQL commands from procedures. Some of these are modelled
57-
after SPI, so this documentation might be of use for those users as
58-
well.
59-
</para>
60-
</note>
61-
6263

6364
<sect1 id="spi-interface">
6465
<title>Interface Functions</title>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp