This patch implements holdable cursors, following the proposal
(materialization into a tuple store) discussed on pgsql-hackers earlier. I've updated the documentation and the regression tests. Notes on the implementation: - I needed to change the tuple store API slightly -- it assumes that it won't be used to hold data across transaction boundaries, so the temp files that it uses for on-disk storage are automatically reclaimed at end-of-transaction. I added a flag to tuplestore_begin_heap() to control this behavior. Is changing the tuple store API in this fashion OK? - in order to store executor results in a tuple store, I added a new CommandDest. This works well for the most part, with one exception: the current DestFunction API doesn't provide enough information to allow the Executor to store results into an arbitrary tuple store (where the particular tuple store to use is chosen by the call site of ExecutorRun). To workaround this, I've temporarily hacked up a solution that works, but is not ideal: since the receiveTuple DestFunction is passed the portal name, we can use that to lookup the Portal data structure for the cursor and then use that to get at the tuple store the Portal is using. This unnecessarily ties the Portal code with the tupleReceiver code, but it works... The proper fix for this is probably to change the DestFunction API -- Tom suggested passing the full QueryDesc to the receiveTuple function. In that case, callers of ExecutorRun could "subclass" QueryDesc to add any additional fields that their particular CommandDest needed to get access to. This approach would work, but I'd like to think about it for a little bit longer before deciding which route to go. In the mean time, the code works fine, so I don't think a fix is urgent. - (semi-related) I added a NO SCROLL keyword to DECLARE CURSOR, and adjusted the behavior of SCROLL in accordance with the discussion on -hackers. - (unrelated) Cleaned up some SGML markup in sql.sgml, copy.sgml Neil Conway
This commit is contained in:
parent
7638087882
commit
54f7338fa1
|
@ -853,7 +853,7 @@ get_crosstab_tuplestore(char *sql,
|
||||||
MemoryContext SPIcontext;
|
MemoryContext SPIcontext;
|
||||||
|
|
||||||
/* initialize our tuplestore */
|
/* initialize our tuplestore */
|
||||||
tupstore = tuplestore_begin_heap(true, SortMem);
|
tupstore = tuplestore_begin_heap(true, false, SortMem);
|
||||||
|
|
||||||
/* Connect to SPI manager */
|
/* Connect to SPI manager */
|
||||||
if ((ret = SPI_connect()) < 0)
|
if ((ret = SPI_connect()) < 0)
|
||||||
|
@ -1124,7 +1124,7 @@ connectby(char *relname,
|
||||||
oldcontext = MemoryContextSwitchTo(per_query_ctx);
|
oldcontext = MemoryContextSwitchTo(per_query_ctx);
|
||||||
|
|
||||||
/* initialize our tuplestore */
|
/* initialize our tuplestore */
|
||||||
tupstore = tuplestore_begin_heap(true, SortMem);
|
tupstore = tuplestore_begin_heap(true, false, SortMem);
|
||||||
|
|
||||||
MemoryContextSwitchTo(oldcontext);
|
MemoryContextSwitchTo(oldcontext);
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<!--
|
<!--
|
||||||
$Header: /cvsroot/pgsql/doc/src/sgml/ref/copy.sgml,v 1.40 2002/09/21 18:32:54 petere Exp $
|
$Header: /cvsroot/pgsql/doc/src/sgml/ref/copy.sgml,v 1.41 2003/03/27 16:51:27 momjian Exp $
|
||||||
PostgreSQL documentation
|
PostgreSQL documentation
|
||||||
-->
|
-->
|
||||||
|
|
||||||
|
@ -133,9 +133,10 @@ COPY <replaceable class="parameter">table</replaceable> [ ( <replaceable class="
|
||||||
</para>
|
</para>
|
||||||
<note>
|
<note>
|
||||||
<para>
|
<para>
|
||||||
On a copy in, any data item that matches this string will be stored as
|
On a <command>COPY FROM</command>, any data item that matches
|
||||||
a NULL value, so you should make sure that you use the same string
|
this string will be stored as a NULL value, so you should
|
||||||
as you used on copy out.
|
make sure that you use the same string as you used with
|
||||||
|
<command>COPY TO</command>.
|
||||||
</para>
|
</para>
|
||||||
</note>
|
</note>
|
||||||
</listitem>
|
</listitem>
|
||||||
|
@ -210,7 +211,8 @@ ERROR: <replaceable>reason</replaceable>
|
||||||
or write to a file. The file must be accessible to the backend and
|
or write to a file. The file must be accessible to the backend and
|
||||||
the name must be specified from the viewpoint of the backend. When
|
the name must be specified from the viewpoint of the backend. When
|
||||||
<filename>stdin</filename> or <filename>stdout</filename> is
|
<filename>stdin</filename> or <filename>stdout</filename> is
|
||||||
specified, data flows through the client frontend to the backend.
|
specified, data is transmitted via the connection between the
|
||||||
|
client frontend and the backend.
|
||||||
|
|
||||||
<tip>
|
<tip>
|
||||||
<para>
|
<para>
|
||||||
|
@ -234,8 +236,8 @@ ERROR: <replaceable>reason</replaceable>
|
||||||
Notes
|
Notes
|
||||||
</title>
|
</title>
|
||||||
<para>
|
<para>
|
||||||
<command>COPY</command> can only be used with plain tables, not with
|
<command>COPY</command> can only be used with plain tables, not
|
||||||
views.
|
with views.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<!--
|
<!--
|
||||||
$Header: /cvsroot/pgsql/doc/src/sgml/ref/declare.sgml,v 1.20 2003/03/21 17:11:46 momjian Exp $
|
$Header: /cvsroot/pgsql/doc/src/sgml/ref/declare.sgml,v 1.21 2003/03/27 16:51:27 momjian Exp $
|
||||||
PostgreSQL documentation
|
PostgreSQL documentation
|
||||||
-->
|
-->
|
||||||
|
|
||||||
|
@ -21,8 +21,8 @@ PostgreSQL documentation
|
||||||
<date>1999-07-20</date>
|
<date>1999-07-20</date>
|
||||||
</refsynopsisdivinfo>
|
</refsynopsisdivinfo>
|
||||||
<synopsis>
|
<synopsis>
|
||||||
DECLARE <replaceable class="parameter">cursorname</replaceable> [ BINARY ] [ INSENSITIVE ] [ SCROLL ]
|
DECLARE <replaceable class="parameter">cursorname</replaceable> [ BINARY ] [ INSENSITIVE ] [ [ NO ] SCROLL ]
|
||||||
CURSOR FOR <replaceable class="parameter">query</replaceable>
|
CURSOR [ { WITH | WITHOUT } HOLD ] FOR <replaceable class="parameter">query</replaceable>
|
||||||
[ FOR { READ ONLY | UPDATE [ OF <replaceable class="parameter">column</replaceable> [, ...] ] ]
|
[ FOR { READ ONLY | UPDATE [ OF <replaceable class="parameter">column</replaceable> [, ...] ] ]
|
||||||
</synopsis>
|
</synopsis>
|
||||||
<refsect2 id="R2-SQL-DECLARE-1">
|
<refsect2 id="R2-SQL-DECLARE-1">
|
||||||
|
@ -38,7 +38,8 @@ DECLARE <replaceable class="parameter">cursorname</replaceable> [ BINARY ] [ INS
|
||||||
<term><replaceable class="parameter">cursorname</replaceable></term>
|
<term><replaceable class="parameter">cursorname</replaceable></term>
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
The name of the cursor to be used in subsequent FETCH operations.
|
The name of the cursor to be used in subsequent
|
||||||
|
<command>FETCH</command> operations.
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
@ -57,8 +58,20 @@ DECLARE <replaceable class="parameter">cursorname</replaceable> [ BINARY ] [ INS
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
<acronym>SQL92</acronym> keyword indicating that data retrieved
|
<acronym>SQL92</acronym> keyword indicating that data retrieved
|
||||||
from the cursor should be unaffected by updates from other processes or cursors.
|
from the cursor should be unaffected by updates from other
|
||||||
By default, all cursors are insensitive. This keyword has no effect.
|
processes or cursors. By default, all cursors are insensitive.
|
||||||
|
This keyword currently has no effect and is present for
|
||||||
|
compatibility with the SQL standard.
|
||||||
|
</para>
|
||||||
|
</listitem>
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry>
|
||||||
|
<term>NO SCROLL</term>
|
||||||
|
<listitem>
|
||||||
|
<para>
|
||||||
|
Specifies that the cursor cannot be used to retrieve rows in a
|
||||||
|
nonsequential fashion (e.g., backward).
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
@ -67,8 +80,33 @@ DECLARE <replaceable class="parameter">cursorname</replaceable> [ BINARY ] [ INS
|
||||||
<term>SCROLL</term>
|
<term>SCROLL</term>
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
Specifies that the cursor may be used to retrieve rows
|
Specifies that the cursor may be used to retrieve rows in a
|
||||||
in a nonsequential fashion (e.g., backwards).
|
nonsequential fashion (e.g., backward). Depending upon the
|
||||||
|
complexity of the query's execution plan, specifying
|
||||||
|
<literal>SCROLL</literal> may impose a slight performance penalty
|
||||||
|
on the query's execution time.
|
||||||
|
</para>
|
||||||
|
</listitem>
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry>
|
||||||
|
<term>WITHOUT HOLD</term>
|
||||||
|
<listitem>
|
||||||
|
<para>
|
||||||
|
Specifies that the cursor cannot be used outside of the
|
||||||
|
transaction that created it. If neither <literal>WITHOUT
|
||||||
|
HOLD</literal> nor <literal>WITH HOLD</literal> is specified,
|
||||||
|
<literal>WITH HOLD</literal> is the default.
|
||||||
|
</para>
|
||||||
|
</listitem>
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry>
|
||||||
|
<term>WITH HOLD</term>
|
||||||
|
<listitem>
|
||||||
|
<para>
|
||||||
|
Specifies that the cursor may be used after the transaction
|
||||||
|
that creates it successfully commits.
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
@ -124,7 +162,8 @@ DECLARE <replaceable class="parameter">cursorname</replaceable> [ BINARY ] [ INS
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
The BINARY, INSENSITIVE, and SCROLL keywords may appear in any order.
|
The <literal>BINARY</literal>, <literal>INSENSITIVE</literal>,
|
||||||
|
<literal>SCROLL</literal> keywords may appear in any order.
|
||||||
</para>
|
</para>
|
||||||
</refsect2>
|
</refsect2>
|
||||||
|
|
||||||
|
@ -144,7 +183,7 @@ DECLARE CURSOR
|
||||||
</computeroutput></term>
|
</computeroutput></term>
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
The message returned if the SELECT is run successfully.
|
The message returned if the <command>SELECT</command> is run successfully.
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
@ -155,9 +194,8 @@ WARNING: Closing pre-existing portal "<replaceable class="parameter">cursorname
|
||||||
</computeroutput></term>
|
</computeroutput></term>
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
This message is reported if the same cursor name was already declared
|
This message is reported if a cursor with the same name already
|
||||||
in the current transaction block. The previous definition is
|
exists. The previous definition is discarded.
|
||||||
discarded.
|
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
@ -168,7 +206,9 @@ ERROR: DECLARE CURSOR may only be used in begin/end transaction blocks
|
||||||
</computeroutput></term>
|
</computeroutput></term>
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
This error occurs if the cursor is not declared within a transaction block.
|
This error occurs if the cursor is not declared within a
|
||||||
|
transaction block, and <literal>WITH HOLD</literal> is not
|
||||||
|
specified.
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
@ -193,16 +233,14 @@ ERROR: DECLARE CURSOR may only be used in begin/end transaction blocks
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
Normal cursors return data in text format, the same as a <command>SELECT</>
|
Normal cursors return data in text format, the same as a
|
||||||
would produce. Since
|
<command>SELECT</> would produce. Since data is stored natively in
|
||||||
data is stored natively in binary format, the system must
|
binary format, the system must do a conversion to produce the text
|
||||||
do a conversion to produce the text format. In addition,
|
format. In addition, text formats are often larger in size than the
|
||||||
text formats are often larger in size than the corresponding binary format.
|
corresponding binary format. Once the information comes back in
|
||||||
Once the information comes back in text form, the client
|
text form, the client application may need to convert it to a
|
||||||
application may need to convert it to a binary format to
|
binary format to manipulate it. BINARY cursors give you back the
|
||||||
manipulate it.
|
data in the native binary representation.
|
||||||
BINARY cursors give you back the data in the native binary
|
|
||||||
representation.
|
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
|
@ -245,7 +283,9 @@ ERROR: DECLARE CURSOR may only be used in begin/end transaction blocks
|
||||||
</title>
|
</title>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
Cursors are only available within transactions. Use
|
If <literal>WITH HOLD</literal> is not specified, the cursor
|
||||||
|
created by this command can only be used within the current
|
||||||
|
transaction. Use
|
||||||
<xref linkend="sql-begin" endterm="sql-begin-title">,
|
<xref linkend="sql-begin" endterm="sql-begin-title">,
|
||||||
<xref linkend="sql-commit" endterm="sql-commit-title">
|
<xref linkend="sql-commit" endterm="sql-commit-title">
|
||||||
and
|
and
|
||||||
|
@ -254,12 +294,25 @@ ERROR: DECLARE CURSOR may only be used in begin/end transaction blocks
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
The <literal>SCROLL</> option should be specified when defining a cursor
|
If <literal>WITH HOLD</literal> is specified and the transaction
|
||||||
that will be used to fetch backwards. This is required by
|
that created the cursor successfully commits, the cursor can be
|
||||||
<acronym>SQL92</acronym>. However, for compatibility with
|
accessed outside the creating transaction. If the creating
|
||||||
earlier versions, <productname>PostgreSQL</productname> will allow
|
transaction is aborted, the cursor is removed. A cursor created
|
||||||
backward fetches without <literal>SCROLL</>, if the cursor's query plan
|
with <literal>WITH HOLD</literal> is closed when an explicit
|
||||||
is simple enough that no extra overhead is needed to support it.
|
<command>CLOSE</command> command is issued on it, or the client
|
||||||
|
connection is terminated.
|
||||||
|
</para>
|
||||||
|
|
||||||
|
<para>
|
||||||
|
The <literal>SCROLL</> option should be specified when defining a
|
||||||
|
cursor that will be used to fetch backwards. This is required by
|
||||||
|
<acronym>SQL92</acronym>. However, for compatibility with earlier
|
||||||
|
versions, <productname>PostgreSQL</productname> will allow
|
||||||
|
backward fetches without <literal>SCROLL</>, if the cursor's query
|
||||||
|
plan is simple enough that no extra overhead is needed to support
|
||||||
|
it. However, application developers are advised not to rely on
|
||||||
|
using backward fetches from a cursor that has not been created
|
||||||
|
with <literal>SCROLL</literal>.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
|
@ -271,7 +324,7 @@ ERROR: DECLARE CURSOR may only be used in begin/end transaction blocks
|
||||||
However, <application>ecpg</application>, the
|
However, <application>ecpg</application>, the
|
||||||
embedded SQL preprocessor for <productname>PostgreSQL</productname>,
|
embedded SQL preprocessor for <productname>PostgreSQL</productname>,
|
||||||
supports the <acronym>SQL92</acronym> cursor conventions, including those
|
supports the <acronym>SQL92</acronym> cursor conventions, including those
|
||||||
involving DECLARE and OPEN statements.
|
involving <command>DECLARE</command> and <command>OPEN</command> statements.
|
||||||
</para>
|
</para>
|
||||||
</refsect2>
|
</refsect2>
|
||||||
</refsect1>
|
</refsect1>
|
||||||
|
@ -303,13 +356,21 @@ DECLARE liahona CURSOR
|
||||||
SQL92
|
SQL92
|
||||||
</title>
|
</title>
|
||||||
<para>
|
<para>
|
||||||
<acronym>SQL92</acronym> allows cursors only in embedded <acronym>SQL</acronym>
|
<para>
|
||||||
and in modules. <productname>PostgreSQL</productname> permits cursors to be used
|
<acronym>SQL92</acronym> allows cursors only in embedded
|
||||||
interactively.
|
<acronym>SQL</acronym> and in modules. <productname>PostgreSQL</>
|
||||||
|
permits cursors to be used interactively.
|
||||||
|
</para>
|
||||||
|
|
||||||
|
<para>
|
||||||
<acronym>SQL92</acronym> allows embedded or modular cursors to
|
<acronym>SQL92</acronym> allows embedded or modular cursors to
|
||||||
update database information.
|
update database information. All <productname>PostgreSQL</>
|
||||||
All <productname>PostgreSQL</productname> cursors are read only.
|
cursors are read only.
|
||||||
The BINARY keyword is a <productname>PostgreSQL</productname> extension.
|
</para>
|
||||||
|
|
||||||
|
<para>
|
||||||
|
The <literal>BINARY</literal> keyword is a
|
||||||
|
<productname>PostgreSQL</productname> extension.
|
||||||
</para>
|
</para>
|
||||||
</refsect2>
|
</refsect2>
|
||||||
</refsect1>
|
</refsect1>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<!--
|
<!--
|
||||||
$Header: /cvsroot/pgsql/doc/src/sgml/ref/fetch.sgml,v 1.27 2003/03/11 19:40:22 tgl Exp $
|
$Header: /cvsroot/pgsql/doc/src/sgml/ref/fetch.sgml,v 1.28 2003/03/27 16:51:27 momjian Exp $
|
||||||
PostgreSQL documentation
|
PostgreSQL documentation
|
||||||
-->
|
-->
|
||||||
|
|
||||||
|
@ -251,8 +251,7 @@ WARNING: PerformPortalFetch: portal "<replaceable class="PARAMETER">cursor</rep
|
||||||
</computeroutput></term>
|
</computeroutput></term>
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
If <replaceable class="PARAMETER">cursor</replaceable> is not known.
|
There is no cursor with the specified name.
|
||||||
The cursor must have been declared within the current transaction block.
|
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
@ -326,7 +325,9 @@ WARNING: PerformPortalFetch: portal "<replaceable class="PARAMETER">cursor</rep
|
||||||
use any variants of <command>FETCH</> other than <command>FETCH NEXT</>
|
use any variants of <command>FETCH</> other than <command>FETCH NEXT</>
|
||||||
or <command>FETCH FORWARD</> with a positive count. For simple queries
|
or <command>FETCH FORWARD</> with a positive count. For simple queries
|
||||||
<productname>PostgreSQL</productname> will allow backwards fetch from
|
<productname>PostgreSQL</productname> will allow backwards fetch from
|
||||||
cursors not declared with SCROLL, but this behavior is best not relied on.
|
cursors not declared with SCROLL, but this behavior is best not
|
||||||
|
relied on. If the cursor is declared with NO SCROLL, no backward
|
||||||
|
fetches are allowed.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
|
@ -339,16 +340,11 @@ WARNING: PerformPortalFetch: portal "<replaceable class="PARAMETER">cursor</rep
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
Updating data via a cursor is not supported by
|
Updating data via a cursor is not supported by
|
||||||
<productname>PostgreSQL</productname>,
|
<productname>PostgreSQL</productname>, because mapping cursor
|
||||||
because mapping cursor updates back to base tables is
|
updates back to base tables is not generally possible, as is also
|
||||||
not generally possible, as is also the case with VIEW updates.
|
the case with view updates. Consequently, users must issue
|
||||||
Consequently,
|
explicit <command>UPDATE</command> commands to replace data.
|
||||||
users must issue explicit UPDATE commands to replace data.
|
|
||||||
</para>
|
|
||||||
|
|
||||||
<para>
|
|
||||||
Cursors may only be used inside transaction blocks.
|
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
|
@ -357,12 +353,6 @@ WARNING: PerformPortalFetch: portal "<replaceable class="PARAMETER">cursor</rep
|
||||||
Use
|
Use
|
||||||
<xref linkend="sql-move" endterm="sql-move-title">
|
<xref linkend="sql-move" endterm="sql-move-title">
|
||||||
to change cursor position without retrieving data.
|
to change cursor position without retrieving data.
|
||||||
Refer to
|
|
||||||
<xref linkend="sql-begin" endterm="sql-begin-title">,
|
|
||||||
<xref linkend="sql-commit" endterm="sql-commit-title">,
|
|
||||||
and
|
|
||||||
<xref linkend="sql-rollback" endterm="sql-rollback-title">
|
|
||||||
for further information about transactions.
|
|
||||||
</para>
|
</para>
|
||||||
</refsect2>
|
</refsect2>
|
||||||
</refsect1>
|
</refsect1>
|
||||||
|
@ -379,7 +369,7 @@ WARNING: PerformPortalFetch: portal "<replaceable class="PARAMETER">cursor</rep
|
||||||
-- Set up and use a cursor:
|
-- Set up and use a cursor:
|
||||||
|
|
||||||
BEGIN WORK;
|
BEGIN WORK;
|
||||||
DECLARE liahona CURSOR FOR SELECT * FROM films;
|
DECLARE liahona SCROLL CURSOR FOR SELECT * FROM films;
|
||||||
|
|
||||||
-- Fetch first 5 rows in the cursor liahona:
|
-- Fetch first 5 rows in the cursor liahona:
|
||||||
FETCH FORWARD 5 IN liahona;
|
FETCH FORWARD 5 IN liahona;
|
||||||
|
@ -425,9 +415,10 @@ COMMIT WORK;
|
||||||
</title>
|
</title>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
<acronym>SQL92</acronym> defines FETCH for use in embedded contexts only.
|
<acronym>SQL92</acronym> defines <command>FETCH</command> for use
|
||||||
Therefore, it describes placing the results into explicit variables using
|
in embedded contexts only. Therefore, it describes placing the
|
||||||
an <literal>INTO</> clause, for example:
|
results into explicit variables using an <literal>INTO</> clause,
|
||||||
|
for example:
|
||||||
|
|
||||||
<synopsis>
|
<synopsis>
|
||||||
FETCH ABSOLUTE <replaceable class="PARAMETER">n</replaceable>
|
FETCH ABSOLUTE <replaceable class="PARAMETER">n</replaceable>
|
||||||
|
@ -435,16 +426,18 @@ FETCH ABSOLUTE <replaceable class="PARAMETER">n</replaceable>
|
||||||
INTO :<replaceable class="PARAMETER">variable</replaceable> [, ...]
|
INTO :<replaceable class="PARAMETER">variable</replaceable> [, ...]
|
||||||
</synopsis>
|
</synopsis>
|
||||||
|
|
||||||
<productname>PostgreSQL</productname>'s use of non-embedded cursors
|
<productname>PostgreSQL</productname>'s use of non-embedded
|
||||||
is non-standard, and so is its practice of returning the result data
|
cursors is non-standard, and so is its practice of returning the
|
||||||
as if it were a SELECT result. Other than this point, FETCH is fully
|
result data as if it were a <command>SELECT</command> result.
|
||||||
|
Other than this point, <command>FETCH</command> is fully
|
||||||
upward-compatible with <acronym>SQL92</acronym>.
|
upward-compatible with <acronym>SQL92</acronym>.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
The FETCH forms involving FORWARD and BACKWARD (including the forms
|
The <command>FETCH</command> forms involving FORWARD and BACKWARD
|
||||||
FETCH <replaceable class="PARAMETER">count</replaceable> and FETCH ALL,
|
(including the forms FETCH <replaceable
|
||||||
in which FORWARD is implicit) are <productname>PostgreSQL</productname>
|
class="PARAMETER">count</replaceable> and FETCH ALL, in which
|
||||||
|
FORWARD is implicit) are <productname>PostgreSQL</productname>
|
||||||
extensions.
|
extensions.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<!--
|
<!--
|
||||||
$Header: /cvsroot/pgsql/doc/src/sgml/ref/move.sgml,v 1.20 2003/03/11 19:40:22 tgl Exp $
|
$Header: /cvsroot/pgsql/doc/src/sgml/ref/move.sgml,v 1.21 2003/03/27 16:51:27 momjian Exp $
|
||||||
PostgreSQL documentation
|
PostgreSQL documentation
|
||||||
-->
|
-->
|
||||||
|
|
||||||
|
@ -64,12 +64,6 @@ MOVE [ <replaceable class="PARAMETER">direction</replaceable> { FROM | IN } ] <r
|
||||||
Refer to
|
Refer to
|
||||||
<xref linkend="sql-declare" endterm="sql-declare-title">
|
<xref linkend="sql-declare" endterm="sql-declare-title">
|
||||||
to define a cursor.
|
to define a cursor.
|
||||||
Refer to
|
|
||||||
<xref linkend="sql-begin" endterm="sql-begin-title">,
|
|
||||||
<xref linkend="sql-commit" endterm="sql-commit-title">,
|
|
||||||
and
|
|
||||||
<xref linkend="sql-rollback" endterm="sql-rollback-title">
|
|
||||||
for further information about transactions.
|
|
||||||
</para>
|
</para>
|
||||||
</refsect2>
|
</refsect2>
|
||||||
</refsect1>
|
</refsect1>
|
||||||
|
@ -83,7 +77,7 @@ MOVE [ <replaceable class="PARAMETER">direction</replaceable> { FROM | IN } ] <r
|
||||||
|
|
||||||
<programlisting>
|
<programlisting>
|
||||||
BEGIN WORK;
|
BEGIN WORK;
|
||||||
DECLARE liahona CURSOR FOR SELECT * FROM films;
|
DECLARE liahona CURSOR FOR SELECT * FROM films;
|
||||||
-- Skip first 5 rows:
|
-- Skip first 5 rows:
|
||||||
MOVE FORWARD 5 IN liahona;
|
MOVE FORWARD 5 IN liahona;
|
||||||
<computeroutput>
|
<computeroutput>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<!--
|
<!--
|
||||||
$Header: /cvsroot/pgsql/doc/src/sgml/sql.sgml,v 1.29 2003/02/19 04:06:28 momjian Exp $
|
$Header: /cvsroot/pgsql/doc/src/sgml/sql.sgml,v 1.30 2003/03/27 16:51:26 momjian Exp $
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<chapter id="sql">
|
<chapter id="sql">
|
||||||
|
@ -851,7 +851,7 @@ A < B + 3.
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
The most often used command in <acronym>SQL</acronym> is the
|
The most often used command in <acronym>SQL</acronym> is the
|
||||||
SELECT statement,
|
<command>SELECT</command> statement,
|
||||||
used to retrieve data. The syntax is:
|
used to retrieve data. The syntax is:
|
||||||
|
|
||||||
<synopsis>
|
<synopsis>
|
||||||
|
@ -881,7 +881,7 @@ SELECT [ ALL | DISTINCT [ ON ( <replaceable class="PARAMETER">expression</replac
|
||||||
<title>Simple Selects</title>
|
<title>Simple Selects</title>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
Here are some simple examples using a SELECT statement:
|
Here are some simple examples using a <command>SELECT</command> statement:
|
||||||
|
|
||||||
<example>
|
<example>
|
||||||
<title id="simple-query">Simple Query with Qualification</title>
|
<title id="simple-query">Simple Query with Qualification</title>
|
||||||
|
@ -905,9 +905,10 @@ SELECT * FROM PART
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
Using <quote>*</quote> in the SELECT statement will deliver all attributes from
|
Using <quote>*</quote> in the <command>SELECT</command> statement
|
||||||
the table. If we want to retrieve only the attributes PNAME and PRICE
|
will deliver all attributes from the table. If we want to retrieve
|
||||||
from table PART we use the statement:
|
only the attributes PNAME and PRICE from table PART we use the
|
||||||
|
statement:
|
||||||
|
|
||||||
<programlisting>
|
<programlisting>
|
||||||
SELECT PNAME, PRICE
|
SELECT PNAME, PRICE
|
||||||
|
@ -924,9 +925,9 @@ SELECT PNAME, PRICE
|
||||||
Cam | 25
|
Cam | 25
|
||||||
</programlisting>
|
</programlisting>
|
||||||
|
|
||||||
Note that the <acronym>SQL</acronym> SELECT corresponds to the
|
Note that the <acronym>SQL</acronym> <command>SELECT</command>
|
||||||
<quote>projection</quote> in relational algebra not to the
|
corresponds to the <quote>projection</quote> in relational algebra
|
||||||
<quote>selection</quote> (see <xref linkend="rel-alg"
|
not to the <quote>selection</quote> (see <xref linkend="rel-alg"
|
||||||
endterm="rel-alg"> for more details).
|
endterm="rel-alg"> for more details).
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
|
@ -1252,15 +1253,15 @@ select sname, pname from supplier
|
||||||
<title id="aggregates-tutorial">Aggregate Operators</title>
|
<title id="aggregates-tutorial">Aggregate Operators</title>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
<acronym>SQL</acronym> provides aggregate operators
|
<acronym>SQL</acronym> provides aggregate operators (e.g. AVG,
|
||||||
(e.g. AVG, COUNT, SUM, MIN, MAX) that
|
COUNT, SUM, MIN, MAX) that take an expression as argument. The
|
||||||
take an expression as argument. The expression is evaluated at
|
expression is evaluated at each row that satisfies the WHERE
|
||||||
each row that satisfies the WHERE clause, and the aggregate operator
|
clause, and the aggregate operator is calculated over this set
|
||||||
is calculated over this set of input values. Normally, an aggregate
|
of input values. Normally, an aggregate delivers a single
|
||||||
delivers a single result for a whole SELECT statement. But if
|
result for a whole <command>SELECT</command> statement. But if
|
||||||
grouping is specified in the query, then a separate calculation is done
|
grouping is specified in the query, then a separate calculation
|
||||||
over the rows of each group, and an aggregate result is delivered per
|
is done over the rows of each group, and an aggregate result is
|
||||||
group (see next section).
|
delivered per group (see next section).
|
||||||
|
|
||||||
<example>
|
<example>
|
||||||
<title id="aggregates-example">Aggregates</title>
|
<title id="aggregates-example">Aggregates</title>
|
||||||
|
@ -1413,11 +1414,12 @@ SELECT S.SNO, S.SNAME, COUNT(SE.PNO)
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
Also observe that it makes no sense to ask for an aggregate of an
|
Also observe that it makes no sense to ask for an aggregate of
|
||||||
aggregate, e.g., AVG(MAX(sno)), because a SELECT only does one pass
|
an aggregate, e.g., AVG(MAX(sno)), because a
|
||||||
of grouping and aggregation. You can get a result of this kind by
|
<command>SELECT</command> only does one pass of grouping and
|
||||||
using a temporary table or a sub-SELECT in the FROM clause to
|
aggregation. You can get a result of this kind by using a
|
||||||
do the first level of aggregation.
|
temporary table or a sub-SELECT in the FROM clause to do the
|
||||||
|
first level of aggregation.
|
||||||
</para>
|
</para>
|
||||||
</sect3>
|
</sect3>
|
||||||
|
|
||||||
|
@ -1502,16 +1504,18 @@ SELECT *
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
When we look at the above query we can see
|
When we look at the above query we can see the keyword
|
||||||
the keyword SELECT two times. The first one at the beginning of the
|
<command>SELECT</command> two times. The first one at the
|
||||||
query - we will refer to it as outer SELECT - and the one in the WHERE
|
beginning of the query - we will refer to it as outer
|
||||||
clause which begins a nested query - we will refer to it as inner
|
<command>SELECT</command> - and the one in the WHERE clause which
|
||||||
SELECT. For every tuple of the outer SELECT the inner SELECT has to be
|
begins a nested query - we will refer to it as inner
|
||||||
evaluated. After every evaluation we know the price of the tuple named
|
<command>SELECT</command>. For every tuple of the outer
|
||||||
'Screw' and we can check if the price of the actual tuple is
|
<command>SELECT</command> the inner <command>SELECT</command> has
|
||||||
greater. (Actually, in this example the inner query need only be
|
to be evaluated. After every evaluation we know the price of the
|
||||||
evaluated once, since it does not depend on the state of the outer
|
tuple named 'Screw' and we can check if the price of the actual
|
||||||
query.)
|
tuple is greater. (Actually, in this example the inner query need
|
||||||
|
only be evaluated once, since it does not depend on the state of
|
||||||
|
the outer query.)
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
|
@ -1528,11 +1532,13 @@ SELECT *
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
In our example the result will be empty because every supplier sells
|
In our example the result will be empty because every supplier
|
||||||
at least one part. Note that we use S.SNO from the outer SELECT within
|
sells at least one part. Note that we use S.SNO from the outer
|
||||||
the WHERE clause of the inner SELECT. Here the subquery must be
|
<command>SELECT</command> within the WHERE clause of the inner
|
||||||
evaluated afresh for each tuple from the outer query, i.e. the value for
|
<command>SELECT</command>. Here the subquery must be evaluated
|
||||||
S.SNO is always taken from the current tuple of the outer SELECT.
|
afresh for each tuple from the outer query, i.e. the value for
|
||||||
|
S.SNO is always taken from the current tuple of the outer
|
||||||
|
<command>SELECT</command>.
|
||||||
</para>
|
</para>
|
||||||
</example>
|
</example>
|
||||||
</para>
|
</para>
|
||||||
|
@ -1670,7 +1676,7 @@ EXCEPT
|
||||||
<para>
|
<para>
|
||||||
The most fundamental command for data definition is the
|
The most fundamental command for data definition is the
|
||||||
one that creates a new relation (a new table). The syntax of the
|
one that creates a new relation (a new table). The syntax of the
|
||||||
CREATE TABLE command is:
|
<command>CREATE TABLE</command> command is:
|
||||||
|
|
||||||
<synopsis>
|
<synopsis>
|
||||||
CREATE TABLE <replaceable class="parameter">table_name</replaceable>
|
CREATE TABLE <replaceable class="parameter">table_name</replaceable>
|
||||||
|
@ -1786,7 +1792,7 @@ CREATE TABLE SELLS
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
To create an index in <acronym>SQL</acronym>
|
To create an index in <acronym>SQL</acronym>
|
||||||
the CREATE INDEX command is used. The syntax is:
|
the <command>CREATE INDEX</command> command is used. The syntax is:
|
||||||
|
|
||||||
<programlisting>
|
<programlisting>
|
||||||
CREATE INDEX <replaceable class="parameter">index_name</replaceable>
|
CREATE INDEX <replaceable class="parameter">index_name</replaceable>
|
||||||
|
@ -1808,10 +1814,11 @@ CREATE INDEX I ON SUPPLIER (SNAME);
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
The created index is maintained automatically, i.e. whenever a new tuple
|
The created index is maintained automatically, i.e. whenever a new
|
||||||
is inserted into the relation SUPPLIER the index I is adapted. Note
|
tuple is inserted into the relation SUPPLIER the index I is
|
||||||
that the only changes a user can perceive when an index is present
|
adapted. Note that the only changes a user can perceive when an
|
||||||
are increased speed for SELECT and decreases in speed of updates.
|
index is present are increased speed for <command>SELECT</command>
|
||||||
|
and decreases in speed of updates.
|
||||||
</para>
|
</para>
|
||||||
</example>
|
</example>
|
||||||
</para>
|
</para>
|
||||||
|
@ -1916,7 +1923,7 @@ SELECT * FROM London_Suppliers
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
To destroy a table (including all tuples stored in that table) the
|
To destroy a table (including all tuples stored in that table) the
|
||||||
DROP TABLE command is used:
|
<command>DROP TABLE</command> command is used:
|
||||||
|
|
||||||
<programlisting>
|
<programlisting>
|
||||||
DROP TABLE <replaceable class="parameter">table_name</replaceable>;
|
DROP TABLE <replaceable class="parameter">table_name</replaceable>;
|
||||||
|
@ -1932,7 +1939,7 @@ DROP TABLE SUPPLIER;
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
The DROP INDEX command is used to destroy an index:
|
The <command>DROP INDEX</command> command is used to destroy an index:
|
||||||
|
|
||||||
<programlisting>
|
<programlisting>
|
||||||
DROP INDEX <replaceable class="parameter">index_name</replaceable>;
|
DROP INDEX <replaceable class="parameter">index_name</replaceable>;
|
||||||
|
@ -1940,7 +1947,8 @@ DROP INDEX <replaceable class="parameter">index_name</replaceable>;
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
Finally to destroy a given view use the command DROP VIEW:
|
Finally to destroy a given view use the command <command>DROP
|
||||||
|
VIEW</command>:
|
||||||
|
|
||||||
<programlisting>
|
<programlisting>
|
||||||
DROP VIEW <replaceable class="parameter">view_name</replaceable>;
|
DROP VIEW <replaceable class="parameter">view_name</replaceable>;
|
||||||
|
@ -1994,7 +2002,7 @@ INSERT INTO SELLS (SNO, PNO)
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
To change one or more attribute values of tuples in a relation the
|
To change one or more attribute values of tuples in a relation the
|
||||||
UPDATE command is used. The syntax is:
|
<command>UPDATE</command> command is used. The syntax is:
|
||||||
|
|
||||||
<programlisting>
|
<programlisting>
|
||||||
UPDATE <replaceable class="parameter">table_name</replaceable>
|
UPDATE <replaceable class="parameter">table_name</replaceable>
|
||||||
|
@ -2126,7 +2134,7 @@ DELETE FROM SUPPLIER
|
||||||
need a mechanism to access every single tuple of the set of tuples
|
need a mechanism to access every single tuple of the set of tuples
|
||||||
returned by a SELECT statement. This mechanism can be provided by
|
returned by a SELECT statement. This mechanism can be provided by
|
||||||
declaring a <firstterm>cursor</firstterm>.
|
declaring a <firstterm>cursor</firstterm>.
|
||||||
After that we can use the FETCH command to
|
After that we can use the <command>FETCH</command> command to
|
||||||
retrieve a tuple and set the cursor to the next tuple.
|
retrieve a tuple and set the cursor to the next tuple.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.144 2003/03/21 04:33:15 momjian Exp $
|
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.145 2003/03/27 16:51:27 momjian Exp $
|
||||||
*
|
*
|
||||||
* NOTES
|
* NOTES
|
||||||
* Transaction aborts can now occur two ways:
|
* Transaction aborts can now occur two ways:
|
||||||
|
@ -926,7 +926,7 @@ CommitTransaction(void)
|
||||||
* access, and in fact could still cause an error...)
|
* access, and in fact could still cause an error...)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
AtEOXact_portals();
|
AtEOXact_portals(true);
|
||||||
|
|
||||||
/* handle commit for large objects [ PA, 7/17/98 ] */
|
/* handle commit for large objects [ PA, 7/17/98 ] */
|
||||||
/* XXX probably this does not belong here */
|
/* XXX probably this does not belong here */
|
||||||
|
@ -1057,7 +1057,7 @@ AbortTransaction(void)
|
||||||
* do abort processing
|
* do abort processing
|
||||||
*/
|
*/
|
||||||
DeferredTriggerAbortXact();
|
DeferredTriggerAbortXact();
|
||||||
AtEOXact_portals();
|
AtEOXact_portals(false);
|
||||||
lo_commit(false); /* 'false' means it's abort */
|
lo_commit(false); /* 'false' means it's abort */
|
||||||
AtAbort_Notify();
|
AtAbort_Notify();
|
||||||
AtEOXact_UpdatePasswordFile(false);
|
AtEOXact_UpdatePasswordFile(false);
|
||||||
|
|
|
@ -1,15 +1,14 @@
|
||||||
/*-------------------------------------------------------------------------
|
/*-------------------------------------------------------------------------
|
||||||
*
|
*
|
||||||
* copy.c
|
* copy.c
|
||||||
* COPY command.
|
* Implements the COPY utility command.
|
||||||
*
|
|
||||||
*
|
*
|
||||||
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
|
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.189 2003/02/03 21:15:43 tgl Exp $
|
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.190 2003/03/27 16:51:27 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
@ -50,6 +49,9 @@
|
||||||
#define ISOCTAL(c) (((c) >= '0') && ((c) <= '7'))
|
#define ISOCTAL(c) (((c) >= '0') && ((c) <= '7'))
|
||||||
#define OCTVALUE(c) ((c) - '0')
|
#define OCTVALUE(c) ((c) - '0')
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Represents the type of data returned by CopyReadAttribute()
|
||||||
|
*/
|
||||||
typedef enum CopyReadResult
|
typedef enum CopyReadResult
|
||||||
{
|
{
|
||||||
NORMAL_ATTR,
|
NORMAL_ATTR,
|
||||||
|
@ -1311,7 +1313,7 @@ GetTypeElement(Oid type)
|
||||||
* *result is set to indicate what terminated the read:
|
* *result is set to indicate what terminated the read:
|
||||||
* NORMAL_ATTR: column delimiter
|
* NORMAL_ATTR: column delimiter
|
||||||
* END_OF_LINE: newline
|
* END_OF_LINE: newline
|
||||||
* END_OF_FILE: EOF indication
|
* END_OF_FILE: EOF indicator
|
||||||
* In all cases, the string read up to the terminator is returned.
|
* In all cases, the string read up to the terminator is returned.
|
||||||
*
|
*
|
||||||
* Note: This function does not care about SQL NULL values -- it
|
* Note: This function does not care about SQL NULL values -- it
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/commands/portalcmds.c,v 1.10 2003/03/11 19:40:22 tgl Exp $
|
* $Header: /cvsroot/pgsql/src/backend/commands/portalcmds.c,v 1.11 2003/03/27 16:51:27 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
@ -17,18 +17,23 @@
|
||||||
|
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
|
||||||
|
#include "miscadmin.h"
|
||||||
#include "commands/portalcmds.h"
|
#include "commands/portalcmds.h"
|
||||||
#include "executor/executor.h"
|
#include "executor/executor.h"
|
||||||
#include "optimizer/planner.h"
|
#include "optimizer/planner.h"
|
||||||
#include "rewrite/rewriteHandler.h"
|
#include "rewrite/rewriteHandler.h"
|
||||||
|
#include "utils/memutils.h"
|
||||||
|
|
||||||
static long DoRelativeFetch(Portal portal,
|
static long DoRelativeFetch(Portal portal,
|
||||||
bool forward,
|
bool forward,
|
||||||
long count,
|
long count,
|
||||||
CommandDest dest);
|
CommandDest dest);
|
||||||
|
static long DoRelativeStoreFetch(Portal portal,
|
||||||
|
bool forward,
|
||||||
|
long count,
|
||||||
|
CommandDest dest);
|
||||||
static void DoPortalRewind(Portal portal);
|
static void DoPortalRewind(Portal portal);
|
||||||
static Portal PreparePortal(char *portalName);
|
static Portal PreparePortal(DeclareCursorStmt *stmt);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -46,8 +51,15 @@ PerformCursorOpen(DeclareCursorStmt *stmt, CommandDest dest)
|
||||||
char *cursorName;
|
char *cursorName;
|
||||||
QueryDesc *queryDesc;
|
QueryDesc *queryDesc;
|
||||||
|
|
||||||
/* Check for invalid context (must be in transaction block) */
|
/*
|
||||||
RequireTransactionChain((void *) stmt, "DECLARE CURSOR");
|
* If this is a non-holdable cursor, we ensure that this statement
|
||||||
|
* has been executed inside a transaction block (or else, it would
|
||||||
|
* have no user-visible effect).
|
||||||
|
*
|
||||||
|
* XXX: surely there is a better way to check this?
|
||||||
|
*/
|
||||||
|
if (!(stmt->options & CURSOR_OPT_HOLD))
|
||||||
|
RequireTransactionChain((void *) stmt, "DECLARE CURSOR");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The query has been through parse analysis, but not rewriting or
|
* The query has been through parse analysis, but not rewriting or
|
||||||
|
@ -76,7 +88,7 @@ PerformCursorOpen(DeclareCursorStmt *stmt, CommandDest dest)
|
||||||
/*
|
/*
|
||||||
* Create a portal and copy the query and plan into its memory context.
|
* Create a portal and copy the query and plan into its memory context.
|
||||||
*/
|
*/
|
||||||
portal = PreparePortal(stmt->portalname);
|
portal = PreparePortal(stmt);
|
||||||
|
|
||||||
oldContext = MemoryContextSwitchTo(PortalGetHeapMemory(portal));
|
oldContext = MemoryContextSwitchTo(PortalGetHeapMemory(portal));
|
||||||
query = copyObject(query);
|
query = copyObject(query);
|
||||||
|
@ -130,6 +142,7 @@ PerformPortalFetch(FetchStmt *stmt,
|
||||||
portal = GetPortalByName(stmt->portalname);
|
portal = GetPortalByName(stmt->portalname);
|
||||||
if (!PortalIsValid(portal))
|
if (!PortalIsValid(portal))
|
||||||
{
|
{
|
||||||
|
/* FIXME: shouldn't this be an ERROR? */
|
||||||
elog(WARNING, "PerformPortalFetch: portal \"%s\" not found",
|
elog(WARNING, "PerformPortalFetch: portal \"%s\" not found",
|
||||||
stmt->portalname);
|
stmt->portalname);
|
||||||
return;
|
return;
|
||||||
|
@ -343,6 +356,9 @@ DoRelativeFetch(Portal portal,
|
||||||
ScanDirection direction;
|
ScanDirection direction;
|
||||||
QueryDesc temp_queryDesc;
|
QueryDesc temp_queryDesc;
|
||||||
|
|
||||||
|
if (portal->holdStore)
|
||||||
|
return DoRelativeStoreFetch(portal, forward, count, dest);
|
||||||
|
|
||||||
queryDesc = PortalGetQueryDesc(portal);
|
queryDesc = PortalGetQueryDesc(portal);
|
||||||
estate = queryDesc->estate;
|
estate = queryDesc->estate;
|
||||||
|
|
||||||
|
@ -407,7 +423,7 @@ DoRelativeFetch(Portal portal,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!portal->backwardOK)
|
if (portal->scrollType == DISABLE_SCROLL)
|
||||||
elog(ERROR, "Cursor can only scan forward"
|
elog(ERROR, "Cursor can only scan forward"
|
||||||
"\n\tDeclare it with SCROLL option to enable backward scan");
|
"\n\tDeclare it with SCROLL option to enable backward scan");
|
||||||
|
|
||||||
|
@ -452,17 +468,85 @@ DoRelativeFetch(Portal portal,
|
||||||
return estate->es_processed;
|
return estate->es_processed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* DoRelativeStoreFetch
|
||||||
|
* Do fetch for a simple N-rows-forward-or-backward case, getting
|
||||||
|
* the results from the portal's tuple store.
|
||||||
|
*/
|
||||||
|
static long
|
||||||
|
DoRelativeStoreFetch(Portal portal,
|
||||||
|
bool forward,
|
||||||
|
long count,
|
||||||
|
CommandDest dest)
|
||||||
|
{
|
||||||
|
DestReceiver *destfunc;
|
||||||
|
QueryDesc *queryDesc = portal->queryDesc;
|
||||||
|
long rows_fetched = 0;
|
||||||
|
|
||||||
|
if (!forward && portal->scrollType == DISABLE_SCROLL)
|
||||||
|
elog(ERROR, "Cursor can only scan forward"
|
||||||
|
"\n\tDeclare it with SCROLL option to enable backward scan");
|
||||||
|
|
||||||
|
destfunc = DestToFunction(dest);
|
||||||
|
(*destfunc->setup) (destfunc, queryDesc->operation,
|
||||||
|
portal->name, queryDesc->tupDesc);
|
||||||
|
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
HeapTuple tup;
|
||||||
|
bool should_free;
|
||||||
|
|
||||||
|
if (rows_fetched >= count)
|
||||||
|
break;
|
||||||
|
if (portal->atEnd && forward)
|
||||||
|
break;
|
||||||
|
if (portal->atStart && !forward)
|
||||||
|
break;
|
||||||
|
|
||||||
|
tup = tuplestore_getheaptuple(portal->holdStore, forward, &should_free);
|
||||||
|
|
||||||
|
if (tup == NULL)
|
||||||
|
{
|
||||||
|
if (forward)
|
||||||
|
portal->atEnd = true;
|
||||||
|
else
|
||||||
|
portal->atStart = true;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
(*destfunc->receiveTuple) (tup, queryDesc->tupDesc, destfunc);
|
||||||
|
|
||||||
|
rows_fetched++;
|
||||||
|
if (forward)
|
||||||
|
portal->portalPos++;
|
||||||
|
else
|
||||||
|
portal->portalPos--;
|
||||||
|
|
||||||
|
if (forward && portal->atStart)
|
||||||
|
portal->atStart = false;
|
||||||
|
if (!forward && portal->atEnd)
|
||||||
|
portal->atEnd = false;
|
||||||
|
|
||||||
|
if (should_free)
|
||||||
|
pfree(tup);
|
||||||
|
}
|
||||||
|
|
||||||
|
(*destfunc->cleanup) (destfunc);
|
||||||
|
|
||||||
|
return rows_fetched;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* DoPortalRewind - rewind a Portal to starting point
|
* DoPortalRewind - rewind a Portal to starting point
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
DoPortalRewind(Portal portal)
|
DoPortalRewind(Portal portal)
|
||||||
{
|
{
|
||||||
QueryDesc *queryDesc;
|
if (portal->holdStore)
|
||||||
|
tuplestore_rescan(portal->holdStore);
|
||||||
queryDesc = PortalGetQueryDesc(portal);
|
else
|
||||||
|
ExecutorRewind(PortalGetQueryDesc(portal));
|
||||||
ExecutorRewind(queryDesc);
|
|
||||||
|
|
||||||
portal->atStart = true;
|
portal->atStart = true;
|
||||||
portal->atEnd = false;
|
portal->atEnd = false;
|
||||||
|
@ -493,22 +577,25 @@ PerformPortalClose(char *name)
|
||||||
/*
|
/*
|
||||||
* Note: PortalCleanup is called as a side-effect
|
* Note: PortalCleanup is called as a side-effect
|
||||||
*/
|
*/
|
||||||
PortalDrop(portal);
|
PortalDrop(portal, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* PreparePortal
|
* PreparePortal
|
||||||
|
* Given a DECLARE CURSOR statement, returns the Portal data
|
||||||
|
* structure based on that statement that is used to manage the
|
||||||
|
* Portal internally. If a portal with specified name already
|
||||||
|
* exists, it is replaced.
|
||||||
*/
|
*/
|
||||||
static Portal
|
static Portal
|
||||||
PreparePortal(char *portalName)
|
PreparePortal(DeclareCursorStmt *stmt)
|
||||||
{
|
{
|
||||||
Portal portal;
|
Portal portal;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check for already-in-use portal name.
|
* Check for already-in-use portal name.
|
||||||
*/
|
*/
|
||||||
portal = GetPortalByName(portalName);
|
portal = GetPortalByName(stmt->portalname);
|
||||||
if (PortalIsValid(portal))
|
if (PortalIsValid(portal))
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
|
@ -516,19 +603,30 @@ PreparePortal(char *portalName)
|
||||||
* portal?
|
* portal?
|
||||||
*/
|
*/
|
||||||
elog(WARNING, "Closing pre-existing portal \"%s\"",
|
elog(WARNING, "Closing pre-existing portal \"%s\"",
|
||||||
portalName);
|
stmt->portalname);
|
||||||
PortalDrop(portal);
|
PortalDrop(portal, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create the new portal.
|
* Create the new portal.
|
||||||
*/
|
*/
|
||||||
portal = CreatePortal(portalName);
|
portal = CreatePortal(stmt->portalname);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Modify the newly created portal based on the options specified in
|
||||||
|
* the DECLARE CURSOR statement.
|
||||||
|
*/
|
||||||
|
if (stmt->options & CURSOR_OPT_SCROLL)
|
||||||
|
portal->scrollType = ENABLE_SCROLL;
|
||||||
|
else if (stmt->options & CURSOR_OPT_NO_SCROLL)
|
||||||
|
portal->scrollType = DISABLE_SCROLL;
|
||||||
|
|
||||||
|
if (stmt->options & CURSOR_OPT_HOLD)
|
||||||
|
portal->holdOpen = true;
|
||||||
|
|
||||||
return portal;
|
return portal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* PortalCleanup
|
* PortalCleanup
|
||||||
*
|
*
|
||||||
|
@ -545,14 +643,128 @@ PortalCleanup(Portal portal)
|
||||||
AssertArg(PortalIsValid(portal));
|
AssertArg(PortalIsValid(portal));
|
||||||
AssertArg(portal->cleanup == PortalCleanup);
|
AssertArg(portal->cleanup == PortalCleanup);
|
||||||
|
|
||||||
/*
|
if (portal->holdStore)
|
||||||
* tell the executor to shutdown the query
|
tuplestore_end(portal->holdStore);
|
||||||
*/
|
else
|
||||||
ExecutorEnd(PortalGetQueryDesc(portal));
|
ExecutorEnd(PortalGetQueryDesc(portal));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* PersistHoldablePortal
|
||||||
|
*
|
||||||
|
* Prepare the specified Portal for access outside of the current
|
||||||
|
* transaction. When this function returns, all future accesses to the
|
||||||
|
* portal must be done via the Tuplestore (not by invoking the
|
||||||
|
* executor).
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
PersistHoldablePortal(Portal portal)
|
||||||
|
{
|
||||||
|
MemoryContext oldcxt;
|
||||||
|
QueryDesc *queryDesc = PortalGetQueryDesc(portal);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This should be unnecessary since the querydesc should be in the
|
* If we're preserving a holdable portal, we had better be
|
||||||
* portal's memory context, but do it anyway for symmetry.
|
* inside the transaction that originally created it.
|
||||||
*/
|
*/
|
||||||
FreeQueryDesc(PortalGetQueryDesc(portal));
|
Assert(portal->createXact == GetCurrentTransactionId());
|
||||||
|
Assert(portal->holdStore == NULL);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This context is used to store portal data that needs to persist
|
||||||
|
* between transactions.
|
||||||
|
*/
|
||||||
|
oldcxt = MemoryContextSwitchTo(portal->holdContext);
|
||||||
|
|
||||||
|
/* XXX: Should SortMem be used for this? */
|
||||||
|
portal->holdStore = tuplestore_begin_heap(true, true, SortMem);
|
||||||
|
|
||||||
|
/* Set the destination to output to the tuplestore */
|
||||||
|
queryDesc->dest = Tuplestore;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Rewind the executor: we need to store the entire result set in
|
||||||
|
* the tuplestore, so that subsequent backward FETCHs can be
|
||||||
|
* processed.
|
||||||
|
*/
|
||||||
|
ExecutorRewind(queryDesc);
|
||||||
|
|
||||||
|
/* Fetch the result set into the tuplestore */
|
||||||
|
ExecutorRun(queryDesc, ForwardScanDirection, 0);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Reset the position in the result set: ideally, this could be
|
||||||
|
* implemented by just skipping straight to the tuple # that we need
|
||||||
|
* to be at, but the tuplestore API doesn't support that. So we
|
||||||
|
* start at the beginning of the tuplestore and iterate through it
|
||||||
|
* until we reach where we need to be.
|
||||||
|
*/
|
||||||
|
if (!portal->atEnd)
|
||||||
|
{
|
||||||
|
int store_pos = 0;
|
||||||
|
bool should_free;
|
||||||
|
|
||||||
|
tuplestore_rescan(portal->holdStore);
|
||||||
|
|
||||||
|
while (store_pos < portal->portalPos)
|
||||||
|
{
|
||||||
|
HeapTuple tmp = tuplestore_gettuple(portal->holdStore,
|
||||||
|
true, &should_free);
|
||||||
|
|
||||||
|
if (tmp == NULL)
|
||||||
|
elog(ERROR,
|
||||||
|
"PersistHoldablePortal: unexpected end of tuple stream");
|
||||||
|
|
||||||
|
store_pos++;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This could probably be optimized by creating and then
|
||||||
|
* deleting a separate memory context for this series of
|
||||||
|
* operations.
|
||||||
|
*/
|
||||||
|
if (should_free)
|
||||||
|
pfree(tmp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The current Portal structure contains some data that will be
|
||||||
|
* needed by the holdable cursor, but it has been allocated in a
|
||||||
|
* memory context that is not sufficiently long-lived: we need to
|
||||||
|
* copy it into the portal's long-term memory context.
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
TupleDesc tupDescCopy;
|
||||||
|
QueryDesc *queryDescCopy;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We need to use this order as ExecutorEnd invalidates the
|
||||||
|
* queryDesc's tuple descriptor
|
||||||
|
*/
|
||||||
|
tupDescCopy = CreateTupleDescCopy(queryDesc->tupDesc);
|
||||||
|
|
||||||
|
ExecutorEnd(queryDesc);
|
||||||
|
|
||||||
|
queryDescCopy = palloc(sizeof(*queryDescCopy));
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This doesn't copy all the dependant data in the QueryDesc,
|
||||||
|
* but that's okay -- the only complex field we need to keep is
|
||||||
|
* the query's tupledesc, which we've copied ourselves.
|
||||||
|
*/
|
||||||
|
memcpy(queryDescCopy, queryDesc, sizeof(*queryDesc));
|
||||||
|
|
||||||
|
FreeQueryDesc(queryDesc);
|
||||||
|
|
||||||
|
queryDescCopy->tupDesc = tupDescCopy;
|
||||||
|
portal->queryDesc = queryDescCopy;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We no longer need the portal's short-term memory context.
|
||||||
|
*/
|
||||||
|
MemoryContextDelete(PortalGetHeapMemory(portal));
|
||||||
|
|
||||||
|
PortalGetHeapMemory(portal) = NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
# Makefile for executor
|
# Makefile for executor
|
||||||
#
|
#
|
||||||
# IDENTIFICATION
|
# IDENTIFICATION
|
||||||
# $Header: /cvsroot/pgsql/src/backend/executor/Makefile,v 1.20 2003/01/10 23:54:24 tgl Exp $
|
# $Header: /cvsroot/pgsql/src/backend/executor/Makefile,v 1.21 2003/03/27 16:51:27 momjian Exp $
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ OBJS = execAmi.o execGrouping.o execJunk.o execMain.o \
|
||||||
nodeHashjoin.o nodeIndexscan.o nodeMaterial.o nodeMergejoin.o \
|
nodeHashjoin.o nodeIndexscan.o nodeMaterial.o nodeMergejoin.o \
|
||||||
nodeNestloop.o nodeFunctionscan.o nodeResult.o nodeSeqscan.o \
|
nodeNestloop.o nodeFunctionscan.o nodeResult.o nodeSeqscan.o \
|
||||||
nodeSetOp.o nodeSort.o nodeUnique.o nodeLimit.o nodeGroup.o \
|
nodeSetOp.o nodeSort.o nodeUnique.o nodeLimit.o nodeGroup.o \
|
||||||
nodeSubplan.o nodeSubqueryscan.o nodeTidscan.o spi.o
|
nodeSubplan.o nodeSubqueryscan.o nodeTidscan.o tstoreReceiver.o spi.o
|
||||||
|
|
||||||
all: SUBSYS.o
|
all: SUBSYS.o
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.204 2003/03/27 14:33:11 tgl Exp $
|
* $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.205 2003/03/27 16:51:27 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
@ -217,8 +217,8 @@ ExecutorRun(QueryDesc *queryDesc,
|
||||||
estate->es_lastoid = InvalidOid;
|
estate->es_lastoid = InvalidOid;
|
||||||
|
|
||||||
destfunc = DestToFunction(dest);
|
destfunc = DestToFunction(dest);
|
||||||
(*destfunc->setup) (destfunc, (int) operation,
|
(*destfunc->setup) (destfunc, operation, queryDesc->portalName,
|
||||||
queryDesc->portalName, queryDesc->tupDesc);
|
queryDesc->tupDesc);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* run plan
|
* run plan
|
||||||
|
@ -421,15 +421,6 @@ ExecCheckRTEPerms(RangeTblEntry *rte, CmdType operation)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ===============================================================
|
|
||||||
* ===============================================================
|
|
||||||
static routines follow
|
|
||||||
* ===============================================================
|
|
||||||
* ===============================================================
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
ExecCheckXactReadOnly(Query *parsetree, CmdType operation)
|
ExecCheckXactReadOnly(Query *parsetree, CmdType operation)
|
||||||
{
|
{
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/executor/execQual.c,v 1.126 2003/03/09 02:19:13 tgl Exp $
|
* $Header: /cvsroot/pgsql/src/backend/executor/execQual.c,v 1.127 2003/03/27 16:51:27 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
@ -1054,8 +1054,7 @@ ExecMakeTableFunctionResult(ExprState *funcexpr,
|
||||||
0,
|
0,
|
||||||
false);
|
false);
|
||||||
}
|
}
|
||||||
tupstore = tuplestore_begin_heap(true, /* randomAccess */
|
tupstore = tuplestore_begin_heap(true, false, SortMem);
|
||||||
SortMem);
|
|
||||||
MemoryContextSwitchTo(oldcontext);
|
MemoryContextSwitchTo(oldcontext);
|
||||||
rsinfo.setResult = tupstore;
|
rsinfo.setResult = tupstore;
|
||||||
rsinfo.setDesc = tupdesc;
|
rsinfo.setDesc = tupdesc;
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/executor/nodeHash.c,v 1.74 2003/01/10 23:54:24 tgl Exp $
|
* $Header: /cvsroot/pgsql/src/backend/executor/nodeHash.c,v 1.75 2003/03/27 16:51:27 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
@ -64,7 +64,7 @@ ExecHash(HashState *node)
|
||||||
* buffers are palloc'd in regular executor context.
|
* buffers are palloc'd in regular executor context.
|
||||||
*/
|
*/
|
||||||
for (i = 0; i < nbatch; i++)
|
for (i = 0; i < nbatch; i++)
|
||||||
hashtable->innerBatchFile[i] = BufFileCreateTemp();
|
hashtable->innerBatchFile[i] = BufFileCreateTemp(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/executor/nodeHashjoin.c,v 1.48 2003/01/27 20:51:48 tgl Exp $
|
* $Header: /cvsroot/pgsql/src/backend/executor/nodeHashjoin.c,v 1.49 2003/03/27 16:51:27 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
@ -138,7 +138,7 @@ ExecHashJoin(HashJoinState *node)
|
||||||
* buffers are palloc'd in regular executor context.
|
* buffers are palloc'd in regular executor context.
|
||||||
*/
|
*/
|
||||||
for (i = 0; i < hashtable->nbatch; i++)
|
for (i = 0; i < hashtable->nbatch; i++)
|
||||||
hashtable->outerBatchFile[i] = BufFileCreateTemp();
|
hashtable->outerBatchFile[i] = BufFileCreateTemp(false);
|
||||||
}
|
}
|
||||||
else if (hashtable == NULL)
|
else if (hashtable == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/executor/nodeMaterial.c,v 1.41 2003/03/09 02:19:13 tgl Exp $
|
* $Header: /cvsroot/pgsql/src/backend/executor/nodeMaterial.c,v 1.42 2003/03/27 16:51:27 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
@ -62,8 +62,7 @@ ExecMaterial(MaterialState *node)
|
||||||
*/
|
*/
|
||||||
if (tuplestorestate == NULL)
|
if (tuplestorestate == NULL)
|
||||||
{
|
{
|
||||||
tuplestorestate = tuplestore_begin_heap(true, /* randomAccess */
|
tuplestorestate = tuplestore_begin_heap(true, false, SortMem);
|
||||||
SortMem);
|
|
||||||
|
|
||||||
node->tuplestorestate = (void *) tuplestorestate;
|
node->tuplestorestate = (void *) tuplestorestate;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/executor/spi.c,v 1.88 2003/03/11 19:40:22 tgl Exp $
|
* $Header: /cvsroot/pgsql/src/backend/executor/spi.c,v 1.89 2003/03/27 16:51:28 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
@ -866,7 +866,7 @@ SPI_cursor_close(Portal portal)
|
||||||
if (!PortalIsValid(portal))
|
if (!PortalIsValid(portal))
|
||||||
elog(ERROR, "invalid portal in SPI cursor operation");
|
elog(ERROR, "invalid portal in SPI cursor operation");
|
||||||
|
|
||||||
PortalDrop(portal);
|
PortalDrop(portal, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* =================== private functions =================== */
|
/* =================== private functions =================== */
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
|
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.265 2003/03/10 03:53:50 tgl Exp $
|
* $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.266 2003/03/27 16:51:28 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
@ -2294,6 +2294,13 @@ transformDeclareCursorStmt(ParseState *pstate, DeclareCursorStmt *stmt)
|
||||||
result->commandType = CMD_UTILITY;
|
result->commandType = CMD_UTILITY;
|
||||||
result->utilityStmt = (Node *) stmt;
|
result->utilityStmt = (Node *) stmt;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Don't allow both SCROLL and NO SCROLL to be specified
|
||||||
|
*/
|
||||||
|
if ((stmt->options & CURSOR_OPT_SCROLL) &&
|
||||||
|
(stmt->options & CURSOR_OPT_NO_SCROLL))
|
||||||
|
elog(ERROR, "Both SCROLL and NO SCROLL cannot be specified.");
|
||||||
|
|
||||||
stmt->query = (Node *) transformStmt(pstate, stmt->query,
|
stmt->query = (Node *) transformStmt(pstate, stmt->query,
|
||||||
&extras_before, &extras_after);
|
&extras_before, &extras_after);
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.408 2003/03/20 18:52:47 momjian Exp $
|
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.409 2003/03/27 16:51:28 momjian Exp $
|
||||||
*
|
*
|
||||||
* HISTORY
|
* HISTORY
|
||||||
* AUTHOR DATE MAJOR EVENT
|
* AUTHOR DATE MAJOR EVENT
|
||||||
|
@ -246,7 +246,7 @@ static void doNegateFloat(Value *v);
|
||||||
%type <boolean> opt_freeze opt_default opt_recheck
|
%type <boolean> opt_freeze opt_default opt_recheck
|
||||||
%type <defelt> opt_binary opt_oids copy_delimiter
|
%type <defelt> opt_binary opt_oids copy_delimiter
|
||||||
|
|
||||||
%type <boolean> copy_from
|
%type <boolean> copy_from opt_hold
|
||||||
|
|
||||||
%type <ival> reindex_type drop_type fetch_count
|
%type <ival> reindex_type drop_type fetch_count
|
||||||
opt_column event comment_type cursor_options
|
opt_column event comment_type cursor_options
|
||||||
|
@ -348,7 +348,7 @@ static void doNegateFloat(Value *v);
|
||||||
|
|
||||||
GLOBAL GRANT GROUP_P
|
GLOBAL GRANT GROUP_P
|
||||||
|
|
||||||
HANDLER HAVING HOUR_P
|
HANDLER HAVING HOLD HOUR_P
|
||||||
|
|
||||||
ILIKE IMMEDIATE IMMUTABLE IMPLICIT_P IN_P INCREMENT
|
ILIKE IMMEDIATE IMMUTABLE IMPLICIT_P IN_P INCREMENT
|
||||||
INDEX INHERITS INITIALLY INNER_P INOUT INPUT
|
INDEX INHERITS INITIALLY INNER_P INOUT INPUT
|
||||||
|
@ -4230,22 +4230,31 @@ UpdateStmt: UPDATE relation_expr
|
||||||
* CURSOR STATEMENTS
|
* CURSOR STATEMENTS
|
||||||
*
|
*
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
DeclareCursorStmt: DECLARE name cursor_options CURSOR FOR SelectStmt
|
DeclareCursorStmt: DECLARE name cursor_options CURSOR opt_hold FOR SelectStmt
|
||||||
{
|
{
|
||||||
DeclareCursorStmt *n = makeNode(DeclareCursorStmt);
|
DeclareCursorStmt *n = makeNode(DeclareCursorStmt);
|
||||||
n->portalname = $2;
|
n->portalname = $2;
|
||||||
n->options = $3;
|
n->options = $3;
|
||||||
n->query = $6;
|
n->query = $7;
|
||||||
|
|
||||||
|
if ($5)
|
||||||
|
n->options |= CURSOR_OPT_HOLD;
|
||||||
|
|
||||||
$$ = (Node *)n;
|
$$ = (Node *)n;
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
cursor_options: /*EMPTY*/ { $$ = 0; }
|
cursor_options: /*EMPTY*/ { $$ = 0; }
|
||||||
| cursor_options BINARY { $$ = $1 | CURSOR_OPT_BINARY; }
|
| cursor_options NO SCROLL { $$ = $1 | CURSOR_OPT_NO_SCROLL; }
|
||||||
| cursor_options SCROLL { $$ = $1 | CURSOR_OPT_SCROLL; }
|
| cursor_options SCROLL { $$ = $1 | CURSOR_OPT_SCROLL; }
|
||||||
|
| cursor_options BINARY { $$ = $1 | CURSOR_OPT_BINARY; }
|
||||||
| cursor_options INSENSITIVE { $$ = $1 | CURSOR_OPT_INSENSITIVE; }
|
| cursor_options INSENSITIVE { $$ = $1 | CURSOR_OPT_INSENSITIVE; }
|
||||||
;
|
;
|
||||||
|
|
||||||
|
opt_hold: /* EMPTY */ { $$ = FALSE; }
|
||||||
|
| WITH HOLD { $$ = TRUE; }
|
||||||
|
| WITHOUT HOLD { $$ = FALSE; }
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
*
|
*
|
||||||
* QUERY:
|
* QUERY:
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/parser/keywords.c,v 1.136 2003/03/20 07:02:10 momjian Exp $
|
* $Header: /cvsroot/pgsql/src/backend/parser/keywords.c,v 1.137 2003/03/27 16:51:28 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
@ -143,6 +143,7 @@ static const ScanKeyword ScanKeywords[] = {
|
||||||
{"group", GROUP_P},
|
{"group", GROUP_P},
|
||||||
{"handler", HANDLER},
|
{"handler", HANDLER},
|
||||||
{"having", HAVING},
|
{"having", HAVING},
|
||||||
|
{"hold", HOLD},
|
||||||
{"hour", HOUR_P},
|
{"hour", HOUR_P},
|
||||||
{"ilike", ILIKE},
|
{"ilike", ILIKE},
|
||||||
{"immediate", IMMEDIATE},
|
{"immediate", IMMEDIATE},
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/storage/file/buffile.c,v 1.14 2002/09/05 00:43:07 tgl Exp $
|
* $Header: /cvsroot/pgsql/src/backend/storage/file/buffile.c,v 1.15 2003/03/27 16:51:29 momjian Exp $
|
||||||
*
|
*
|
||||||
* NOTES:
|
* NOTES:
|
||||||
*
|
*
|
||||||
|
@ -64,6 +64,7 @@ struct BufFile
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool isTemp; /* can only add files if this is TRUE */
|
bool isTemp; /* can only add files if this is TRUE */
|
||||||
|
bool isInterTxn; /* keep open over transactions? */
|
||||||
bool dirty; /* does buffer need to be written? */
|
bool dirty; /* does buffer need to be written? */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -118,7 +119,7 @@ extendBufFile(BufFile *file)
|
||||||
File pfile;
|
File pfile;
|
||||||
|
|
||||||
Assert(file->isTemp);
|
Assert(file->isTemp);
|
||||||
pfile = OpenTemporaryFile();
|
pfile = OpenTemporaryFile(file->isInterTxn);
|
||||||
Assert(pfile >= 0);
|
Assert(pfile >= 0);
|
||||||
|
|
||||||
file->files = (File *) repalloc(file->files,
|
file->files = (File *) repalloc(file->files,
|
||||||
|
@ -136,16 +137,17 @@ extendBufFile(BufFile *file)
|
||||||
* written to it).
|
* written to it).
|
||||||
*/
|
*/
|
||||||
BufFile *
|
BufFile *
|
||||||
BufFileCreateTemp(void)
|
BufFileCreateTemp(bool interTxn)
|
||||||
{
|
{
|
||||||
BufFile *file;
|
BufFile *file;
|
||||||
File pfile;
|
File pfile;
|
||||||
|
|
||||||
pfile = OpenTemporaryFile();
|
pfile = OpenTemporaryFile(interTxn);
|
||||||
Assert(pfile >= 0);
|
Assert(pfile >= 0);
|
||||||
|
|
||||||
file = makeBufFile(pfile);
|
file = makeBufFile(pfile);
|
||||||
file->isTemp = true;
|
file->isTemp = true;
|
||||||
|
file->isInterTxn = interTxn;
|
||||||
|
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/storage/file/fd.c,v 1.95 2002/09/02 06:11:42 momjian Exp $
|
* $Header: /cvsroot/pgsql/src/backend/storage/file/fd.c,v 1.96 2003/03/27 16:51:29 momjian Exp $
|
||||||
*
|
*
|
||||||
* NOTES:
|
* NOTES:
|
||||||
*
|
*
|
||||||
|
@ -112,14 +112,14 @@ int max_files_per_process = 1000;
|
||||||
|
|
||||||
#define FileUnknownPos (-1L)
|
#define FileUnknownPos (-1L)
|
||||||
|
|
||||||
|
/* these are the assigned bits in fdstate below: */
|
||||||
|
#define FD_TEMPORARY (1 << 0)
|
||||||
|
#define FD_TXN_TEMPORARY (1 << 1)
|
||||||
|
|
||||||
typedef struct vfd
|
typedef struct vfd
|
||||||
{
|
{
|
||||||
signed short fd; /* current FD, or VFD_CLOSED if none */
|
signed short fd; /* current FD, or VFD_CLOSED if none */
|
||||||
unsigned short fdstate; /* bitflags for VFD's state */
|
unsigned short fdstate; /* bitflags for VFD's state */
|
||||||
|
|
||||||
/* these are the assigned bits in fdstate: */
|
|
||||||
#define FD_TEMPORARY (1 << 0) /* should be unlinked when closed */
|
|
||||||
|
|
||||||
File nextFree; /* link to next free VFD, if in freelist */
|
File nextFree; /* link to next free VFD, if in freelist */
|
||||||
File lruMoreRecently; /* doubly linked recency-of-use list */
|
File lruMoreRecently; /* doubly linked recency-of-use list */
|
||||||
File lruLessRecently;
|
File lruLessRecently;
|
||||||
|
@ -750,9 +750,15 @@ PathNameOpenFile(FileName fileName, int fileFlags, int fileMode)
|
||||||
* This routine takes care of generating an appropriate tempfile name.
|
* This routine takes care of generating an appropriate tempfile name.
|
||||||
* There's no need to pass in fileFlags or fileMode either, since only
|
* There's no need to pass in fileFlags or fileMode either, since only
|
||||||
* one setting makes any sense for a temp file.
|
* one setting makes any sense for a temp file.
|
||||||
|
*
|
||||||
|
* keepOverTxn: if true, don't close the file at end-of-transaction. In
|
||||||
|
* most cases, you don't want temporary files to outlive the transaction
|
||||||
|
* that created them, so this should be false -- but if you need
|
||||||
|
* "somewhat" temporary storage, this might be useful. In either case,
|
||||||
|
* the file is removed when the File is explicitely closed.
|
||||||
*/
|
*/
|
||||||
File
|
File
|
||||||
OpenTemporaryFile(void)
|
OpenTemporaryFile(bool keepOverTxn)
|
||||||
{
|
{
|
||||||
char tempfilepath[128];
|
char tempfilepath[128];
|
||||||
File file;
|
File file;
|
||||||
|
@ -795,9 +801,13 @@ OpenTemporaryFile(void)
|
||||||
elog(ERROR, "Failed to create temporary file %s", tempfilepath);
|
elog(ERROR, "Failed to create temporary file %s", tempfilepath);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Mark it for deletion at close or EOXact */
|
/* Mark it for deletion at close */
|
||||||
VfdCache[file].fdstate |= FD_TEMPORARY;
|
VfdCache[file].fdstate |= FD_TEMPORARY;
|
||||||
|
|
||||||
|
/* Mark it for deletion at EOXact */
|
||||||
|
if (!keepOverTxn)
|
||||||
|
VfdCache[file].fdstate |= FD_TXN_TEMPORARY;
|
||||||
|
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1114,6 +1124,7 @@ AtEOXact_Files(void)
|
||||||
for (i = 1; i < SizeVfdCache; i++)
|
for (i = 1; i < SizeVfdCache; i++)
|
||||||
{
|
{
|
||||||
if ((VfdCache[i].fdstate & FD_TEMPORARY) &&
|
if ((VfdCache[i].fdstate & FD_TEMPORARY) &&
|
||||||
|
(VfdCache[i].fdstate & FD_TXN_TEMPORARY) &&
|
||||||
VfdCache[i].fileName != NULL)
|
VfdCache[i].fileName != NULL)
|
||||||
FileClose(i);
|
FileClose(i);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/tcop/dest.c,v 1.50 2003/01/21 22:06:12 tgl Exp $
|
* $Header: /cvsroot/pgsql/src/backend/tcop/dest.c,v 1.51 2003/03/27 16:51:29 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
@ -29,6 +29,7 @@
|
||||||
#include "postgres.h"
|
#include "postgres.h"
|
||||||
|
|
||||||
#include "access/printtup.h"
|
#include "access/printtup.h"
|
||||||
|
#include "executor/tstoreReceiver.h"
|
||||||
#include "libpq/libpq.h"
|
#include "libpq/libpq.h"
|
||||||
#include "libpq/pqformat.h"
|
#include "libpq/pqformat.h"
|
||||||
|
|
||||||
|
@ -60,9 +61,11 @@ donothingCleanup(DestReceiver *self)
|
||||||
static DestReceiver donothingDR = {
|
static DestReceiver donothingDR = {
|
||||||
donothingReceive, donothingSetup, donothingCleanup
|
donothingReceive, donothingSetup, donothingCleanup
|
||||||
};
|
};
|
||||||
|
|
||||||
static DestReceiver debugtupDR = {
|
static DestReceiver debugtupDR = {
|
||||||
debugtup, debugSetup, donothingCleanup
|
debugtup, debugSetup, donothingCleanup
|
||||||
};
|
};
|
||||||
|
|
||||||
static DestReceiver spi_printtupDR = {
|
static DestReceiver spi_printtupDR = {
|
||||||
spi_printtup, spi_dest_setup, donothingCleanup
|
spi_printtup, spi_dest_setup, donothingCleanup
|
||||||
};
|
};
|
||||||
|
@ -98,6 +101,9 @@ DestToFunction(CommandDest dest)
|
||||||
case SPI:
|
case SPI:
|
||||||
return &spi_printtupDR;
|
return &spi_printtupDR;
|
||||||
|
|
||||||
|
case Tuplestore:
|
||||||
|
return tstoreReceiverCreateDR();
|
||||||
|
|
||||||
case None:
|
case None:
|
||||||
return &donothingDR;
|
return &donothingDR;
|
||||||
}
|
}
|
||||||
|
@ -122,6 +128,7 @@ EndCommand(const char *commandTag, CommandDest dest)
|
||||||
|
|
||||||
case None:
|
case None:
|
||||||
case Debug:
|
case Debug:
|
||||||
|
case Tuplestore:
|
||||||
case SPI:
|
case SPI:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -183,6 +190,7 @@ NullCommand(CommandDest dest)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Debug:
|
case Debug:
|
||||||
|
case Tuplestore:
|
||||||
case None:
|
case None:
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -213,6 +221,7 @@ ReadyForQuery(CommandDest dest)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Debug:
|
case Debug:
|
||||||
|
case Tuplestore:
|
||||||
case None:
|
case None:
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/utils/mmgr/mcxt.c,v 1.38 2002/12/16 16:22:46 tgl Exp $
|
* $Header: /cvsroot/pgsql/src/backend/utils/mmgr/mcxt.c,v 1.39 2003/03/27 16:51:29 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
@ -36,7 +36,8 @@
|
||||||
MemoryContext CurrentMemoryContext = NULL;
|
MemoryContext CurrentMemoryContext = NULL;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Standard top-level contexts
|
* Standard top-level contexts. For a description of the purpose of each
|
||||||
|
* of these contexts, refer to src/backend/utils/mmgr/README
|
||||||
*/
|
*/
|
||||||
MemoryContext TopMemoryContext = NULL;
|
MemoryContext TopMemoryContext = NULL;
|
||||||
MemoryContext ErrorContext = NULL;
|
MemoryContext ErrorContext = NULL;
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/utils/mmgr/portalmem.c,v 1.53 2003/03/11 19:40:23 tgl Exp $
|
* $Header: /cvsroot/pgsql/src/backend/utils/mmgr/portalmem.c,v 1.54 2003/03/27 16:51:29 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
@ -20,8 +20,8 @@
|
||||||
* "PortalData" structure, plans the query and then stores the query
|
* "PortalData" structure, plans the query and then stores the query
|
||||||
* in the portal without executing it. Later, when the backend
|
* in the portal without executing it. Later, when the backend
|
||||||
* sees a
|
* sees a
|
||||||
* fetch 1 from FOO
|
* fetch 1 from foo
|
||||||
* the system looks up the portal named "FOO" in the portal table,
|
* the system looks up the portal named "foo" in the portal table,
|
||||||
* gets the planned query and then calls the executor with a count
|
* gets the planned query and then calls the executor with a count
|
||||||
* of 1. The executor then runs the query and returns a single
|
* of 1. The executor then runs the query and returns a single
|
||||||
* tuple. The problem is that we have to hold onto the state of the
|
* tuple. The problem is that we have to hold onto the state of the
|
||||||
|
@ -38,7 +38,6 @@
|
||||||
#include "utils/memutils.h"
|
#include "utils/memutils.h"
|
||||||
#include "utils/portal.h"
|
#include "utils/portal.h"
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* estimate of the maximum number of open portals a user would have,
|
* estimate of the maximum number of open portals a user would have,
|
||||||
* used in initially sizing the PortalHashTable in EnablePortalManager()
|
* used in initially sizing the PortalHashTable in EnablePortalManager()
|
||||||
|
@ -131,8 +130,8 @@ EnablePortalManager(void)
|
||||||
ctl.entrysize = sizeof(PortalHashEnt);
|
ctl.entrysize = sizeof(PortalHashEnt);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* use PORTALS_PER_USER, defined in utils/portal.h as a guess of how
|
* use PORTALS_PER_USER as a guess of how many hash table entries to
|
||||||
* many hash table entries to create, initially
|
* create, initially
|
||||||
*/
|
*/
|
||||||
PortalHashTable = hash_create("Portal hash", PORTALS_PER_USER,
|
PortalHashTable = hash_create("Portal hash", PORTALS_PER_USER,
|
||||||
&ctl, HASH_ELEM);
|
&ctl, HASH_ELEM);
|
||||||
|
@ -157,7 +156,9 @@ GetPortalByName(const char *name)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* PortalSetQuery
|
* PortalSetQuery
|
||||||
* Attaches a "query" to portal.
|
* Attaches a "query" to the specified portal. Note that in the
|
||||||
|
* case of DECLARE CURSOR, some Portal options have already been
|
||||||
|
* set based upon the parsetree of the original DECLARE statement.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
PortalSetQuery(Portal portal,
|
PortalSetQuery(Portal portal,
|
||||||
|
@ -166,9 +167,25 @@ PortalSetQuery(Portal portal,
|
||||||
{
|
{
|
||||||
AssertArg(PortalIsValid(portal));
|
AssertArg(PortalIsValid(portal));
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If the user didn't specify a SCROLL type, allow or disallow
|
||||||
|
* scrolling based on whether it would require any additional
|
||||||
|
* runtime overhead to do so.
|
||||||
|
*/
|
||||||
|
if (portal->scrollType == DEFAULT_SCROLL)
|
||||||
|
{
|
||||||
|
bool backwardPlan;
|
||||||
|
|
||||||
|
backwardPlan = ExecSupportsBackwardScan(queryDesc->plantree);
|
||||||
|
|
||||||
|
if (backwardPlan)
|
||||||
|
portal->scrollType = ENABLE_SCROLL;
|
||||||
|
else
|
||||||
|
portal->scrollType = DISABLE_SCROLL;
|
||||||
|
}
|
||||||
|
|
||||||
portal->queryDesc = queryDesc;
|
portal->queryDesc = queryDesc;
|
||||||
portal->cleanup = cleanup;
|
portal->cleanup = cleanup;
|
||||||
portal->backwardOK = ExecSupportsBackwardScan(queryDesc->plantree);
|
|
||||||
portal->atStart = true;
|
portal->atStart = true;
|
||||||
portal->atEnd = false; /* allow fetches */
|
portal->atEnd = false; /* allow fetches */
|
||||||
portal->portalPos = 0;
|
portal->portalPos = 0;
|
||||||
|
@ -179,10 +196,8 @@ PortalSetQuery(Portal portal,
|
||||||
* CreatePortal
|
* CreatePortal
|
||||||
* Returns a new portal given a name.
|
* Returns a new portal given a name.
|
||||||
*
|
*
|
||||||
* Exceptions:
|
* An elog(WARNING) is emitted if portal name is in use (existing
|
||||||
* BadState if called when disabled.
|
* portal is returned!)
|
||||||
* BadArg if portal name is invalid.
|
|
||||||
* "WARNING" if portal name is in use (existing portal is returned!)
|
|
||||||
*/
|
*/
|
||||||
Portal
|
Portal
|
||||||
CreatePortal(const char *name)
|
CreatePortal(const char *name)
|
||||||
|
@ -214,7 +229,11 @@ CreatePortal(const char *name)
|
||||||
/* initialize portal query */
|
/* initialize portal query */
|
||||||
portal->queryDesc = NULL;
|
portal->queryDesc = NULL;
|
||||||
portal->cleanup = NULL;
|
portal->cleanup = NULL;
|
||||||
portal->backwardOK = false;
|
portal->scrollType = DEFAULT_SCROLL;
|
||||||
|
portal->holdOpen = false;
|
||||||
|
portal->holdStore = NULL;
|
||||||
|
portal->holdContext = NULL;
|
||||||
|
portal->createXact = GetCurrentTransactionId();
|
||||||
portal->atStart = true;
|
portal->atStart = true;
|
||||||
portal->atEnd = true; /* disallow fetches until query is set */
|
portal->atEnd = true; /* disallow fetches until query is set */
|
||||||
portal->portalPos = 0;
|
portal->portalPos = 0;
|
||||||
|
@ -228,17 +247,47 @@ CreatePortal(const char *name)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* PortalDrop
|
* PortalDrop
|
||||||
* Destroys portal.
|
* Destroy the portal.
|
||||||
*
|
*
|
||||||
* Exceptions:
|
* keepHoldable: if true, holdable portals should not be removed by
|
||||||
* BadState if called when disabled.
|
* this function. More specifically, invoking this function with
|
||||||
* BadArg if portal is invalid.
|
* keepHoldable = true on a holdable portal prepares the portal for
|
||||||
|
* access outside of its creating transaction.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
PortalDrop(Portal portal)
|
PortalDrop(Portal portal, bool persistHoldable)
|
||||||
{
|
{
|
||||||
AssertArg(PortalIsValid(portal));
|
AssertArg(PortalIsValid(portal));
|
||||||
|
|
||||||
|
if (portal->holdOpen && persistHoldable)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* We're "dropping" a holdable portal, but what we really need
|
||||||
|
* to do is prepare the portal for access outside of its
|
||||||
|
* creating transaction.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Create the memory context that is used for storage of
|
||||||
|
* long-term (cross transaction) data needed by the holdable
|
||||||
|
* portal.
|
||||||
|
*/
|
||||||
|
portal->holdContext =
|
||||||
|
AllocSetContextCreate(PortalMemory,
|
||||||
|
"PortalHeapMemory",
|
||||||
|
ALLOCSET_DEFAULT_MINSIZE,
|
||||||
|
ALLOCSET_DEFAULT_INITSIZE,
|
||||||
|
ALLOCSET_DEFAULT_MAXSIZE);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Note that PersistHoldablePortal() releases any resources used
|
||||||
|
* by the portal that are local to the creating txn.
|
||||||
|
*/
|
||||||
|
PersistHoldablePortal(portal);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* remove portal from hash table */
|
/* remove portal from hash table */
|
||||||
PortalHashTableDelete(portal);
|
PortalHashTableDelete(portal);
|
||||||
|
|
||||||
|
@ -246,8 +295,20 @@ PortalDrop(Portal portal)
|
||||||
if (PointerIsValid(portal->cleanup))
|
if (PointerIsValid(portal->cleanup))
|
||||||
(*portal->cleanup) (portal);
|
(*portal->cleanup) (portal);
|
||||||
|
|
||||||
/* release subsidiary storage */
|
/*
|
||||||
MemoryContextDelete(PortalGetHeapMemory(portal));
|
* delete short-term memory context; in the case of a holdable
|
||||||
|
* portal, this has already been done
|
||||||
|
*/
|
||||||
|
if (PortalGetHeapMemory(portal))
|
||||||
|
MemoryContextDelete(PortalGetHeapMemory(portal));
|
||||||
|
|
||||||
|
/*
|
||||||
|
* delete long-term memory context; in the case of a non-holdable
|
||||||
|
* portal, this context has never been created, so we don't need to
|
||||||
|
* do anything
|
||||||
|
*/
|
||||||
|
if (portal->holdContext)
|
||||||
|
MemoryContextDelete(portal->holdContext);
|
||||||
|
|
||||||
/* release name and portal data (both are in PortalMemory) */
|
/* release name and portal data (both are in PortalMemory) */
|
||||||
pfree(portal->name);
|
pfree(portal->name);
|
||||||
|
@ -255,7 +316,12 @@ PortalDrop(Portal portal)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Destroy all portals created in the current transaction (ie, all of them).
|
* Cleanup the portals created in the current transaction. If the
|
||||||
|
* transaction was aborted, all the portals created in this transaction
|
||||||
|
* should be removed. If the transaction was successfully committed, any
|
||||||
|
* holdable cursors created in this transaction need to be kept
|
||||||
|
* open. Only cursors created in the current transaction should be
|
||||||
|
* removed in this fashion.
|
||||||
*
|
*
|
||||||
* XXX This assumes that portals can be deleted in a random order, ie,
|
* XXX This assumes that portals can be deleted in a random order, ie,
|
||||||
* no portal has a reference to any other (at least not one that will be
|
* no portal has a reference to any other (at least not one that will be
|
||||||
|
@ -264,13 +330,17 @@ PortalDrop(Portal portal)
|
||||||
* references...
|
* references...
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
AtEOXact_portals(void)
|
AtEOXact_portals(bool isCommit)
|
||||||
{
|
{
|
||||||
HASH_SEQ_STATUS status;
|
HASH_SEQ_STATUS status;
|
||||||
PortalHashEnt *hentry;
|
PortalHashEnt *hentry;
|
||||||
|
TransactionId xact = GetCurrentTransactionId();
|
||||||
|
|
||||||
hash_seq_init(&status, PortalHashTable);
|
hash_seq_init(&status, PortalHashTable);
|
||||||
|
|
||||||
while ((hentry = (PortalHashEnt *) hash_seq_search(&status)) != NULL)
|
while ((hentry = (PortalHashEnt *) hash_seq_search(&status)) != NULL)
|
||||||
PortalDrop(hentry->portal);
|
{
|
||||||
|
if (hentry->portal->createXact == xact)
|
||||||
|
PortalDrop(hentry->portal, isCommit);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,7 @@
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/utils/sort/logtape.c,v 1.8 2002/06/20 20:29:40 momjian Exp $
|
* $Header: /cvsroot/pgsql/src/backend/utils/sort/logtape.c,v 1.9 2003/03/27 16:51:29 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
@ -470,7 +470,7 @@ LogicalTapeSetCreate(int ntapes)
|
||||||
Assert(ntapes > 0);
|
Assert(ntapes > 0);
|
||||||
lts = (LogicalTapeSet *) palloc(sizeof(LogicalTapeSet) +
|
lts = (LogicalTapeSet *) palloc(sizeof(LogicalTapeSet) +
|
||||||
(ntapes - 1) *sizeof(LogicalTape *));
|
(ntapes - 1) *sizeof(LogicalTape *));
|
||||||
lts->pfile = BufFileCreateTemp();
|
lts->pfile = BufFileCreateTemp(false);
|
||||||
lts->nFileBlocks = 0L;
|
lts->nFileBlocks = 0L;
|
||||||
lts->freeBlocksLen = 32; /* reasonable initial guess */
|
lts->freeBlocksLen = 32; /* reasonable initial guess */
|
||||||
lts->freeBlocks = (long *) palloc(lts->freeBlocksLen * sizeof(long));
|
lts->freeBlocks = (long *) palloc(lts->freeBlocksLen * sizeof(long));
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/utils/sort/tuplestore.c,v 1.11 2003/03/09 02:19:13 tgl Exp $
|
* $Header: /cvsroot/pgsql/src/backend/utils/sort/tuplestore.c,v 1.12 2003/03/27 16:51:29 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
@ -65,6 +65,7 @@ struct Tuplestorestate
|
||||||
{
|
{
|
||||||
TupStoreStatus status; /* enumerated value as shown above */
|
TupStoreStatus status; /* enumerated value as shown above */
|
||||||
bool randomAccess; /* did caller request random access? */
|
bool randomAccess; /* did caller request random access? */
|
||||||
|
bool interTxn; /* keep open through transactions? */
|
||||||
long availMem; /* remaining memory available, in bytes */
|
long availMem; /* remaining memory available, in bytes */
|
||||||
BufFile *myfile; /* underlying file, or NULL if none */
|
BufFile *myfile; /* underlying file, or NULL if none */
|
||||||
|
|
||||||
|
@ -190,7 +191,8 @@ struct Tuplestorestate
|
||||||
|
|
||||||
|
|
||||||
static Tuplestorestate *tuplestore_begin_common(bool randomAccess,
|
static Tuplestorestate *tuplestore_begin_common(bool randomAccess,
|
||||||
int maxKBytes);
|
bool interTxn,
|
||||||
|
int maxKBytes);
|
||||||
static void dumptuples(Tuplestorestate *state);
|
static void dumptuples(Tuplestorestate *state);
|
||||||
static unsigned int getlen(Tuplestorestate *state, bool eofOK);
|
static unsigned int getlen(Tuplestorestate *state, bool eofOK);
|
||||||
static void *copytup_heap(Tuplestorestate *state, void *tup);
|
static void *copytup_heap(Tuplestorestate *state, void *tup);
|
||||||
|
@ -205,7 +207,7 @@ static void *readtup_heap(Tuplestorestate *state, unsigned int len);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static Tuplestorestate *
|
static Tuplestorestate *
|
||||||
tuplestore_begin_common(bool randomAccess, int maxKBytes)
|
tuplestore_begin_common(bool randomAccess, bool interTxn, int maxKBytes)
|
||||||
{
|
{
|
||||||
Tuplestorestate *state;
|
Tuplestorestate *state;
|
||||||
|
|
||||||
|
@ -213,6 +215,7 @@ tuplestore_begin_common(bool randomAccess, int maxKBytes)
|
||||||
|
|
||||||
state->status = TSS_INMEM;
|
state->status = TSS_INMEM;
|
||||||
state->randomAccess = randomAccess;
|
state->randomAccess = randomAccess;
|
||||||
|
state->interTxn = interTxn;
|
||||||
state->availMem = maxKBytes * 1024L;
|
state->availMem = maxKBytes * 1024L;
|
||||||
state->myfile = NULL;
|
state->myfile = NULL;
|
||||||
|
|
||||||
|
@ -231,10 +234,27 @@ tuplestore_begin_common(bool randomAccess, int maxKBytes)
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* tuplestore_begin_heap
|
||||||
|
*
|
||||||
|
* Create a new tuplestore; other types of tuple stores (other than
|
||||||
|
* "heap" tuple stores, for heap tuples) are possible, but not presently
|
||||||
|
* implemented.
|
||||||
|
*
|
||||||
|
* randomAccess: if true, both forward and backward accesses to the
|
||||||
|
* tuple store are allowed.
|
||||||
|
*
|
||||||
|
* interTxn: if true, the files used by on-disk storage persist beyond
|
||||||
|
* the end of the current transaction.
|
||||||
|
*
|
||||||
|
* maxKBytes: how much data to store in memory (any data beyond this
|
||||||
|
* amount is paged to disk).
|
||||||
|
*/
|
||||||
Tuplestorestate *
|
Tuplestorestate *
|
||||||
tuplestore_begin_heap(bool randomAccess, int maxKBytes)
|
tuplestore_begin_heap(bool randomAccess, bool interTxn, int maxKBytes)
|
||||||
{
|
{
|
||||||
Tuplestorestate *state = tuplestore_begin_common(randomAccess, maxKBytes);
|
Tuplestorestate *state = tuplestore_begin_common(randomAccess,
|
||||||
|
interTxn, maxKBytes);
|
||||||
|
|
||||||
state->copytup = copytup_heap;
|
state->copytup = copytup_heap;
|
||||||
state->writetup = writetup_heap;
|
state->writetup = writetup_heap;
|
||||||
|
@ -321,7 +341,7 @@ tuplestore_puttuple(Tuplestorestate *state, void *tuple)
|
||||||
/*
|
/*
|
||||||
* Nope; time to switch to tape-based operation.
|
* Nope; time to switch to tape-based operation.
|
||||||
*/
|
*/
|
||||||
state->myfile = BufFileCreateTemp();
|
state->myfile = BufFileCreateTemp(state->interTxn);
|
||||||
state->status = TSS_WRITEFILE;
|
state->status = TSS_WRITEFILE;
|
||||||
dumptuples(state);
|
dumptuples(state);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
|
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $Id: parsenodes.h,v 1.235 2003/03/20 18:52:48 momjian Exp $
|
* $Id: parsenodes.h,v 1.236 2003/03/27 16:51:29 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
@ -1210,7 +1210,9 @@ typedef struct CommentStmt
|
||||||
*/
|
*/
|
||||||
#define CURSOR_OPT_BINARY 0x0001
|
#define CURSOR_OPT_BINARY 0x0001
|
||||||
#define CURSOR_OPT_SCROLL 0x0002
|
#define CURSOR_OPT_SCROLL 0x0002
|
||||||
#define CURSOR_OPT_INSENSITIVE 0x0004
|
#define CURSOR_OPT_NO_SCROLL 0x0004
|
||||||
|
#define CURSOR_OPT_INSENSITIVE 0x0008
|
||||||
|
#define CURSOR_OPT_HOLD 0x0010
|
||||||
|
|
||||||
typedef struct DeclareCursorStmt
|
typedef struct DeclareCursorStmt
|
||||||
{
|
{
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
|
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $Id: buffile.h,v 1.12 2002/06/20 20:29:52 momjian Exp $
|
* $Id: buffile.h,v 1.13 2003/03/27 16:51:29 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
@ -34,7 +34,7 @@ typedef struct BufFile BufFile;
|
||||||
* prototypes for functions in buffile.c
|
* prototypes for functions in buffile.c
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern BufFile *BufFileCreateTemp(void);
|
extern BufFile *BufFileCreateTemp(bool interTxn);
|
||||||
extern void BufFileClose(BufFile *file);
|
extern void BufFileClose(BufFile *file);
|
||||||
extern size_t BufFileRead(BufFile *file, void *ptr, size_t size);
|
extern size_t BufFileRead(BufFile *file, void *ptr, size_t size);
|
||||||
extern size_t BufFileWrite(BufFile *file, void *ptr, size_t size);
|
extern size_t BufFileWrite(BufFile *file, void *ptr, size_t size);
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
|
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $Id: fd.h,v 1.36 2002/08/06 02:36:35 tgl Exp $
|
* $Id: fd.h,v 1.37 2003/03/27 16:51:29 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
@ -55,7 +55,7 @@ extern int max_files_per_process;
|
||||||
/* Operations on virtual Files --- equivalent to Unix kernel file ops */
|
/* Operations on virtual Files --- equivalent to Unix kernel file ops */
|
||||||
extern File FileNameOpenFile(FileName fileName, int fileFlags, int fileMode);
|
extern File FileNameOpenFile(FileName fileName, int fileFlags, int fileMode);
|
||||||
extern File PathNameOpenFile(FileName fileName, int fileFlags, int fileMode);
|
extern File PathNameOpenFile(FileName fileName, int fileFlags, int fileMode);
|
||||||
extern File OpenTemporaryFile(void);
|
extern File OpenTemporaryFile(bool keepOverTxn);
|
||||||
extern void FileClose(File file);
|
extern void FileClose(File file);
|
||||||
extern void FileUnlink(File file);
|
extern void FileUnlink(File file);
|
||||||
extern int FileRead(File file, char *buffer, int amount);
|
extern int FileRead(File file, char *buffer, int amount);
|
||||||
|
|
|
@ -44,7 +44,7 @@
|
||||||
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
|
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $Id: dest.h,v 1.32 2002/09/04 20:31:45 momjian Exp $
|
* $Id: dest.h,v 1.33 2003/03/27 16:51:29 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
@ -70,7 +70,8 @@ typedef enum
|
||||||
Remote, /* results sent to frontend process */
|
Remote, /* results sent to frontend process */
|
||||||
RemoteInternal, /* results sent to frontend process in
|
RemoteInternal, /* results sent to frontend process in
|
||||||
* internal (binary) form */
|
* internal (binary) form */
|
||||||
SPI /* results sent to SPI manager */
|
SPI, /* results sent to SPI manager */
|
||||||
|
Tuplestore /* results sent to Tuplestore */
|
||||||
} CommandDest;
|
} CommandDest;
|
||||||
|
|
||||||
/* ----------------
|
/* ----------------
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
|
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $Id: portal.h,v 1.39 2003/03/11 19:40:24 tgl Exp $
|
* $Id: portal.h,v 1.40 2003/03/27 16:51:29 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
@ -18,17 +18,45 @@
|
||||||
|
|
||||||
#include "executor/execdesc.h"
|
#include "executor/execdesc.h"
|
||||||
#include "nodes/memnodes.h"
|
#include "nodes/memnodes.h"
|
||||||
|
#include "utils/tuplestore.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We support three kinds of scroll behavior:
|
||||||
|
*
|
||||||
|
* (1) Neither NO SCROLL nor SCROLL was specified: to remain backward
|
||||||
|
* compatible, we allow backward fetches here, unless it would
|
||||||
|
* impose additional runtime overhead to do so.
|
||||||
|
*
|
||||||
|
* (2) NO SCROLL was specified: don't allow any backward fetches.
|
||||||
|
*
|
||||||
|
* (3) SCROLL was specified: allow all kinds of backward fetches, even
|
||||||
|
* if we need to take a slight performance hit to do so.
|
||||||
|
*
|
||||||
|
* Case #1 is converted to #2 or #3 by looking at the query itself and
|
||||||
|
* determining if scrollability can be supported without additional
|
||||||
|
* overhead.
|
||||||
|
*/
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
DEFAULT_SCROLL,
|
||||||
|
DISABLE_SCROLL,
|
||||||
|
ENABLE_SCROLL
|
||||||
|
} ScrollType;
|
||||||
|
|
||||||
typedef struct PortalData *Portal;
|
typedef struct PortalData *Portal;
|
||||||
|
|
||||||
typedef struct PortalData
|
typedef struct PortalData
|
||||||
{
|
{
|
||||||
char *name; /* Portal's name */
|
char *name; /* Portal's name */
|
||||||
MemoryContext heap; /* subsidiary memory */
|
MemoryContext heap; /* memory for storing short-term data */
|
||||||
QueryDesc *queryDesc; /* Info about query associated with portal */
|
QueryDesc *queryDesc; /* Info about query associated with portal */
|
||||||
void (*cleanup) (Portal); /* Cleanup routine (optional) */
|
void (*cleanup) (Portal); /* Cleanup routine (optional) */
|
||||||
bool backwardOK; /* is fetch backwards allowed? */
|
ScrollType scrollType; /* Allow backward fetches? */
|
||||||
|
bool holdOpen; /* hold open after txn ends? */
|
||||||
|
TransactionId createXact; /* the xid of the creating txn */
|
||||||
|
Tuplestorestate *holdStore; /* store for holdable cursors */
|
||||||
|
MemoryContext holdContext; /* memory for long-term data */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* atStart, atEnd and portalPos indicate the current cursor position.
|
* atStart, atEnd and portalPos indicate the current cursor position.
|
||||||
* portalPos is zero before the first row, N after fetching N'th row of
|
* portalPos is zero before the first row, N after fetching N'th row of
|
||||||
|
@ -58,11 +86,12 @@ typedef struct PortalData
|
||||||
|
|
||||||
|
|
||||||
extern void EnablePortalManager(void);
|
extern void EnablePortalManager(void);
|
||||||
extern void AtEOXact_portals(void);
|
extern void AtEOXact_portals(bool isCommit);
|
||||||
extern Portal CreatePortal(const char *name);
|
extern Portal CreatePortal(const char *name);
|
||||||
extern void PortalDrop(Portal portal);
|
extern void PortalDrop(Portal portal, bool persistHoldable);
|
||||||
extern Portal GetPortalByName(const char *name);
|
extern Portal GetPortalByName(const char *name);
|
||||||
extern void PortalSetQuery(Portal portal, QueryDesc *queryDesc,
|
extern void PortalSetQuery(Portal portal, QueryDesc *queryDesc,
|
||||||
void (*cleanup) (Portal portal));
|
void (*cleanup) (Portal portal));
|
||||||
|
extern void PersistHoldablePortal(Portal portal);
|
||||||
|
|
||||||
#endif /* PORTAL_H */
|
#endif /* PORTAL_H */
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
|
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $Id: tuplestore.h,v 1.9 2003/03/09 03:34:10 tgl Exp $
|
* $Id: tuplestore.h,v 1.10 2003/03/27 16:51:29 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
@ -37,7 +37,8 @@ typedef struct Tuplestorestate Tuplestorestate;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern Tuplestorestate *tuplestore_begin_heap(bool randomAccess,
|
extern Tuplestorestate *tuplestore_begin_heap(bool randomAccess,
|
||||||
int maxKBytes);
|
bool interTxn,
|
||||||
|
int maxKBytes);
|
||||||
|
|
||||||
extern void tuplestore_puttuple(Tuplestorestate *state, void *tuple);
|
extern void tuplestore_puttuple(Tuplestorestate *state, void *tuple);
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
* procedural language
|
* procedural language
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.83 2003/03/25 03:16:40 tgl Exp $
|
* $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.84 2003/03/27 16:51:29 momjian Exp $
|
||||||
*
|
*
|
||||||
* This software is copyrighted by Jan Wieck - Hamburg.
|
* This software is copyrighted by Jan Wieck - Hamburg.
|
||||||
*
|
*
|
||||||
|
@ -1757,7 +1757,7 @@ exec_init_tuple_store(PLpgSQL_execstate * estate)
|
||||||
estate->tuple_store_cxt = rsi->econtext->ecxt_per_query_memory;
|
estate->tuple_store_cxt = rsi->econtext->ecxt_per_query_memory;
|
||||||
|
|
||||||
oldcxt = MemoryContextSwitchTo(estate->tuple_store_cxt);
|
oldcxt = MemoryContextSwitchTo(estate->tuple_store_cxt);
|
||||||
estate->tuple_store = tuplestore_begin_heap(true, SortMem);
|
estate->tuple_store = tuplestore_begin_heap(true, false, SortMem);
|
||||||
MemoryContextSwitchTo(oldcxt);
|
MemoryContextSwitchTo(oldcxt);
|
||||||
|
|
||||||
estate->rettupdesc = rsi->expectedDesc;
|
estate->rettupdesc = rsi->expectedDesc;
|
||||||
|
|
|
@ -1,30 +1,30 @@
|
||||||
--
|
--
|
||||||
-- PORTALS
|
-- Cursor regression tests
|
||||||
--
|
--
|
||||||
BEGIN;
|
BEGIN;
|
||||||
DECLARE foo1 CURSOR FOR SELECT * FROM tenk1;
|
DECLARE foo1 SCROLL CURSOR FOR SELECT * FROM tenk1;
|
||||||
DECLARE foo2 CURSOR FOR SELECT * FROM tenk2;
|
DECLARE foo2 SCROLL CURSOR FOR SELECT * FROM tenk2;
|
||||||
DECLARE foo3 CURSOR FOR SELECT * FROM tenk1;
|
DECLARE foo3 SCROLL CURSOR FOR SELECT * FROM tenk1;
|
||||||
DECLARE foo4 CURSOR FOR SELECT * FROM tenk2;
|
DECLARE foo4 SCROLL CURSOR FOR SELECT * FROM tenk2;
|
||||||
DECLARE foo5 CURSOR FOR SELECT * FROM tenk1;
|
DECLARE foo5 SCROLL CURSOR FOR SELECT * FROM tenk1;
|
||||||
DECLARE foo6 CURSOR FOR SELECT * FROM tenk2;
|
DECLARE foo6 SCROLL CURSOR FOR SELECT * FROM tenk2;
|
||||||
DECLARE foo7 CURSOR FOR SELECT * FROM tenk1;
|
DECLARE foo7 SCROLL CURSOR FOR SELECT * FROM tenk1;
|
||||||
DECLARE foo8 CURSOR FOR SELECT * FROM tenk2;
|
DECLARE foo8 SCROLL CURSOR FOR SELECT * FROM tenk2;
|
||||||
DECLARE foo9 CURSOR FOR SELECT * FROM tenk1;
|
DECLARE foo9 SCROLL CURSOR FOR SELECT * FROM tenk1;
|
||||||
DECLARE foo10 CURSOR FOR SELECT * FROM tenk2;
|
DECLARE foo10 SCROLL CURSOR FOR SELECT * FROM tenk2;
|
||||||
DECLARE foo11 CURSOR FOR SELECT * FROM tenk1;
|
DECLARE foo11 SCROLL CURSOR FOR SELECT * FROM tenk1;
|
||||||
DECLARE foo12 CURSOR FOR SELECT * FROM tenk2;
|
DECLARE foo12 SCROLL CURSOR FOR SELECT * FROM tenk2;
|
||||||
DECLARE foo13 CURSOR FOR SELECT * FROM tenk1;
|
DECLARE foo13 SCROLL CURSOR FOR SELECT * FROM tenk1;
|
||||||
DECLARE foo14 CURSOR FOR SELECT * FROM tenk2;
|
DECLARE foo14 SCROLL CURSOR FOR SELECT * FROM tenk2;
|
||||||
DECLARE foo15 CURSOR FOR SELECT * FROM tenk1;
|
DECLARE foo15 SCROLL CURSOR FOR SELECT * FROM tenk1;
|
||||||
DECLARE foo16 CURSOR FOR SELECT * FROM tenk2;
|
DECLARE foo16 SCROLL CURSOR FOR SELECT * FROM tenk2;
|
||||||
DECLARE foo17 CURSOR FOR SELECT * FROM tenk1;
|
DECLARE foo17 SCROLL CURSOR FOR SELECT * FROM tenk1;
|
||||||
DECLARE foo18 CURSOR FOR SELECT * FROM tenk2;
|
DECLARE foo18 SCROLL CURSOR FOR SELECT * FROM tenk2;
|
||||||
DECLARE foo19 CURSOR FOR SELECT * FROM tenk1;
|
DECLARE foo19 SCROLL CURSOR FOR SELECT * FROM tenk1;
|
||||||
DECLARE foo20 CURSOR FOR SELECT * FROM tenk2;
|
DECLARE foo20 SCROLL CURSOR FOR SELECT * FROM tenk2;
|
||||||
DECLARE foo21 CURSOR FOR SELECT * FROM tenk1;
|
DECLARE foo21 SCROLL CURSOR FOR SELECT * FROM tenk1;
|
||||||
DECLARE foo22 CURSOR FOR SELECT * FROM tenk2;
|
DECLARE foo22 SCROLL CURSOR FOR SELECT * FROM tenk2;
|
||||||
DECLARE foo23 CURSOR FOR SELECT * FROM tenk1;
|
DECLARE foo23 SCROLL CURSOR FOR SELECT * FROM tenk1;
|
||||||
FETCH 1 in foo1;
|
FETCH 1 in foo1;
|
||||||
unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4
|
unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4
|
||||||
---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
|
---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
|
||||||
|
@ -675,4 +675,66 @@ CLOSE foo9;
|
||||||
CLOSE foo10;
|
CLOSE foo10;
|
||||||
CLOSE foo11;
|
CLOSE foo11;
|
||||||
CLOSE foo12;
|
CLOSE foo12;
|
||||||
end;
|
-- is there a reason why we don't close the rest of the open cursors?
|
||||||
|
END;
|
||||||
|
--
|
||||||
|
-- NO SCROLL disallows backward fetching
|
||||||
|
--
|
||||||
|
BEGIN;
|
||||||
|
DECLARE foo24 NO SCROLL CURSOR FOR SELECT * FROM tenk1;
|
||||||
|
FETCH 1 FROM foo24;
|
||||||
|
unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4
|
||||||
|
---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
|
||||||
|
8800 | 0 | 0 | 0 | 0 | 0 | 0 | 800 | 800 | 3800 | 8800 | 0 | 1 | MAAAAA | AAAAAA | AAAAxx
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
FETCH BACKWARD 1 FROM foo24; -- should fail
|
||||||
|
ERROR: Cursor can only scan forward
|
||||||
|
Declare it with SCROLL option to enable backward scan
|
||||||
|
END;
|
||||||
|
--
|
||||||
|
-- Cursors outside transaction blocks
|
||||||
|
--
|
||||||
|
BEGIN;
|
||||||
|
DECLARE foo25 SCROLL CURSOR WITH HOLD FOR SELECT * FROM tenk2;
|
||||||
|
FETCH FROM foo25;
|
||||||
|
unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4
|
||||||
|
---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
|
||||||
|
8800 | 0 | 0 | 0 | 0 | 0 | 0 | 800 | 800 | 3800 | 8800 | 0 | 1 | MAAAAA | AAAAAA | AAAAxx
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
FETCH FROM foo25;
|
||||||
|
unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4
|
||||||
|
---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
|
||||||
|
1891 | 1 | 1 | 3 | 1 | 11 | 91 | 891 | 1891 | 1891 | 1891 | 182 | 183 | TUAAAA | BAAAAA | HHHHxx
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
COMMIT;
|
||||||
|
FETCH FROM foo25;
|
||||||
|
unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4
|
||||||
|
---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
|
||||||
|
3420 | 2 | 0 | 0 | 0 | 0 | 20 | 420 | 1420 | 3420 | 3420 | 40 | 41 | OBAAAA | CAAAAA | OOOOxx
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
FETCH BACKWARD FROM foo25;
|
||||||
|
unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4
|
||||||
|
---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
|
||||||
|
1891 | 1 | 1 | 3 | 1 | 11 | 91 | 891 | 1891 | 1891 | 1891 | 182 | 183 | TUAAAA | BAAAAA | HHHHxx
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
FETCH ABSOLUTE -1 FROM foo25;
|
||||||
|
unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4
|
||||||
|
---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
|
||||||
|
2968 | 9999 | 0 | 0 | 8 | 8 | 68 | 968 | 968 | 2968 | 2968 | 136 | 137 | EKAAAA | PUOAAA | VVVVxx
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
CLOSE foo25;
|
||||||
|
--
|
||||||
|
-- ROLLBACK should close holdable cursors
|
||||||
|
--
|
||||||
|
BEGIN;
|
||||||
|
DECLARE foo26 CURSOR WITH HOLD FOR SELECT * FROM tenk1;
|
||||||
|
ROLLBACK;
|
||||||
|
-- should fail
|
||||||
|
FETCH FROM foo26;
|
||||||
|
WARNING: PerformPortalFetch: portal "foo26" not found
|
||||||
|
|
|
@ -1,54 +1,54 @@
|
||||||
--
|
--
|
||||||
-- PORTALS
|
-- Cursor regression tests
|
||||||
--
|
--
|
||||||
|
|
||||||
BEGIN;
|
BEGIN;
|
||||||
|
|
||||||
DECLARE foo1 CURSOR FOR SELECT * FROM tenk1;
|
DECLARE foo1 SCROLL CURSOR FOR SELECT * FROM tenk1;
|
||||||
|
|
||||||
DECLARE foo2 CURSOR FOR SELECT * FROM tenk2;
|
DECLARE foo2 SCROLL CURSOR FOR SELECT * FROM tenk2;
|
||||||
|
|
||||||
DECLARE foo3 CURSOR FOR SELECT * FROM tenk1;
|
DECLARE foo3 SCROLL CURSOR FOR SELECT * FROM tenk1;
|
||||||
|
|
||||||
DECLARE foo4 CURSOR FOR SELECT * FROM tenk2;
|
DECLARE foo4 SCROLL CURSOR FOR SELECT * FROM tenk2;
|
||||||
|
|
||||||
DECLARE foo5 CURSOR FOR SELECT * FROM tenk1;
|
DECLARE foo5 SCROLL CURSOR FOR SELECT * FROM tenk1;
|
||||||
|
|
||||||
DECLARE foo6 CURSOR FOR SELECT * FROM tenk2;
|
DECLARE foo6 SCROLL CURSOR FOR SELECT * FROM tenk2;
|
||||||
|
|
||||||
DECLARE foo7 CURSOR FOR SELECT * FROM tenk1;
|
DECLARE foo7 SCROLL CURSOR FOR SELECT * FROM tenk1;
|
||||||
|
|
||||||
DECLARE foo8 CURSOR FOR SELECT * FROM tenk2;
|
DECLARE foo8 SCROLL CURSOR FOR SELECT * FROM tenk2;
|
||||||
|
|
||||||
DECLARE foo9 CURSOR FOR SELECT * FROM tenk1;
|
DECLARE foo9 SCROLL CURSOR FOR SELECT * FROM tenk1;
|
||||||
|
|
||||||
DECLARE foo10 CURSOR FOR SELECT * FROM tenk2;
|
DECLARE foo10 SCROLL CURSOR FOR SELECT * FROM tenk2;
|
||||||
|
|
||||||
DECLARE foo11 CURSOR FOR SELECT * FROM tenk1;
|
DECLARE foo11 SCROLL CURSOR FOR SELECT * FROM tenk1;
|
||||||
|
|
||||||
DECLARE foo12 CURSOR FOR SELECT * FROM tenk2;
|
DECLARE foo12 SCROLL CURSOR FOR SELECT * FROM tenk2;
|
||||||
|
|
||||||
DECLARE foo13 CURSOR FOR SELECT * FROM tenk1;
|
DECLARE foo13 SCROLL CURSOR FOR SELECT * FROM tenk1;
|
||||||
|
|
||||||
DECLARE foo14 CURSOR FOR SELECT * FROM tenk2;
|
DECLARE foo14 SCROLL CURSOR FOR SELECT * FROM tenk2;
|
||||||
|
|
||||||
DECLARE foo15 CURSOR FOR SELECT * FROM tenk1;
|
DECLARE foo15 SCROLL CURSOR FOR SELECT * FROM tenk1;
|
||||||
|
|
||||||
DECLARE foo16 CURSOR FOR SELECT * FROM tenk2;
|
DECLARE foo16 SCROLL CURSOR FOR SELECT * FROM tenk2;
|
||||||
|
|
||||||
DECLARE foo17 CURSOR FOR SELECT * FROM tenk1;
|
DECLARE foo17 SCROLL CURSOR FOR SELECT * FROM tenk1;
|
||||||
|
|
||||||
DECLARE foo18 CURSOR FOR SELECT * FROM tenk2;
|
DECLARE foo18 SCROLL CURSOR FOR SELECT * FROM tenk2;
|
||||||
|
|
||||||
DECLARE foo19 CURSOR FOR SELECT * FROM tenk1;
|
DECLARE foo19 SCROLL CURSOR FOR SELECT * FROM tenk1;
|
||||||
|
|
||||||
DECLARE foo20 CURSOR FOR SELECT * FROM tenk2;
|
DECLARE foo20 SCROLL CURSOR FOR SELECT * FROM tenk2;
|
||||||
|
|
||||||
DECLARE foo21 CURSOR FOR SELECT * FROM tenk1;
|
DECLARE foo21 SCROLL CURSOR FOR SELECT * FROM tenk1;
|
||||||
|
|
||||||
DECLARE foo22 CURSOR FOR SELECT * FROM tenk2;
|
DECLARE foo22 SCROLL CURSOR FOR SELECT * FROM tenk2;
|
||||||
|
|
||||||
DECLARE foo23 CURSOR FOR SELECT * FROM tenk1;
|
DECLARE foo23 SCROLL CURSOR FOR SELECT * FROM tenk1;
|
||||||
|
|
||||||
FETCH 1 in foo1;
|
FETCH 1 in foo1;
|
||||||
|
|
||||||
|
@ -166,5 +166,55 @@ CLOSE foo11;
|
||||||
|
|
||||||
CLOSE foo12;
|
CLOSE foo12;
|
||||||
|
|
||||||
end;
|
-- is there a reason why we don't close the rest of the open cursors?
|
||||||
|
|
||||||
|
END;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- NO SCROLL disallows backward fetching
|
||||||
|
--
|
||||||
|
|
||||||
|
BEGIN;
|
||||||
|
|
||||||
|
DECLARE foo24 NO SCROLL CURSOR FOR SELECT * FROM tenk1;
|
||||||
|
|
||||||
|
FETCH 1 FROM foo24;
|
||||||
|
|
||||||
|
FETCH BACKWARD 1 FROM foo24; -- should fail
|
||||||
|
|
||||||
|
END;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Cursors outside transaction blocks
|
||||||
|
--
|
||||||
|
|
||||||
|
BEGIN;
|
||||||
|
|
||||||
|
DECLARE foo25 SCROLL CURSOR WITH HOLD FOR SELECT * FROM tenk2;
|
||||||
|
|
||||||
|
FETCH FROM foo25;
|
||||||
|
|
||||||
|
FETCH FROM foo25;
|
||||||
|
|
||||||
|
COMMIT;
|
||||||
|
|
||||||
|
FETCH FROM foo25;
|
||||||
|
|
||||||
|
FETCH BACKWARD FROM foo25;
|
||||||
|
|
||||||
|
FETCH ABSOLUTE -1 FROM foo25;
|
||||||
|
|
||||||
|
CLOSE foo25;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- ROLLBACK should close holdable cursors
|
||||||
|
--
|
||||||
|
|
||||||
|
BEGIN;
|
||||||
|
|
||||||
|
DECLARE foo26 CURSOR WITH HOLD FOR SELECT * FROM tenk1;
|
||||||
|
|
||||||
|
ROLLBACK;
|
||||||
|
|
||||||
|
-- should fail
|
||||||
|
FETCH FROM foo26;
|
Loading…
Reference in New Issue