17-817--8=16∈A17a=-8/17时.解方程x 0.36x 16

/ VRInceptionOnline
项目语言:C#
VRInceptionOnline/
(C)&&2013&&Alibaba&&Inc.&&All&&rights&&resvered.
Powered byRe: A bug in gist code with fetch/move
<td bgcolor="lightgrey" You May Like:
May 4 [OSDir]
This patch no longer appears to be required.
I think someone has fixed
it already.
---------------------------------------------------------------------------
Dmitry Tkach wrote:
& ============================================================================
POSTGRESQL BUG REPORT TEMPLATE
& ============================================================================
& Your name
Dima Tkach
& Your email address
dmitry@xxxxxxxxxxxxxxx
& System Configuration
& ---------------------
Architecture (example: Intel Pentium)
Operating System (example: Linux 2.0.26 ELF)
PostgreSQL version (example: PostgreSQL-7.2.1): PostgreSQL-7.2.1
Compiler used (example:
gcc 2.95.2)
: egcs-2.91.57
& Please enter a FULL description of your problem:
& ------------------------------------------------
& Move/fetch doesn't work correctly with cursors for queries that use GiST
& indexes:
& If you declare such a cursor, fetch a few rows, move it back the same number
& of rows and fetch again, the output will start with the SECOND row, not the
& first one.
& Similarly, if you 'fetch all' from the cursor, and then 'fetch -1', you will
& get the one BEFORE the last row, not the last one.
& The problem is specific to GiST - it does not occur with btree or seq scan
& (I did not test rtrees though) - but it is NOT related to any particular
& extension. I ran into it with my own (custom) extension, and then reproduced
& the same problem using btree_gist from contrib...
& Please describe a way to repeat the problem.
Please try to provide a
& concise reproducible example, if at all possible:
& ----------------------------------------------------------------------
& This example uses btree_gist implementation from contrib, but the same problem
& will occur with any GiST extension, as far as I know:
& -- START OF EXAMPLE (run it in psql)
& \i contrib/btree_gist.sql
& create table test (x int);
& insert into x values (1);
& insert into x values (2);
& create index test_idx on test using gist (x gist_int4_ops);
& set enable_seqscan =
& declare test_cursor cursor for select * from test where x & 0;
& fetch 1 from test_
& move -1 in test_
& -- PROBLEM HERE:
& -- The following command will return 2, although the correct output is 1
& fetch 1 from test_
& -- Or (it is actually, the same problem):
& declare test_cursor cursor for select * from test where x & 0;
& fetch all from test_
& -- PROBLEM: This returns 1, but it should be 2
& fetch -1 from test_
& ---------------------------------------------------------------------
& -- AND HERE IS THE CORRECT BEHAVIOR:
& ---------------------------------------------------------------------
& drop index test_
& declare test_cursor cursor for select * from test where x & 0;
& fetch 1 from test_
& move -1 in test_
& fetch 1 from test_ -- Returns 1 (CORRECT)
& declare test_cursor cursor for select * from test where x & 0;
& fetch all from test_
& fetch -1 from test_ -- Returns 2 (ALSO CORRECT)
& -- END OF EXAMPLE
& --------------------------------------------------------------------
& If you know how this problem might be fixed, list the solution below:
& ---------------------------------------------------------------------
& I compared the gist code to btree, and it seems to me that the patch below
& should do the job (I did compile it and verified that it fixes the problem):
& *** gistget.c
3 16:31:08 2002
& --- gistget.c.old
3 16:29:08 2002
& ***************
& *** 164,173 ****
ReleaseBuffer(b);
if (so-&s_stack == (GISTSTACK *) NULL)
ItemPointerSetInvalid (&(s-&currentItemData));
return (RetrieveIndexResult) NULL;
stk = so-&s_
b = ReadBuffer(s-&relation, stk-&gs_blk);
& --- 164,170 ----
& I hope, it helps...
& ---------------------------(end of broadcast)---------------------------
& TIP 6: Have you searched our list archives?
Bruce Momjian
pgman@xxxxxxxxxxxxxxxx
(610) 853-3000
If your life is a hard drive,
830 Blythe Avenue
Christ can be your backup.
Drexel Hill, Pennsylvania 19026
---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send &unregister YourEmailAddressHere& to majordomo@xxxxxxxxxxxxxx)
Thread at a glance:
Previous Message by Date:
Tatsuo Ishii wrote:
As postgresql is widely used in the world,many Chinese users are looking
forward to use such a high performanced database management
system.However since the Chinese new codepage standard GB18030 is not
completely supported,postgresql is limitted to be used in China.
Now I have managed to implement the GB18030 support upon the latest
version,so the following functions are added after the patches are added.
-Chinese GB18030 encoding is available on front-end side,while on
backend side,EUC_CN or MIC is used.
-Encoding convertion between MIC and GB18030 is implement.
-GB18030 locale support is available on front-end side.
-GB18030 locale test is added.
Any help for testing with these patches and sugguestions for GB18030
support are greatly appreciated.
In your patches I found conversion functions between UTF-8 and GB18030
using the same mapping for EUC_CN. I don't know the details of GB18030
but I could guess that the mapping for EUC_CN might not work with
GB18030. If so, what do you intend to add these function?
Tatsuo Ishii
---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster
Now conversion between UTF-8 and GB18030 is implemented.
/---------------------------/
Bill Huang)
E-mail:bill_huanghb@xxxxxxxxx
/---------------------------/
--- postgresql-7.2.1/src/backend/utils/mb/conv.c.org
7 11:57:14 2002
+++ postgresql-7.2.1/src/backend/utils/mb/conv.c
7 14:15:26 2002
@@ -48,6 +48,8 @@
#include &Unicode/euc_jp_to_utf8.map&
#include &Unicode/utf8_to_euc_cn.map&
#include &Unicode/euc_cn_to_utf8.map&
+#include &Unicode/utf8_to_gb18030.map&
+#include &Unicode/gb18030_to_utf8.map&
#include &Unicode/utf8_to_euc_kr.map&
#include &Unicode/euc_kr_to_utf8.map&
#include &Unicode/utf8_to_euc_tw.map&
@@ -502,6 +504,96 @@
+ * GB18030 ---& MIC
+ * Added by Bill Huang &bhuang@xxxxxxxxxx&,&bill_huanghb@xxxxxxxxx&
+static void
+gb180302mic(unsigned char *gb18030, unsigned char *p, int len)
while (len & 0 && (c1 = *gb18030++))
if (c1 & 0x80)
/* should be
*p++ = c1;
else if(c1 &= 0x81 && c1 &= 0xfe)
c2 = *gb18030++;
if(c2 &= 0x30 && c2 &= 0x69){
*p++ = c1;
*p++ = c2;
*p++ = *gb18030++;
*p++ = *gb18030++;
*p++ = *gb18030++;
else if ((c2 &=0x40 && c2 &= 0x7e) ||(c2 &=0x80 && c2
&= 0xfe)){
*p++ = c1;
*p++ = c2;
*p++ = *gb18030++;
/*throw the strange code*/
*p = '\0';
+ * MIC ---& GB18030
+ * Added by Bill Huang &bhuang@xxxxxxxxxx&,&bill_huanghb@xxxxxxxxx&
+static void
+mic2gb18030(unsigned char *mic, unsigned char *p, int len)
while (len & 0 && (c1 = *mic))
len -= pg_mic_mblen(mic++);
if (c1 &= 0x7f) /*ASCII*/
*p++ = c1;
else if (c1 &= 0x81 && c1 &= 0xfe)
c2 = *mic++;
if((c2 &= 0x40 && c2 &= 0x7e) || (c2 &= 0x80 && c2 &=
*p++ = c1;
*p++ = c2;
else if(c2 &= 0x30 && c2 &= 0x39){
*p++ = c1;
*p++ = c2;
*p++ = *mic++;
*p++ = *mic++;
printBogusChar(&mic, &p);
printBogusChar(&mic, &p);
printBogusChar(&mic, &p);
*p = '\0';
* EUC_TW ---& MIC
static void
@@ -75,26 @@
+ * UTF-8 ---& GB18030
+static void
+utf_to_gb18030(unsigned char *utf, unsigned char *euc, int len)
utf_to_local(utf, euc, ULmapGB18030,
sizeof(ULmapGB18030) /
sizeof(pg_utf_to_local), len);
+ * GB18030 ---& UTF-8
+static void
+gb18030_to_utf(unsigned char *euc, unsigned char *utf, int len)
local_to_utf(euc, utf, LUmapGB18030,
sizeof(LUmapGB18030) / sizeof(pg_local_to_utf), PG_GB18030,
* UTF-8 ---& EUC_KR
static void
@@ -66,9 @@
PG_BIG5, big52mic, mic2big5, big5_to_utf, utf_to_big5
PG_GB18030, gb180302mic, mic2gb18030, gb18030_to_utf,
utf_to_gb18030
PG_WIN1250, win12502mic, mic2win
@@ -56,9 @@
PG_BIG5, big52mic, mic2big5, 0, 0
PG_GB18030, gb180302mic, mic2gb1
PG_WIN1250, win12502mic, mic2win
#! /usr/bin/perl
# Copyright 2002 by Bill Huang
# $Id: UCS_to_GB18030.pl,v 1.2
06:10:18 Bill Huang Exp $
# Generate UTF-8 &--& GB18030 code conversion tables from
# map files provided by Unicode organization.
# Unfortunately it is prohibited by the organization
# to distribute the map files. So if you try to use this script,
# you have to obtain ISO10646-GB18030.TXT from
# the organization's ftp site.
# ISO10646-GB18030.TXT format:
GB18030 code in hex
UCS-2 code in hex
# and Unicode name (not used in this script)
require &ucs2utf.pl&;
# first generate UTF-8 --& GB18030 table
$in_file = &ISO10646-GB18030.TXT&;
open( FILE, $in_file ) || die( &cannot open $in_file& );
while( &FILE& ){
if( /^#/ ){
( $u, $c, $rest ) =
$utf = hex($u);
$code = hex($c);
$array{ $utf } = ($code);
close( FILE );
# first, generate UTF8 --& GB18030 table
$file = &utf8_to_gb18030.map&;
open( FILE, && $file& ) || die( &cannot open $file& );
print FILE &static pg_utf_to_local ULmapGB18030[ $count ] = {\n&;
for $index ( sort {$a &=& $b} keys( %array ) ){
$code = $array{ $index };
if( $count == 0 ){
printf FILE &
{0x%04x, 0x%04x}\n&, $index, $
printf FILE &
{0x%04x, 0x%04x},\n&, $index, $
print FILE &};\n&;
close(FILE);
# then generate GB18030 --& UTF8 table
reset 'array';
open( FILE, $in_file ) || die( &cannot open $in_file& );
while( &FILE& ){
if( /^#/ ){
( $u, $c, $rest ) =
$utf = hex($u);
$code = hex($c);
$array{ $code } = $
close( FILE );
$file = &gb18030_to_utf8.map&;
open( FILE, && $file& ) || die( &cannot open $file& );
print FILE &static pg_local_to_utf LUmapGB18030[ $count ] = {\n&;
for $index ( sort {$a &=& $b} keys( %array ) ){
$utf = $array{ $index };
if( $count == 0 ){
printf FILE &
{0x%04x, 0x%04x}\n&, $index, $
printf FILE &
{0x%04x, 0x%04x},\n&, $index, $
print FILE &};\n&;
close(FILE);
---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?
http://archives.postgresql.org
Next Message by Date:
Patch applied.
---------------------------------------------------------------------------
Jason Tishler wrote:
& The attached patch fixes a problem with InstallXLogFileSegment()'s use
& of link() under Cygwin:
http://archives.postgresql.org/pgsql-cygwin/2002-04/msg00072.php
& Note that it appears that BeOS and Netware also have the above or
& similar problem.
& I have only verified that PostgreSQL builds under Cygwin with this patch.
& Since I cannot reproduce the problem, I cannot verify that the proposed
& patch solves it.
Nevertheless, both Barry Pederson and David P. Caldwell
& attest that this patch solves the problem.
See the following for details:
http://archives.postgresql.org/pgsql-cygwin/2002-05/msg00043.php
http://archives.postgresql.org/pgsql-cygwin/2002-05/msg00040.php
[ Attachment, skipping... ]
& ---------------------------(end of broadcast)---------------------------
& TIP 5: Have you checked our extensive FAQ?
& http://www.postgresql.org/users-lounge/docs/faq.html
Bruce Momjian
http://candle.pha.pa.us
pgman@xxxxxxxxxxxxxxxx
(610) 853-3000
If your life is a hard drive,
830 Blythe Avenue
Christ can be your backup.
Drexel Hill, Pennsylvania 19026
---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?
http://archives.postgresql.org
Previous Message by Thread:
This is a small script to check that guc.c and postgresql.conf.sample
are fairly representative of each other, and the output that I'm getting
against the most recent cvs.
The fix for debug_level is easy enough (I know it was removed from guc.c),
but I don't know enough about the rest of the items to be able to document
them in the postgresql.conf.sample well.
debug_level seems to be missing from guc.c
fixbtree seems to be missing from postgresql.conf.sample
pre_auth_delay seems to be missing from postgresql.conf.sample
lc_messages seems to be missing from postgresql.conf.sample
lc_monetary seems to be missing from postgresql.conf.sample
lc_numeric seems to be missing from postgresql.conf.sample
lc_time seems to be missing from postgresql.conf.sample
server_encoding seems to be missing from postgresql.conf.sample
session_authorization seems to be missing from postgresql.conf.sample
I believe this script should live in src/tools
## currently, this script makes a lot of assumptions:
## 1) location of guc.c and postgresql.conf.sample relative to src/tools
For postgresql.conf.sample
## 2) the valid config settings may be preceded by a '#', but NOT '# '
## 3) the valid config settings will be followed immediately by
(at least one space preceding the '='
## 4) the options have PGC_ on the same line as the option
## 5) the options have '{ ' on the same line as the option
## 1) Don't know what to do with TRANSACTION ISOLATION LEVEL (in guc.c)
PATH_TO_GUC=&`dirname $0`/../backend/utils/misc&
SETTINGS=`grep ' =' $PATH_TO_GUC/postgresql.conf.sample | grep -v '^# ' | sed
-e 's,^#,,' | awk '{print $1}'`
for i in $SETTINGS ; do
grep -i $i $PATH_TO_GUC/guc.c & /dev/
if [ ! $? = 0 ] ; then
echo &$i seems to be missing from guc.c&;
SETTINGS=`grep '{ .*PGC_' $PATH_TO_GUC/guc.c | awk '{print $2}' | sed -e
's,&,,g' -e 's/,//'`
for i in $SETTINGS ; do
grep -i $i $PATH_TO_GUC/postgresql.conf.sample & /dev/
if [ ! $? = 0 ] ; then
echo &$i seems to be missing from postgresql.conf.sample&;
---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@xxxxxxxxxxxxxx so that your
message can get through to the mailing list cleanly
Next Message by Thread:
Tom Lane wrote:
Definitely better.
I'd suggest also thinking about whether the
same/similar macros can support functions that return a set of a
scalar (non-tuple) datatype.
In my mind, the cleanest design would
be some base macros that support functions-returning-set (of anything),
and if you want to return a set of scalar then you just use these
directly (handing a Datum to FUNC_RETURN_NEXT).
If you want to return
a set of tuples then there are a couple extra steps that you need to
do to build a tupdesc, build a tuple, and convert the tuple to Datum
(which at the moment you do by putting it into a slot, but I think we
ought to change that soon).
If it were really clean then the macros
supporting these extra steps would also work without the SRF macros,
so that you could use 'em in a function returning a single tuple.
As promised on HACKERS, here's the Composite and SRF function API patch.
Included is a new builtin guc function, exported as show_all_vars(). In
order to avoid creating a new bootstrapped relation, I made the pg_proc
entry specify 0 as the function return type, and then fixed it in
initdb.sh as follows:
$ECHO_N &setting return type for composite returning functions... &$ECHO_C
&$PGPATH&/postgres $PGSQL_OPT template1 &/dev/null &&EOF
CREATE VIEW pg__guc AS \
''::text as varname, \
UPDATE pg_proc SET \
prorettype = (SELECT oid FROM pg_type WHERE typname = 'pg__guc') \
proname = 'show_all_vars';
if [ &$?& -ne 0 ]; then
exit_nicely
Any concerns with this approach? Is it too much of a hack, or
preferrable to adding new bootstrapped relations solely for this purpose?
Index: src/backend/access/common/tupdesc.c
===================================================================
RCS file: /opt/src/cvs/pgsql/src/backend/access/common/tupdesc.c,v
retrieving revision 1.78
diff -c -r1.78 tupdesc.c
*** src/backend/access/common/tupdesc.c 29 Mar :59 -0000
--- src/backend/access/common/tupdesc.c 7 Jun :52 -0000
***************
*** 19,24 ****
--- 19,27 ----
#include &postgres.h&
+ #include &funcapi.h&
+ #include &access/heapam.h&
+ #include &catalog/namespace.h&
#include &catalog/pg_type.h&
#include &nodes/parsenodes.h&
#include &parser/parse_type.h&
***************
*** 548,551 ****
--- 551,660 ----
desc-&constr = NULL;
* RelationNameGetTupleDesc
* Given a (possibly qualified) relation name, build a TupleDesc.
+ TupleDesc
+ RelationNameGetTupleDesc(char *relname)
/* Open relation and get the tuple description */
relname_list = stringToQualifiedNameList(relname,
&RelationNameGetTupleDesc&);
relvar = makeRangeVarFromNameList(relname_list);
rel = heap_openrv(relvar, AccessShareLock);
tupdesc = CreateTupleDescCopy(RelationGetDescr(rel));
relation_close(rel, AccessShareLock);
* TypeGetTupleDesc
* Given a type Oid, build a TupleDesc.
* If the type is composite, *and* a colaliases List is provided, *and*
* the List is of natts length, use the aliases instead of the relation
* attnames.
* If the type is a base type, a single item alias List is required.
+ TupleDesc
+ TypeGetTupleDesc(Oid typeoid, List *colaliases)
relid = typeidTypeRelid(typeoid);
* Build a suitable tupledesc representing the output rows
if (OidIsValid(relid))
/* Composite data type, i.e. a table's row type */
rel = relation_open(relid, AccessShareLock);
tupdesc = CreateTupleDescCopy(RelationGetDescr(rel));
natts = tupdesc-&
relation_close(rel, AccessShareLock);
/* check to see if we've given column aliases */
if(colaliases != NIL)
/* does the List length match the number of attributes
if (length(colaliases) != natts)
elog(ERROR, &TypeGetTupleDesc: number of
aliases does not match number of attributes&);
/* OK, use the aliases instead */
for (varattno = 0; varattno & varattno++)
label = strVal(nth(varattno, colaliases));
if (label != NULL)
namestrcpy(&(tupdesc-&attrs[varattno]-&attname), label);
MemSet(NameStr(tupdesc-&attrs[varattno]-&attname), 0, NAMEDATALEN);
/* Must be a base data type, i.e. scalar */
/* the alias List is required for base types */
if (colaliases == NIL)
elog(ERROR, &TypeGetTupleDesc: no column alias was
provided&);
/* the alias List length must be 1 */
if (length(colaliases) != 1)
elog(ERROR, &TypeGetTupleDesc: number of aliases does
not match number of attributes&);
/* OK, get the column alias */
attname = strVal(lfirst(colaliases));
tupdesc = CreateTemplateTupleDesc(1);
TupleDescInitEntry(tupdesc,
(AttrNumber) 1,
Index: src/backend/executor/execTuples.c
===================================================================
RCS file: /opt/src/cvs/pgsql/src/backend/executor/execTuples.c,v
retrieving revision 1.51
diff -c -r1.51 execTuples.c
*** src/backend/executor/execTuples.c
21 Mar :04 -0000
--- src/backend/executor/execTuples.c
7 Jun :51 -0000
***************
*** 107,117 ****
#include &postgres.h&
#include &access/heapam.h&
#include &catalog/pg_type.h&
#include &executor/executor.h&
/* ----------------------------------------------------------------
tuple table create/delete functions
* ----------------------------------------------------------------
--- 107,117 ----
#include &postgres.h&
+ #include &funcapi.h&
#include &access/heapam.h&
#include &catalog/pg_type.h&
#include &executor/executor.h&
/* ----------------------------------------------------------------
tuple table create/delete functions
* ----------------------------------------------------------------
***************
*** 673,675 ****
--- 673,795 ----
return typeI
* TupleDescGetSlot - Initialize a slot based on the supplied
* tupledesc
+ TupleTableSlot *
+ TupleDescGetSlot(TupleDesc tupdesc)
TupleTableSlot
/* Make a standalone slot */
slot = MakeTupleTableSlot();
/* Bind the tuple description to the slot */
ExecSetSlotDescriptor(slot, tupdesc, true);
/* Return the slot */
* TupleDescGetAttInMetadata - Get a pointer to AttInMetadata based on the
* supplied TupleDesc. AttInMetadata can be used in conjunction with C strings
* to produce a properly formed tuple.
+ AttInMetadata *
+ TupleDescGetAttInMetadata(TupleDesc tupdesc)
AttInMetadata
attinmeta = (AttInMetadata *) palloc(sizeof(AttInMetadata));
natts = tupdesc-&
* Gather info needed later to call the &in& function for each attribute
attinfuncinfo = (FmgrInfo *) palloc(natts * sizeof(FmgrInfo));
attelems = (Oid *) palloc(natts * sizeof(Oid));
atttypmods = (int4 *) palloc(natts * sizeof(int4));
for (i = 0; i & i++)
atttypeid = tupdesc-&attrs[i]-&
get_type_metadata(atttypeid, &attinfuncid, &attelem);
fmgr_info(attinfuncid, &attinfuncinfo[i]);
attelems[i] =
atttypmods[i] = tupdesc-&attrs[i]-&
attinmeta-&tupdesc =
attinmeta-&attinfuncs =
attinmeta-&attelems =
attinmeta-&atttypmods =
* BuildTupleFromCStrings - build a HeapTuple given user data in C string
* values is an array of C strings, one for each attribute of the return
+ HeapTuple
+ BuildTupleFromCStrings(AttInMetadata *attinmeta, char **values)
tupdesc = attinmeta-&
natts = tupdesc-&
dvalues = (Datum *) palloc(natts * sizeof(Datum));
/* Call the &in& function for each attribute */
for (i = 0; i & i++)
if (values[i] != NULL)
attinfuncinfo = attinmeta-&attinfuncs[i];
attelem = attinmeta-&attelems[i];
atttypmod = attinmeta-&atttypmods[i];
dvalues[i] = FunctionCall3(&attinfuncinfo,
CStringGetDatum(values[i]),
ObjectIdGetDatum(attelem),
Int32GetDatum(atttypmod));
dvalues[i] = PointerGetDatum(NULL);
* Form a tuple
nulls = (char *) palloc(natts * sizeof(char));
for (i = 0; i & i++)
if (DatumGetPointer(dvalues[i]) != NULL)
nulls[i] = ' ';
nulls[i] = 'n';
tuple = heap_formtuple(tupdesc, dvalues, nulls);
Index: src/backend/utils/adt/regproc.c
===================================================================
RCS file: /opt/src/cvs/pgsql/src/backend/utils/adt/regproc.c,v
retrieving revision 1.68
diff -c -r1.68 regproc.c
*** src/backend/utils/adt/regproc.c
11 May :16 -0000
--- src/backend/utils/adt/regproc.c
7 Jun :51 -0000
***************
*** 37,44 ****
#include &utils/lsyscache.h&
#include &utils/syscache.h&
- static List *stringToQualifiedNameList(const char *string, const char
static void parseNameAndArgTypes(const char *string, const char *caller,
const char
*type0_spelling,
List **names,
int *nargs, Oid *argtypes);
--- 37,42 ----
***************
*** 960,973 ****
- /*****************************************************************************
SUPPORT ROUTINES
*****************************************************************************/
* Given a C string, parse it into a qualified-name list.
! static List *
stringToQualifiedNameList(const char *string, const char *caller)
--- 958,967 ----
* Given a C string, parse it into a qualified-name list.
stringToQualifiedNameList(const char *string, const char *caller)
***************
*** 996,1001 ****
--- 990,999 ----
+ /*****************************************************************************
SUPPORT ROUTINES
*****************************************************************************/
* Given a C string, parse it into a qualified function or operator name
Index: src/backend/utils/fmgr/Makefile
===================================================================
RCS file: /opt/src/cvs/pgsql/src/backend/utils/fmgr/Makefile,v
retrieving revision 1.12
diff -c -r1.12 Makefile
*** src/backend/utils/fmgr/Makefile
16 Sep :11 -0000
--- src/backend/utils/fmgr/Makefile
7 Jun :51 -0000
***************
*** 12,18 ****
top_builddir = ../../../..
include $(top_builddir)/src/Makefile.global
! OBJS = dfmgr.o fmgr.o
override CPPFLAGS += -DPKGLIBDIR=\&$(pkglibdir)\& -DDLSUFFIX=\&$(DLSUFFIX)\&
--- 12,18 ----
top_builddir = ../../../..
include $(top_builddir)/src/Makefile.global
! OBJS = dfmgr.o fmgr.o funcapi.o
override CPPFLAGS += -DPKGLIBDIR=\&$(pkglibdir)\& -DDLSUFFIX=\&$(DLSUFFIX)\&
Index: src/backend/utils/fmgr/funcapi.c
===================================================================
RCS file: src/backend/utils/fmgr/funcapi.c
diff -N src/backend/utils/fmgr/funcapi.c
*** /dev/null
1 Jan :00 -0000
--- src/backend/utils/fmgr/funcapi.c
7 Jun :51 -0000
***************
*** 0 ****
--- 1,122 ----
+ /*-------------------------------------------------------------------------
* funcapi.c
Utility and convenience functions for fmgr functions that return
sets and/or composite types.
* Copyright (c) 2002, PostgreSQL Global Development Group
*-------------------------------------------------------------------------
+ #include &funcapi.h&
+ #include &catalog/pg_type.h&
+ #include &utils/syscache.h&
* init_MultiFuncCall
* Create an empty FuncCallContext data structure
* and do some other basic Multi-function call setup
* and error checking
+ FuncCallContext *
+ init_MultiFuncCall(PG_FUNCTION_ARGS, TupleTableSlot *slot)
FuncCallContext *
* Bail if we're called in the wrong context
if (fcinfo-&resultinfo == NULL || !IsA(fcinfo-&resultinfo,
ReturnSetInfo))
elog(ERROR, &function called in context that does not accept a
set result&);
if (fcinfo-&flinfo-&fn_extra == NULL)
* First call
/* switch to the appropriate memory context */
oldcontext = MemoryContextSwitchTo(fcinfo-&flinfo-&fn_mcxt);
* allocate space and zero it
retval = (FuncCallContext *) palloc(sizeof(FuncCallContext));
MemSet(retval, 0, sizeof(FuncCallContext));
* initialize the elements
retval-&call_cntr = 0;
retval-&max_calls = 0;
retval-&slot =
retval-&fctx = NULL;
retval-&attinmeta = NULL;
retval-&fmctx = fcinfo-&flinfo-&fn_
* save the pointer for cross-call use
fcinfo-&flinfo-&fn_extra =
/* back to the original memory context */
MemoryContextSwitchTo(oldcontext);
/* second and subsequent calls */
elog(ERROR, &init_MultiFuncCall may not be called more than
/* never reached, but keep compiler happy */
retval = NULL;
* end_MultiFuncCall
* Clean up after init_MultiFuncCall
+ end_MultiFuncCall(PG_FUNCTION_ARGS, FuncCallContext *funcctx)
/* unbind from fcinfo */
fcinfo-&flinfo-&fn_extra = NULL;
* Caller is responsible to free up memory for individual
* struct elements other than att_in_funcinfo and elements.
oldcontext = MemoryContextSwitchTo(funcctx-&fmctx);
if (funcctx-&attinmeta != NULL)
pfree(funcctx-&attinmeta);
pfree(funcctx);
MemoryContextSwitchTo(oldcontext);
+ get_type_metadata(Oid typeid, Oid *attinfuncid, Oid *attelem)
typeTuple = SearchSysCache(TYPEOID,
ObjectIdGetDatum(typeid),
if (!HeapTupleIsValid(typeTuple))
elog(ERROR, &get_type_metadata: Cache lookup of type %u
failed&, typeid);
typtup = (Form_pg_type) GETSTRUCT(typeTuple);
*attinfuncid = typtup-&
*attelem = typtup-&
ReleaseSysCache(typeTuple);
Index: src/backend/utils/misc/guc.c
===================================================================
RCS file: /opt/src/cvs/pgsql/src/backend/utils/misc/guc.c,v
retrieving revision 1.69
diff -c -r1.69 guc.c
*** src/backend/utils/misc/guc.c
17 May :29 -0000
--- src/backend/utils/misc/guc.c
7 Jun :51 -0000
***************
*** 21,28 ****
--- 21,30 ----
#include &utils/guc.h&
+ #include &funcapi.h&
#include &access/xlog.h&
#include &catalog/namespace.h&
+ #include &catalog/pg_type.h&
#include &commands/async.h&
#include &commands/variable.h&
#include &fmgr.h&
***************
*** 824,830 ****
static int guc_var_compare(const void *a, const void *b);
! static void _ShowOption(struct config_generic *record);
--- 826,833 ----
static int guc_var_compare(const void *a, const void *b);
! static char *_ShowOption(struct config_generic *record);
! static char *GetNextGUCConfig(int varnum, char **varname);
***************
ShowGUCConfigOption(const char *name)
struct config_generic *
record = find_option(name);
if (record == NULL)
elog(ERROR, &Option '%s' is not recognized&, name);
_ShowOption(record);
ShowGUCConfigOption(const char *name)
struct config_generic *
record = find_option(name);
if (record == NULL)
elog(ERROR, &Option '%s' is not recognized&, name);
val = _ShowOption(record);
if(val != NULL)
elog(INFO, &%s is %s&, record-&name, val);
pfree(val);
***************
ShowAllGUCConfig(void)
for (i = 0; i & num_guc_ i++)
struct config_generic *conf = guc_variables[i];
if ((conf-&flags & GUC_NO_SHOW_ALL) == 0)
_ShowOption(conf);
! static void
_ShowOption(struct config_generic *record)
buffer[256];
const char *
switch (record-&vartype)
ShowAllGUCConfig(void)
for (i = 0; i & num_guc_ i++)
struct config_generic *conf = guc_variables[i];
if ((conf-&flags & GUC_NO_SHOW_ALL) == 0)
val = _ShowOption(conf);
if(val != NULL)
elog(INFO, &%s is %s&, conf-&name, val);
pfree(val);
* SHOW X or SHOW ALL command
! static char *
! GetNextGUCConfig(int varnum, char **varname)
struct config_generic *conf = guc_variables[varnum];
*varname = pstrdup(conf-&name);
if ((conf-&flags & GUC_NO_SHOW_ALL) == 0)
return _ShowOption(conf);
return NULL;
! static char *
_ShowOption(struct config_generic *record)
buffer[256];
const char *
switch (record-&vartype)
***************
elog(INFO, &%s is %s&, record-&name, val);
retval = pstrdup(val);
***************
* showguc_all - equiv to SHOW ALL command but implemented as
+ showguc_all(PG_FUNCTION_ARGS)
FuncCallContext
TupleTableSlot
AttInMetadata
struct config_generic **
/* stuff done only on the first call of the function */
if(SRF_IS_FIRSTPASS())
* Build a tuple description for a pg__guc tuple
tupdesc = RelationNameGetTupleDesc(&pg__guc&);
/* allocate a slot for a tuple with this tupdesc */
slot = TupleDescGetSlot(tupdesc);
/* create a function context for cross-call persistence */
funcctx = SRF_FIRSTCALL_INIT(slot);
* Generate attribute metadata needed later to produce tuples
* C strings
attinmeta = TupleDescGetAttInMetadata(tupdesc);
funcctx-&attinmeta =
/* total number of tuples to be returned */
funcctx-&max_calls = num_guc_
/* pointer to structure containing user defined context */
funcctx-&fctx = (void *) guc_
/* stuff done on every call of the function */
funcctx = SRF_PERCALL_SETUP(funcctx);
call_cntr = funcctx-&call_
max_calls = funcctx-&max_
slot = funcctx-&
fctx = (struct config_generic **) funcctx-&
attinmeta = funcctx-&
if (call_cntr & max_calls)
/* do when there is more left to send */
* Get the next GUC variable name and value
varval = GetNextGUCConfig(call_cntr, &varname);
* Prepare a values array for storage in our slot.
* This should be an array of C strings which will
* be processed later by the appropriate &in& functions.
values = (char **) palloc(2 * sizeof(char *));
values[0] =
values[1] =
/* build a tuple */
tuple = BuildTupleFromCStrings(attinmeta, values);
/* make the tuple into a datum */
result = TupleGetDatum(slot, tuple);
/* Clean up */
pfree(varname);
pfree(values);
SRF_RETURN_NEXT(funcctx, result);
/* do when there is no more left */
SRF_RETURN_DONE(funcctx);
Index: src/bin/initdb/initdb.sh
===================================================================
RCS file: /opt/src/cvs/pgsql/src/bin/initdb/initdb.sh,v
retrieving revision 1.155
diff -c -r1.155 initdb.sh
*** src/bin/initdb/initdb.sh
21 May :00 -0000
--- src/bin/initdb/initdb.sh
7 Jun :20 -0000
***************
*** 967,972 ****
--- 967,993 ----
| &$PGPATH&/postgres $PGSQL_OPT template1 & /dev/null || exit_nicely
+ $ECHO_N &setting return type for composite returning functions... &$ECHO_C
+ &$PGPATH&/postgres $PGSQL_OPT template1 &/dev/null &&EOF
+ CREATE VIEW pg__guc AS \
''::text as varname, \
+ UPDATE pg_proc SET \
prorettype = (SELECT oid FROM pg_type WHERE typname = 'pg__guc') \
proname = 'show_all_vars';
+ if [ &$?& -ne 0 ]; then
exit_nicely
+ echo &ok&
# Set most system catalogs and built-in functions as world-accessible.
# Some objects may require different permissions by default, so we
# make sure we don't overwrite privilege sets that have already been
Index: src/include/funcapi.h
===================================================================
RCS file: src/include/funcapi.h
diff -N src/include/funcapi.h
*** /dev/null
1 Jan :00 -0000
--- src/include/funcapi.h
7 Jun :17 -0000
***************
*** 0 ****
--- 1,193 ----
+ /*-------------------------------------------------------------------------
* funcapi.h
Definitions for functions which return composite type and/or sets
* This file must be included by all Postgres modules that either define
* or call FUNCAPI-callable functions or macros.
* Copyright (c) 2002, PostgreSQL Global Development Group
*-------------------------------------------------------------------------
+ #ifndef FUNCAPI_H
+ #define FUNCAPI_H
+ #include &postgres.h&
+ #include &fmgr.h&
+ #include &access/htup.h&
+ #include &access/tupdesc.h&
+ #include &executor/executor.h&
+ #include &executor/tuptable.h&
* All functions that can be called directly by fmgr must have this signature.
* (Other functions can be called by using a handler that does have this
* signature.)
+ /*-------------------------------------------------------------------------
Support to ease writing Functions returning composite types
*-------------------------------------------------------------------------
* This struct holds arrays of individual attribute information
* needed to create a tuple from raw C strings. It also requires
* a copy of the TupleDesc. The information carried here
* is derived from the TupleDesc, but it is stored here to
* avoid redundant cpu cycles on each call to an SRF.
+ typedef struct
/* full TupleDesc */
/* pointer to array of attribute &type&in finfo */
/* pointer to array of attribute type typelem */
/* pointer to array of attribute type typtypmod */
+ /*-------------------------------------------------------------------------
Support struct to ease writing Set Returning Functions (SRFs)
*-------------------------------------------------------------------------
* This struct holds function context for Set Returning Functions.
* Use fn_extra to hold a pointer to it across calls
+ typedef struct
/* Number of times we've been called before */
/* Maximum number of calls */
/* pointer to result slot */
TupleTableSlot *
/* pointer to misc context info */
/* pointer to struct containing arrays of attribute type input metainfo
AttInMetadata
/* memory context used to initialize structure */
+ /*-------------------------------------------------------------------------
Support to ease writing Functions returning composite types
* External declarations:
* TupleDesc RelationNameGetTupleDesc(char *relname) - Use to get a TupleDesc
based on the function's return type relation.
* TupleDesc TypeGetTupleDesc(Oid typeoid, List *colaliases) - Use to get a
TupleDesc based on the function's type oid. This can be used to
a TupleDesc for a base (scalar), or composite (relation) type.
* TupleTableSlot *TupleDescGetSlot(TupleDesc tupdesc) - Initialize a slot
given a TupleDesc.
* AttInMetadata *TupleDescGetAttInMetadata(TupleDesc tupdesc) - Get a pointer
to AttInMetadata based on the function's TupleDesc.
AttInMetadata can
be used in conjunction with C strings to produce a properly
tuple. Store the metadata here for use across calls to avoid
* HeapTuple BuildTupleFromCStrings(AttInMetadata *attinmeta, char **values) -
build a HeapTuple given user data in C string form. values is
of C strings, one for each attribute of the return tuple.
* Macro declarations:
* TupleGetDatum(TupleTableSlot *slot, HeapTuple tuple) - get a Datum
given a tuple and a slot.
+ /* from tupdesc.c */
+ extern TupleDesc RelationNameGetTupleDesc(char *relname);
+ extern TupleDesc TypeGetTupleDesc(Oid typeoid, List *colaliases);
+ /* from execTuples.c */
+ extern TupleTableSlot *TupleDescGetSlot(TupleDesc tupdesc);
+ extern AttInMetadata *TupleDescGetAttInMetadata(TupleDesc tupdesc);
+ extern HeapTuple BuildTupleFromCStrings(AttInMetadata *attinmeta, char
**values);
+ /* from funcapi.c */
+ extern FuncCallContext *init_MultiFuncCall(PG_FUNCTION_ARGS, TupleTableSlot
+ extern void end_MultiFuncCall(PG_FUNCTION_ARGS, FuncCallContext *funcctx);
+ extern void get_type_metadata(Oid typeid, Oid *attinfuncid, Oid *attelem);
+ #define TupleGetDatum(_slot, _tuple) \
PointerGetDatum(ExecStoreTuple(_tuple, _slot, InvalidBuffer, true))
+ /*-------------------------------------------------------------------------
Support for Set Returning Functions (SRFs)
* The basic API for SRFs looks something like:
* my_Set_Returning_Function(PG_FUNCTION_ARGS)
FuncCallContext
&user defined declarations&
if(SRF_IS_FIRSTPASS())
&user defined code&
&obtain slot&
funcctx = SRF_FIRSTCALL_INIT(slot);
&user defined code&
&user defined code&
funcctx = SRF_PERCALL_SETUP(funcctx);
&user defined code&
if (funcctx-&call_cntr & funcctx-&max_calls)
&user defined code&
&obtain result Datum&
SRF_RETURN_NEXT(funcctx, result);
SRF_RETURN_DONE(funcctx);
+ /* from funcapi.c */
+ extern FuncCallContext *init_MultiFuncCall(PG_FUNCTION_ARGS, TupleTableSlot
+ extern void end_MultiFuncCall(PG_FUNCTION_ARGS, FuncCallContext *funcctx);
+ #define SRF_IS_FIRSTPASS() (fcinfo-&flinfo-&fn_extra == NULL)
+ #define SRF_FIRSTCALL_INIT(_slot) init_MultiFuncCall(fcinfo,_slot)
+ #define SRF_PERCALL_SETUP(_funcctx)
fcinfo-&flinfo-&fn_ExecClearTuple(_funcctx-&slot)
+ #define SRF_RETURN_NEXT(_funcctx, _result) \
ReturnSetInfo
_funcctx-&call_cntr++; \
rsi = (ReturnSetInfo *) fcinfo-& \
rsi-&isDone = ExprMultipleR \
PG_RETURN_DATUM(_result); \
} while (0)
SRF_RETURN_DONE(_funcctx) \
ReturnSetInfo
end_MultiFuncCall(fcinfo, _funcctx); \
rsi = (ReturnSetInfo *) fcinfo-& \
rsi-&isDone = ExprEndR \
_funcctx-&slot = NULL; \
PG_RETURN_NULL(); \
} while (0)
/* FUNCAPI_H */
Index: src/include/catalog/catversion.h
===================================================================
RCS file: /opt/src/cvs/pgsql/src/include/catalog/catversion.h,v
retrieving revision 1.133
diff -c -r1.133 catversion.h
*** src/include/catalog/catversion.h
22 May :01 -0000
--- src/include/catalog/catversion.h
7 Jun :51 -0000
***************
*** 53,58 ****
yyyymmddN */
! #define CATALOG_VERSION_NO
--- 53,58 ----
yyyymmddN */
! #define CATALOG_VERSION_NO
Index: src/include/catalog/pg_proc.h
===================================================================
RCS file: /opt/src/cvs/pgsql/src/include/catalog/pg_proc.h,v
retrieving revision 1.240
diff -c -r1.240 pg_proc.h
*** src/include/catalog/pg_proc.h
24 May :56 -0000
--- src/include/catalog/pg_proc.h
7 Jun :25 -0000
***************
DATA(insert OID = 2072 (
date_mi_interval
PGNSP PGUID 14 f f f t f i 2
&select cast($1 as timestamp without time zone) -
$2;& - _null_ ));
DESCR(&subtract&);
+ DATA(insert OID = 2073 (
show_all_vars
PGNSP PGUID 12 f f f t t s
0 0 &0& 100 0 0 100
showguc_all - _null_ ));
+ DESCR(&show all GUC variable values&);
/* Aggregates (moved here from pg_aggregate for 7.3) */
DATA(insert OID = 2100 (
PGNSP PGUID 12 t f f f
f i 1 0 0 0 100
aggregate_dummy - _null_ ));
Index: src/include/utils/builtins.h
===================================================================
RCS file: /opt/src/cvs/pgsql/src/include/utils/builtins.h,v
retrieving revision 1.182
diff -c -r1.182 builtins.h
*** src/include/utils/builtins.h
18 May :41 -0000
--- src/include/utils/builtins.h
7 Jun :52 -0000
***************
*** 341,346 ****
--- 341,347 ----
extern Datum regclassout(PG_FUNCTION_ARGS);
extern Datum regtypein(PG_FUNCTION_ARGS);
extern Datum regtypeout(PG_FUNCTION_ARGS);
+ extern List *stringToQualifiedNameList(const char *string, const char
/* ruleutils.c */
extern Datum pg_get_ruledef(PG_FUNCTION_ARGS);
***************
*** 630,634 ****
--- 631,638 ----
/* quote.c */
extern Datum quote_ident(PG_FUNCTION_ARGS);
extern Datum quote_literal(PG_FUNCTION_ARGS);
+ /* guc.c */
+ extern Datum showguc_all(PG_FUNCTION_ARGS);
/* BUILTINS_H */
Index: src/test/regress/expected/rules.out
===================================================================
RCS file: /opt/src/cvs/pgsql/src/test/regress/expected/rules.out,v
retrieving revision 1.53
diff -c -r1.53 rules.out
*** src/test/regress/expected/rules.out 3 May :19 -0000
--- src/test/regress/expected/rules.out 7 Jun :58 -0000
***************
definition
--------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| SELECT ih.name, ih.thepath,
interpt_pp(ih.thepath, r.thepath) AS exit FROM ihighway ih, ramp r WHERE
(ih.thepath ## r.thepath);
| SELECT ''::text AS varname, ''::text AS
pg_indexes
| SELECT c.relname AS tablename, i.relname AS
indexname, pg_get_indexdef(x.indexrelid) AS indexdef FROM pg_index x, pg_class
c, pg_class i WHERE ((((c.relkind = 'r'::&char&) AND (i.relkind = 'i'::&char&))
AND (c.oid = x.indrelid)) AND (i.oid = x.indexrelid));
| SELECT n.nspname AS schemaname, c.relname AS
tablename, r.rulename, pg_get_ruledef(r.oid) AS definition FROM ((pg_rewrite r
JOIN pg_class c ON ((c.oid = r.ev_class))) LEFT JOIN pg_namespace n ON ((n.oid
= c.relnamespace))) WHERE (r.rulename && '_RETURN'::name);
pg_stat_activity
| SELECT d.oid AS datid, d.datname,
pg_stat_get_backend_pid(s.backendid) AS procpid,
pg_stat_get_backend_userid(s.backendid) AS usesysid, u.usename,
pg_stat_get_backend_activity(s.backendid) AS current_query FROM pg_database d,
(SELECT pg_stat_get_backend_idset() AS backendid) s, pg_shadow u WHERE
((pg_stat_get_backend_dbid(s.backendid) = d.oid) AND
(pg_stat_get_backend_userid(s.backendid) = u.usesysid));
***************
shoelace_obsolete
| SELECT shoelace.sl_name, shoelace.sl_avail,
shoelace.sl_color, shoelace.sl_len, shoelace.sl_unit, shoelace.sl_len_cm FROM
shoelace WHERE (NOT (EXISTS (SELECT shoe.shoename FROM shoe WHERE (shoe.slcolor
= shoelace.sl_color))));
| SELECT r.name, r.thepath, c.cname FROM ONLY road
r, real_city c WHERE (c.outline ## r.thepath);
| SELECT emp.name, emp.age, emp.&location&, (12 *
emp.salary) AS annualsal FROM
! (38 rows)
SELECT tablename, rulename, definition FROM pg_rules
ORDER BY tablename,
shoelace_obsolete
| SELECT shoelace.sl_name, shoelace.sl_avail,
shoelace.sl_color, shoelace.sl_len, shoelace.sl_unit, shoelace.sl_len_cm FROM
shoelace WHERE (NOT (EXISTS (SELECT shoe.shoename FROM shoe WHERE (shoe.slcolor
= shoelace.sl_color))));
| SELECT r.name, r.thepath, c.cname FROM ONLY road
r, real_city c WHERE (c.outline ## r.thepath);
| SELECT emp.name, emp.age, emp.&location&, (12 *
emp.salary) AS annualsal FROM
! (39 rows)
SELECT tablename, rulename, definition FROM pg_rules
ORDER BY tablename,
---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster
Latest News Stories:
Latest News Stories:}

我要回帖

更多关于 一元二次方程 题目 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信