Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 473af39

Browse files
Add missing optimizer hooks for function cost and number of rows.
Closely follow design of other optimizer hooks: if hook exists retrieve value from plugin; if still not set then get from cache.
1 parent 491d1ea commit 473af39

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/backend/utils/cache/lsyscache.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/src/backend/utils/cache/lsyscache.c,v 1.168 2010/02/26 02:01:11 momjian Exp $
10+
* $PostgreSQL: pgsql/src/backend/utils/cache/lsyscache.c,v 1.169 2010/04/23 22:23:39 sriggs Exp $
1111
*
1212
* NOTES
1313
* Eventually, the index information should go through here, too.
@@ -38,6 +38,9 @@
3838
/* Hook for plugins to get control in get_attavgwidth() */
3939
get_attavgwidth_hook_type get_attavgwidth_hook = NULL;
4040

41+
/* Hook for plugins to get control in get_func_cost and get_func_rows */
42+
get_func_cost_hook_type get_func_cost_hook = NULL;
43+
get_func_rows_hook_type get_func_rows_hook = NULL;
4144

4245
/* ---------- AMOP CACHES ---------- */
4346

@@ -1409,6 +1412,12 @@ get_func_cost(Oid funcid)
14091412
HeapTuple tp;
14101413
float4 result;
14111414

1415+
if (get_func_cost_hook)
1416+
{
1417+
result = (*get_func_cost_hook) (funcid);
1418+
if (result > (float4) 0)
1419+
return result;
1420+
}
14121421
tp = SearchSysCache1(PROCOID, ObjectIdGetDatum(funcid));
14131422
if (!HeapTupleIsValid(tp))
14141423
elog(ERROR, "cache lookup failed for function %u", funcid);
@@ -1428,6 +1437,12 @@ get_func_rows(Oid funcid)
14281437
HeapTuple tp;
14291438
float4 result;
14301439

1440+
if (get_func_rows_hook)
1441+
{
1442+
result = (*get_func_rows_hook) (funcid);
1443+
if (result > (float4) 0)
1444+
return result;
1445+
}
14311446
tp = SearchSysCache1(PROCOID, ObjectIdGetDatum(funcid));
14321447
if (!HeapTupleIsValid(tp))
14331448
elog(ERROR, "cache lookup failed for function %u", funcid);

src/include/utils/lsyscache.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $PostgreSQL: pgsql/src/include/utils/lsyscache.h,v 1.131 2010/01/04 02:44:40 tgl Exp $
9+
* $PostgreSQL: pgsql/src/include/utils/lsyscache.h,v 1.132 2010/04/23 22:23:39 sriggs Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -30,6 +30,12 @@ typedef enum IOFuncSelector
3030
typedef int32 (*get_attavgwidth_hook_type) (Oid relid, AttrNumber attnum);
3131
extern PGDLLIMPORT get_attavgwidth_hook_type get_attavgwidth_hook;
3232

33+
/* Hook for plugins to get control in get_func_cost and get_func_rows */
34+
typedef float4 (*get_func_cost_hook_type) (Oid funcid);
35+
extern PGDLLIMPORT get_func_cost_hook_type get_func_cost_hook;
36+
typedef float4 (*get_func_rows_hook_type) (Oid funcid);
37+
extern PGDLLIMPORT get_func_rows_hook_type get_func_rows_hook;
38+
3339
extern bool op_in_opfamily(Oid opno, Oid opfamily);
3440
extern int get_op_opfamily_strategy(Oid opno, Oid opfamily);
3541
extern void get_op_opfamily_properties(Oid opno, Oid opfamily,

0 commit comments

Comments
 (0)