mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
Replace slightly klugy create_bitmap_restriction() function with a
more efficient routine in restrictinfo.c (which can make use of make_restrictinfo_internal).
This commit is contained in:
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/backend/optimizer/path/orindxpath.c,v 1.69 2005/04/25 01:30:13 tgl Exp $
|
* $PostgreSQL: pgsql/src/backend/optimizer/path/orindxpath.c,v 1.70 2005/04/25 02:14:47 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -146,7 +146,8 @@ create_or_index_quals(Query *root, RelOptInfo *rel)
|
|||||||
* Convert the path's indexclauses structure to a RestrictInfo tree,
|
* Convert the path's indexclauses structure to a RestrictInfo tree,
|
||||||
* and add it to the rel's restriction list.
|
* and add it to the rel's restriction list.
|
||||||
*/
|
*/
|
||||||
newrinfos = create_bitmap_restriction((Path *) bestpath);
|
newrinfos = make_restrictinfo_from_bitmapqual((Path *) bestpath,
|
||||||
|
true, true);
|
||||||
Assert(list_length(newrinfos) == 1);
|
Assert(list_length(newrinfos) == 1);
|
||||||
or_rinfo = (RestrictInfo *) linitial(newrinfos);
|
or_rinfo = (RestrictInfo *) linitial(newrinfos);
|
||||||
Assert(IsA(or_rinfo, RestrictInfo));
|
Assert(IsA(or_rinfo, RestrictInfo));
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/backend/optimizer/plan/createplan.c,v 1.185 2005/04/25 01:30:13 tgl Exp $
|
* $PostgreSQL: pgsql/src/backend/optimizer/plan/createplan.c,v 1.186 2005/04/25 02:14:47 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -54,7 +54,6 @@ static BitmapHeapScan *create_bitmap_scan_plan(Query *root,
|
|||||||
List *tlist, List *scan_clauses);
|
List *tlist, List *scan_clauses);
|
||||||
static Plan *create_bitmap_subplan(Query *root, Path *bitmapqual,
|
static Plan *create_bitmap_subplan(Query *root, Path *bitmapqual,
|
||||||
List **qual, List **indexqual);
|
List **qual, List **indexqual);
|
||||||
static List *create_bitmap_qual(Path *bitmapqual);
|
|
||||||
static TidScan *create_tidscan_plan(Query *root, TidPath *best_path,
|
static TidScan *create_tidscan_plan(Query *root, TidPath *best_path,
|
||||||
List *tlist, List *scan_clauses);
|
List *tlist, List *scan_clauses);
|
||||||
static SubqueryScan *create_subqueryscan_plan(Query *root, Path *best_path,
|
static SubqueryScan *create_subqueryscan_plan(Query *root, Path *best_path,
|
||||||
@ -981,86 +980,6 @@ create_bitmap_subplan(Query *root, Path *bitmapqual,
|
|||||||
return plan;
|
return plan;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Given a bitmapqual tree, generate the equivalent ordinary expression tree
|
|
||||||
* (which we need for the bitmapqualorig field of the BitmapHeapScan plan).
|
|
||||||
* The result is expressed as an implicit-AND list.
|
|
||||||
*/
|
|
||||||
static List *
|
|
||||||
create_bitmap_qual(Path *bitmapqual)
|
|
||||||
{
|
|
||||||
List *result;
|
|
||||||
List *sublist;
|
|
||||||
|
|
||||||
if (IsA(bitmapqual, BitmapAndPath))
|
|
||||||
{
|
|
||||||
BitmapAndPath *apath = (BitmapAndPath *) bitmapqual;
|
|
||||||
ListCell *l;
|
|
||||||
|
|
||||||
result = NIL;
|
|
||||||
foreach(l, apath->bitmapquals)
|
|
||||||
{
|
|
||||||
sublist = create_bitmap_qual(lfirst(l));
|
|
||||||
result = list_concat(result, sublist);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (IsA(bitmapqual, BitmapOrPath))
|
|
||||||
{
|
|
||||||
BitmapOrPath *opath = (BitmapOrPath *) bitmapqual;
|
|
||||||
List *newlist = NIL;
|
|
||||||
ListCell *l;
|
|
||||||
|
|
||||||
foreach(l, opath->bitmapquals)
|
|
||||||
{
|
|
||||||
sublist = create_bitmap_qual(lfirst(l));
|
|
||||||
if (sublist == NIL)
|
|
||||||
{
|
|
||||||
/* constant TRUE input yields constant TRUE OR result */
|
|
||||||
return NIL;
|
|
||||||
}
|
|
||||||
newlist = lappend(newlist, make_ands_explicit(sublist));
|
|
||||||
}
|
|
||||||
result = list_make1(make_orclause(newlist));
|
|
||||||
}
|
|
||||||
else if (IsA(bitmapqual, IndexPath))
|
|
||||||
{
|
|
||||||
IndexPath *ipath = (IndexPath *) bitmapqual;
|
|
||||||
|
|
||||||
result = get_actual_clauses(ipath->indexclauses);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
elog(ERROR, "unrecognized node type: %d", nodeTag(bitmapqual));
|
|
||||||
result = NIL; /* keep compiler quiet */
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Given a bitmapqual tree, generate the equivalent RestrictInfo list.
|
|
||||||
*/
|
|
||||||
List *
|
|
||||||
create_bitmap_restriction(Path *bitmapqual)
|
|
||||||
{
|
|
||||||
List *bitmapquals;
|
|
||||||
List *bitmapclauses;
|
|
||||||
ListCell *l;
|
|
||||||
|
|
||||||
bitmapquals = create_bitmap_qual(bitmapqual);
|
|
||||||
|
|
||||||
/* must convert qual list to restrictinfos ... painful ... */
|
|
||||||
bitmapclauses = NIL;
|
|
||||||
foreach(l, bitmapquals)
|
|
||||||
{
|
|
||||||
bitmapclauses = lappend(bitmapclauses,
|
|
||||||
make_restrictinfo((Expr *) lfirst(l),
|
|
||||||
true, true));
|
|
||||||
}
|
|
||||||
|
|
||||||
return bitmapclauses;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* create_tidscan_plan
|
* create_tidscan_plan
|
||||||
* Returns a tidscan plan for the base relation scanned by 'best_path'
|
* Returns a tidscan plan for the base relation scanned by 'best_path'
|
||||||
@ -1210,7 +1129,9 @@ create_nestloop_plan(Query *root,
|
|||||||
{
|
{
|
||||||
List *bitmapclauses;
|
List *bitmapclauses;
|
||||||
|
|
||||||
bitmapclauses = create_bitmap_restriction(innerpath->bitmapqual);
|
bitmapclauses =
|
||||||
|
make_restrictinfo_from_bitmapqual(innerpath->bitmapqual,
|
||||||
|
true, true);
|
||||||
joinrestrictclauses =
|
joinrestrictclauses =
|
||||||
select_nonredundant_join_clauses(root,
|
select_nonredundant_join_clauses(root,
|
||||||
joinrestrictclauses,
|
joinrestrictclauses,
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/backend/optimizer/util/restrictinfo.c,v 1.34 2005/04/25 01:30:13 tgl Exp $
|
* $PostgreSQL: pgsql/src/backend/optimizer/util/restrictinfo.c,v 1.35 2005/04/25 02:14:47 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -65,10 +65,95 @@ make_restrictinfo(Expr *clause, bool is_pushed_down, bool valid_everywhere)
|
|||||||
is_pushed_down, valid_everywhere);
|
is_pushed_down, valid_everywhere);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* make_restrictinfo_from_bitmapqual
|
||||||
|
*
|
||||||
|
* Given the bitmapqual Path structure for a bitmap indexscan, generate
|
||||||
|
* RestrictInfo node(s) equivalent to the condition represented by the
|
||||||
|
* indexclauses of the Path structure.
|
||||||
|
*
|
||||||
|
* The result is a List since we might need to return multiple RestrictInfos.
|
||||||
|
*
|
||||||
|
* To do this through the normal make_restrictinfo() API, callers would have
|
||||||
|
* to strip off the RestrictInfo nodes present in the indexclauses lists, and
|
||||||
|
* then make_restrictinfo() would have to build new ones. It's better to have
|
||||||
|
* a specialized routine to allow sharing of RestrictInfos.
|
||||||
|
*/
|
||||||
|
List *
|
||||||
|
make_restrictinfo_from_bitmapqual(Path *bitmapqual,
|
||||||
|
bool is_pushed_down,
|
||||||
|
bool valid_everywhere)
|
||||||
|
{
|
||||||
|
List *result;
|
||||||
|
|
||||||
|
if (IsA(bitmapqual, BitmapAndPath))
|
||||||
|
{
|
||||||
|
BitmapAndPath *apath = (BitmapAndPath *) bitmapqual;
|
||||||
|
ListCell *l;
|
||||||
|
|
||||||
|
result = NIL;
|
||||||
|
foreach(l, apath->bitmapquals)
|
||||||
|
{
|
||||||
|
List *sublist;
|
||||||
|
|
||||||
|
sublist = make_restrictinfo_from_bitmapqual((Path *) lfirst(l),
|
||||||
|
is_pushed_down,
|
||||||
|
valid_everywhere);
|
||||||
|
result = list_concat(result, sublist);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (IsA(bitmapqual, BitmapOrPath))
|
||||||
|
{
|
||||||
|
BitmapOrPath *opath = (BitmapOrPath *) bitmapqual;
|
||||||
|
List *withris = NIL;
|
||||||
|
List *withoutris = NIL;
|
||||||
|
ListCell *l;
|
||||||
|
|
||||||
|
foreach(l, opath->bitmapquals)
|
||||||
|
{
|
||||||
|
List *sublist;
|
||||||
|
|
||||||
|
sublist = make_restrictinfo_from_bitmapqual((Path *) lfirst(l),
|
||||||
|
is_pushed_down,
|
||||||
|
valid_everywhere);
|
||||||
|
if (sublist == NIL)
|
||||||
|
{
|
||||||
|
/* constant TRUE input yields constant TRUE OR result */
|
||||||
|
/* (though this probably cannot happen) */
|
||||||
|
return NIL;
|
||||||
|
}
|
||||||
|
/* Create AND subclause with RestrictInfos */
|
||||||
|
withris = lappend(withris, make_ands_explicit(sublist));
|
||||||
|
/* And one without */
|
||||||
|
sublist = get_actual_clauses(sublist);
|
||||||
|
withoutris = lappend(withoutris, make_ands_explicit(sublist));
|
||||||
|
}
|
||||||
|
/* Here's the magic part not available to outside callers */
|
||||||
|
result =
|
||||||
|
list_make1(make_restrictinfo_internal(make_orclause(withoutris),
|
||||||
|
make_orclause(withris),
|
||||||
|
is_pushed_down,
|
||||||
|
valid_everywhere));
|
||||||
|
}
|
||||||
|
else if (IsA(bitmapqual, IndexPath))
|
||||||
|
{
|
||||||
|
IndexPath *ipath = (IndexPath *) bitmapqual;
|
||||||
|
|
||||||
|
result = list_copy(ipath->indexclauses);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
elog(ERROR, "unrecognized node type: %d", nodeTag(bitmapqual));
|
||||||
|
result = NIL; /* keep compiler quiet */
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* make_restrictinfo_internal
|
* make_restrictinfo_internal
|
||||||
*
|
*
|
||||||
* Common code for the main entry point and the recursive cases.
|
* Common code for the main entry points and the recursive cases.
|
||||||
*/
|
*/
|
||||||
static RestrictInfo *
|
static RestrictInfo *
|
||||||
make_restrictinfo_internal(Expr *clause, Expr *orclause,
|
make_restrictinfo_internal(Expr *clause, Expr *orclause,
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
|
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $PostgreSQL: pgsql/src/include/optimizer/planmain.h,v 1.83 2005/04/25 01:30:14 tgl Exp $
|
* $PostgreSQL: pgsql/src/include/optimizer/planmain.h,v 1.84 2005/04/25 02:14:48 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -33,7 +33,6 @@ extern Plan *optimize_minmax_aggregates(Query *root, List *tlist,
|
|||||||
* prototypes for plan/createplan.c
|
* prototypes for plan/createplan.c
|
||||||
*/
|
*/
|
||||||
extern Plan *create_plan(Query *root, Path *best_path);
|
extern Plan *create_plan(Query *root, Path *best_path);
|
||||||
extern List *create_bitmap_restriction(Path *bitmapqual);
|
|
||||||
extern SubqueryScan *make_subqueryscan(List *qptlist, List *qpqual,
|
extern SubqueryScan *make_subqueryscan(List *qptlist, List *qpqual,
|
||||||
Index scanrelid, Plan *subplan);
|
Index scanrelid, Plan *subplan);
|
||||||
extern Append *make_append(List *appendplans, bool isTarget, List *tlist);
|
extern Append *make_append(List *appendplans, bool isTarget, List *tlist);
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
|
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $PostgreSQL: pgsql/src/include/optimizer/restrictinfo.h,v 1.28 2005/04/25 01:30:14 tgl Exp $
|
* $PostgreSQL: pgsql/src/include/optimizer/restrictinfo.h,v 1.29 2005/04/25 02:14:48 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -18,6 +18,9 @@
|
|||||||
|
|
||||||
extern RestrictInfo *make_restrictinfo(Expr *clause, bool is_pushed_down,
|
extern RestrictInfo *make_restrictinfo(Expr *clause, bool is_pushed_down,
|
||||||
bool valid_everywhere);
|
bool valid_everywhere);
|
||||||
|
extern List *make_restrictinfo_from_bitmapqual(Path *bitmapqual,
|
||||||
|
bool is_pushed_down,
|
||||||
|
bool valid_everywhere);
|
||||||
extern bool restriction_is_or_clause(RestrictInfo *restrictinfo);
|
extern bool restriction_is_or_clause(RestrictInfo *restrictinfo);
|
||||||
extern List *get_actual_clauses(List *restrictinfo_list);
|
extern List *get_actual_clauses(List *restrictinfo_list);
|
||||||
extern void get_actual_join_clauses(List *restrictinfo_list,
|
extern void get_actual_join_clauses(List *restrictinfo_list,
|
||||||
|
Reference in New Issue
Block a user