Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 4d58a7c

Browse files
committed
Optimizer can now estimate selectivity of IS NULL, IS NOT NULL,
IS TRUE, etc, with some degree of verisimilitude. Split out selectivity support functions from builtins.h into a new header file selfuncs.h, so as to reduce the number of header files builtins.h must depend on. Fix a few missing inclusions exposed thereby. From Joe Conway, with some kibitzing from Tom Lane.
1 parent c31545a commit 4d58a7c

File tree

9 files changed

+439
-68
lines changed

9 files changed

+439
-68
lines changed

src/backend/access/common/tupdesc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/common/tupdesc.c,v 1.74 2001/05/07 00:43:15 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/common/tupdesc.c,v 1.75 2001/06/25 21:11:43 tgl Exp $
1212
*
1313
* NOTES
1414
* some of the executor utility code such as "ExecTypeFromTL" should be
@@ -20,6 +20,7 @@
2020
#include "postgres.h"
2121

2222
#include "catalog/pg_type.h"
23+
#include "nodes/parsenodes.h"
2324
#include "parser/parse_type.h"
2425
#include "utils/builtins.h"
2526
#include "utils/syscache.h"

src/backend/commands/comment.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@
77
* Copyright (c) 1999-2001, PostgreSQL Global Development Group
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/commands/comment.c,v 1.30 2001/06/13 21:44:40 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/commands/comment.c,v 1.31 2001/06/25 21:11:43 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
1414

1515
#include "postgres.h"
1616

17-
#include "utils/builtins.h"
1817
#include "access/heapam.h"
1918
#include "catalog/catname.h"
2019
#include "catalog/indexing.h"
@@ -26,11 +25,12 @@
2625
#include "catalog/pg_class.h"
2726
#include "commands/comment.h"
2827
#include "miscadmin.h"
29-
#include "parser/parse.h"
3028
#include "parser/parse_expr.h"
3129
#include "parser/parse_func.h"
30+
#include "parser/parse.h"
3231
#include "rewrite/rewriteRemove.h"
3332
#include "utils/acl.h"
33+
#include "utils/builtins.h"
3434
#include "utils/fmgroids.h"
3535
#include "utils/syscache.h"
3636

@@ -717,7 +717,7 @@ CommentOperator(char *opername, List *arguments, char *comment)
717717
/*** Get the procedure associated with the operator ***/
718718

719719
data = (Form_pg_operator) GETSTRUCT(optuple);
720-
oid = RegprocToOid(data->oprcode);
720+
oid = data->oprcode;
721721
if (oid == InvalidOid)
722722
elog(ERROR, "operator '%s' does not have an underlying function", opername);
723723

src/backend/optimizer/path/clausesel.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/clausesel.c,v 1.45 2001/06/05 05:26:04 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/clausesel.c,v 1.46 2001/06/25 21:11:43 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -24,6 +24,7 @@
2424
#include "parser/parsetree.h"
2525
#include "utils/fmgroids.h"
2626
#include "utils/lsyscache.h"
27+
#include "utils/selfuncs.h"
2728

2829

2930
/* note that pg_type.h hardwires size of bool as 1 ... duplicate it */
@@ -509,6 +510,16 @@ clause_selectivity(Query *root,
509510
*/
510511
s1 = (Selectivity) 0.5;
511512
}
513+
else if (IsA(clause, NullTest))
514+
{
515+
/* Use node specific selectivity calculation function */
516+
s1 = nulltestsel(root, (NullTest *) clause, varRelid);
517+
}
518+
else if (IsA(clause, BooleanTest))
519+
{
520+
/* Use node specific selectivity calculation function */
521+
s1 = booltestsel(root, (BooleanTest *) clause, varRelid);
522+
}
512523
else if (IsA(clause, RelabelType))
513524
{
514525
/* Not sure this case is needed, but it can't hurt */
@@ -517,5 +528,9 @@ clause_selectivity(Query *root,
517528
varRelid);
518529
}
519530

531+
#ifdef SELECTIVITY_DEBUG
532+
elog(NOTICE, "clause_selectivity: s1 %f", s1);
533+
#endif /* SELECTIVITY_DEBUG */
534+
520535
return s1;
521536
}

src/backend/optimizer/path/indxpath.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/indxpath.c,v 1.107 2001/06/17 02:05:19 tgl Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/indxpath.c,v 1.108 2001/06/25 21:11:43 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -37,6 +37,7 @@
3737
#include "utils/builtins.h"
3838
#include "utils/fmgroids.h"
3939
#include "utils/lsyscache.h"
40+
#include "utils/selfuncs.h"
4041
#include "utils/syscache.h"
4142

4243

src/backend/parser/analyze.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.190 2001/06/23 00:07:34 momjian Exp $
9+
* $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.191 2001/06/25 21:11:44 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -33,6 +33,7 @@
3333
#include "rewrite/rewriteManip.h"
3434
#include "utils/builtins.h"
3535
#include "utils/fmgroids.h"
36+
#include "utils/numeric.h"
3637
#include "utils/relcache.h"
3738
#include "utils/syscache.h"
3839

src/backend/utils/adt/formatting.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* -----------------------------------------------------------------------
22
* formatting.c
33
*
4-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/formatting.c,v 1.37 2001/05/03 22:53:07 tgl Exp $
4+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/formatting.c,v 1.38 2001/06/25 21:11:44 tgl Exp $
55
*
66
*
77
* Portions Copyright (c) 1999-2000, PostgreSQL Global Development Group
@@ -67,21 +67,23 @@
6767
#define DEBUG_elog_output NOTICE
6868
***/
6969

70-
#include <stdio.h>
71-
#include <string.h>
70+
#include "postgres.h"
71+
7272
#include <ctype.h>
7373
#include <sys/time.h>
7474
#include <unistd.h>
75+
#ifdef USE_LOCALE
7576
#include <locale.h>
77+
#endif
7678
#include <math.h>
7779
#include <float.h>
7880

79-
#include "postgres.h"
8081
#include "utils/builtins.h"
8182
#include "utils/date.h"
8283
#include "utils/datetime.h"
8384
#include "utils/formatting.h"
8485
#include "utils/int8.h"
86+
#include "utils/numeric.h"
8587
#include "utils/pg_locale.h"
8688

8789
/* ----------

0 commit comments

Comments
 (0)