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

Commit75586cb

Browse files
committed
Disallow non-cachable functions in functional indexes and in index
predicates. Per suggestion from Hiroshi.
1 parent84a3634 commit75586cb

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

‎src/backend/commands/indexcmds.c

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
/*-------------------------------------------------------------------------
22
*
33
* indexcmds.c
4-
* POSTGRES define, extend and remove index code.
4+
* POSTGRES define and remove index code.
55
*
66
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.52 2001/07/16 05:06:57 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.53 2001/07/17 21:53:01 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -39,8 +39,10 @@
3939
#include"parser/parse_type.h"
4040
#include"utils/builtins.h"
4141
#include"utils/fmgroids.h"
42+
#include"utils/lsyscache.h"
4243
#include"utils/syscache.h"
4344

45+
4446
#defineIsFuncIndex(ATTR_LIST) (((IndexElem*)lfirst(ATTR_LIST))->args != NIL)
4547

4648
/* non-export function prototypes */
@@ -232,10 +234,21 @@ CheckPredicate(List *predList, List *rangeTable, Oid baseRelOid)
232234
elog(ERROR,
233235
"Partial-index predicates may refer only to the base relation");
234236

237+
/*
238+
* We don't currently support generation of an actual query plan for a
239+
* predicate, only simple scalar expressions; hence these restrictions.
240+
*/
235241
if (contain_subplans((Node*)predList))
236242
elog(ERROR,"Cannot use subselect in index predicate");
237243
if (contain_agg_clause((Node*)predList))
238244
elog(ERROR,"Cannot use aggregate in index predicate");
245+
246+
/*
247+
* A predicate using noncachable functions is probably wrong, for the
248+
* same reasons that we don't allow a functional index to use one.
249+
*/
250+
if (contain_noncachable_functions((Node*)predList))
251+
elog(ERROR,"Cannot use non-cachable function in index predicate");
239252
}
240253

241254

@@ -308,6 +321,15 @@ FuncIndexArgs(IndexInfo *indexInfo,
308321
"Index function must be binary-compatible with table datatype");
309322
}
310323

324+
/*
325+
* Require that the function be marked cachable. Using a noncachable
326+
* function for a functional index is highly questionable, since if you
327+
* aren't going to get the same result for the same data every time,
328+
* it's not clear what the index entries mean at all.
329+
*/
330+
if (!func_iscachable(funcid))
331+
elog(ERROR,"DefineIndex: index function must be marked iscachable");
332+
311333
/* Process opclass, using func return type as default type */
312334

313335
classOidP[0]=GetAttrOpClass(funcIndex,rettype,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp