Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4b8f1bc

Browse files
committed
Make functional indexes accept binary-compatible functions, for example
CREATE INDEX fooi ON foo (lower(f1)) where f1 is varchar rather than text.
1 parent5cfbf3a commit4b8f1bc

File tree

3 files changed

+51
-54
lines changed

3 files changed

+51
-54
lines changed

‎src/backend/commands/indexcmds.c

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.36 2000/08/03 16:34:01 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.37 2000/08/20 00:44:19 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -370,9 +370,12 @@ FuncIndexArgs(IndexInfo *indexInfo,
370370
{
371371
OidargTypes[FUNC_MAX_ARGS];
372372
List*arglist;
373-
HeapTupletuple;
374-
OidretType;
375-
intargn=0;
373+
intnargs=0;
374+
inti;
375+
Oidfuncid;
376+
Oidrettype;
377+
boolretset;
378+
Oid*true_typeids;
376379

377380
/*
378381
* process the function arguments, which are a list of T_String
@@ -385,6 +388,7 @@ FuncIndexArgs(IndexInfo *indexInfo,
385388
foreach(arglist,funcIndex->args)
386389
{
387390
char*arg=strVal(lfirst(arglist));
391+
HeapTupletuple;
388392
Form_pg_attributeatt;
389393

390394
tuple=SearchSysCacheTuple(ATTNAME,
@@ -395,40 +399,47 @@ FuncIndexArgs(IndexInfo *indexInfo,
395399
elog(ERROR,"DefineIndex: attribute \"%s\" not found",arg);
396400
att= (Form_pg_attribute)GETSTRUCT(tuple);
397401

398-
indexInfo->ii_KeyAttrNumbers[argn]=att->attnum;
399-
argTypes[argn]=att->atttypid;
400-
argn++;
402+
indexInfo->ii_KeyAttrNumbers[nargs]=att->attnum;
403+
argTypes[nargs]=att->atttypid;
404+
nargs++;
401405
}
402406

403407
/* ----------------
404408
* Lookup the function procedure to get its OID and result type.
405409
*
406-
* XXX need to accept binary-compatible functions here, not just
407-
* an exact match.
410+
* We rely on parse_func.c to find the correct function in the
411+
* possible presence of binary-compatible types. However, parse_func
412+
* may do too much: it will accept a function that requires run-time
413+
* coercion of input types, and the executor is not currently set up
414+
* to support that. So, check to make sure that the selected function
415+
* has exact-match or binary-compatible input types.
408416
* ----------------
409417
*/
410-
tuple=SearchSysCacheTuple(PROCNAME,
411-
PointerGetDatum(funcIndex->name),
412-
Int32GetDatum(indexInfo->ii_NumKeyAttrs),
413-
PointerGetDatum(argTypes),
414-
0);
415-
if (!HeapTupleIsValid(tuple))
418+
if (!func_get_detail(funcIndex->name,nargs,argTypes,
419+
&funcid,&rettype,&retset,&true_typeids))
420+
func_error("DefineIndex",funcIndex->name,nargs,argTypes,NULL);
421+
422+
if (retset)
423+
elog(ERROR,"DefineIndex: cannot index on a function returning a set");
424+
425+
for (i=0;i<nargs;i++)
416426
{
417-
func_error("DefineIndex",funcIndex->name,
418-
indexInfo->ii_NumKeyAttrs,argTypes,NULL);
427+
if (argTypes[i]!=true_typeids[i]&&
428+
!IS_BINARY_COMPATIBLE(argTypes[i],true_typeids[i]))
429+
func_error("DefineIndex",funcIndex->name,nargs,argTypes,
430+
"Index function must be binary-compatible with table datatype");
419431
}
420432

421-
indexInfo->ii_FuncOid=tuple->t_data->t_oid;
422-
retType= ((Form_pg_proc)GETSTRUCT(tuple))->prorettype;
423-
424433
/* Process opclass, using func return type as default type */
425434

426-
classOidP[0]=GetAttrOpClass(funcIndex,retType,
435+
classOidP[0]=GetAttrOpClass(funcIndex,rettype,
427436
accessMethodName,accessMethodId);
428437

429-
/*Need to do the fmgr function lookup now, too */
438+
/*OK, return results */
430439

431-
fmgr_info(indexInfo->ii_FuncOid,&indexInfo->ii_FuncInfo);
440+
indexInfo->ii_FuncOid=funcid;
441+
/* Need to do the fmgr function lookup now, too */
442+
fmgr_info(funcid,&indexInfo->ii_FuncInfo);
432443
}
433444

434445
staticvoid

‎src/backend/parser/parse_func.c

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/parser/parse_func.c,v 1.87 2000/08/08 15:42:04 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/parser/parse_func.c,v 1.88 2000/08/20 00:44:18 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -37,18 +37,10 @@ static Node *ParseComplexProjection(ParseState *pstate,
3737
char*funcname,
3838
Node*first_arg,
3939
bool*attisset);
40-
staticOid**argtype_inherit(intnargs,Oid*oid_array);
40+
staticOid**argtype_inherit(intnargs,Oid*argtypes);
4141

4242
staticintfind_inheritors(Oidrelid,Oid**supervec);
4343
staticCandidateListfunc_get_candidates(char*funcname,intnargs);
44-
staticbool
45-
func_get_detail(char*funcname,
46-
intnargs,
47-
Oid*oid_array,
48-
Oid*funcid,/* return value */
49-
Oid*rettype,/* return value */
50-
bool*retset,/* return value */
51-
Oid**true_typeids);
5244
staticOid**gen_cross_product(InhPaths*arginh,intnargs);
5345
staticvoidmake_arguments(ParseState*pstate,
5446
intnargs,
@@ -1097,10 +1089,10 @@ func_select_candidate(int nargs,
10971089
* c) if the answer is more than one, attempt to resolve the conflict
10981090
* d) if the answer is zero, try the next array from vector #1
10991091
*/
1100-
staticbool
1092+
bool
11011093
func_get_detail(char*funcname,
11021094
intnargs,
1103-
Oid*oid_array,
1095+
Oid*argtypes,
11041096
Oid*funcid,/* return value */
11051097
Oid*rettype,/* return value */
11061098
bool*retset,/* return value */
@@ -1112,13 +1104,13 @@ func_get_detail(char *funcname,
11121104
ftup=SearchSysCacheTuple(PROCNAME,
11131105
PointerGetDatum(funcname),
11141106
Int32GetDatum(nargs),
1115-
PointerGetDatum(oid_array),
1107+
PointerGetDatum(argtypes),
11161108
0);
11171109

11181110
if (HeapTupleIsValid(ftup))
11191111
{
11201112
/* given argument types are the right ones */
1121-
*true_typeids=oid_array;
1113+
*true_typeids=argtypes;
11221114
}
11231115
else
11241116
{
@@ -1138,11 +1130,11 @@ func_get_detail(char *funcname,
11381130
Oid*current_input_typeids;
11391131

11401132
/*
1141-
* First we will search with the givenoid_array, then with
1133+
* First we will search with the givenargtypes, then with
11421134
* variants based on replacing complex types with their
11431135
* inheritance ancestors. Stop as soon as any match is found.
11441136
*/
1145-
current_input_typeids=oid_array;
1137+
current_input_typeids=argtypes;
11461138

11471139
do
11481140
{
@@ -1200,7 +1192,7 @@ func_get_detail(char *funcname,
12001192
* vectors.
12011193
*/
12021194
if (input_typeid_vector==NULL)
1203-
input_typeid_vector=argtype_inherit(nargs,oid_array);
1195+
input_typeid_vector=argtype_inherit(nargs,argtypes);
12041196

12051197
current_input_typeids=*input_typeid_vector++;
12061198
}
@@ -1243,7 +1235,7 @@ func_get_detail(char *funcname,
12431235
*catalogs.
12441236
*/
12451237
staticOid**
1246-
argtype_inherit(intnargs,Oid*oid_array)
1238+
argtype_inherit(intnargs,Oid*argtypes)
12471239
{
12481240
Oidrelid;
12491241
inti;
@@ -1253,8 +1245,8 @@ argtype_inherit(int nargs, Oid *oid_array)
12531245
{
12541246
if (i<nargs)
12551247
{
1256-
arginh[i].self=oid_array[i];
1257-
if ((relid=typeidTypeRelid(oid_array[i]))!=InvalidOid)
1248+
arginh[i].self=argtypes[i];
1249+
if ((relid=typeidTypeRelid(argtypes[i]))!=InvalidOid)
12581250
arginh[i].nsupers=find_inheritors(relid,&(arginh[i].supervec));
12591251
else
12601252
{
@@ -1467,16 +1459,6 @@ typeInheritsFrom(Oid subclassTypeId, Oid superclassTypeId)
14671459
/* make_arguments()
14681460
* Given the number and types of arguments to a function, and the
14691461
*actual arguments and argument types, do the necessary typecasting.
1470-
*
1471-
* There are two ways an input typeid can differ from a function typeid:
1472-
*1) the input type inherits the function type, so no typecasting required
1473-
*2) the input type can be typecast into the function type
1474-
* Right now, we only typecast unknowns, and that is all we check for.
1475-
*
1476-
* func_get_detail() now can find coercions for function arguments which
1477-
*will make this function executable. So, we need to recover these
1478-
*results here too.
1479-
* - thomas 1998-03-25
14801462
*/
14811463
staticvoid
14821464
make_arguments(ParseState*pstate,

‎src/include/parser/parse_func.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: parse_func.h,v 1.25 2000/08/08 15:42:59 tgl Exp $
10+
* $Id: parse_func.h,v 1.26 2000/08/20 00:44:17 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -45,6 +45,10 @@ extern Node *ParseFuncOrColumn(ParseState *pstate,
4545
boolagg_star,boolagg_distinct,
4646
int*curr_resno,intprecedence);
4747

48+
externboolfunc_get_detail(char*funcname,intnargs,Oid*argtypes,
49+
Oid*funcid,Oid*rettype,
50+
bool*retset,Oid**true_typeids);
51+
4852
externbooltypeInheritsFrom(OidsubclassTypeId,OidsuperclassTypeId);
4953

5054
externvoidfunc_error(char*caller,char*funcname,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp