mirror of
https://github.com/postgres/postgres.git
synced 2025-07-05 07:21:24 +03:00
Allow merge and hash joins to occur on arbitrary expressions (anything not
containing a volatile function), rather than only on 'Var = Var' clauses as before. This makes it practical to do flatten_join_alias_vars at the start of planning, which in turn eliminates a bunch of klugery inside the planner to deal with alias vars. As a free side effect, we now detect implied equality of non-Var expressions; for example in SELECT ... WHERE a.x = b.y and b.y = 42 we will deduce a.x = 42 and use that as a restriction qual on a. Also, we can remove the restriction introduced 12/5/02 to prevent pullup of subqueries whose targetlists contain sublinks. Still TODO: make statistical estimation routines in selfuncs.c and costsize.c smarter about expressions that are more complex than plain Vars. The need for this is considerably greater now that we have to be able to estimate the suitability of merge and hash join techniques on such expressions.
This commit is contained in:
26
src/backend/utils/cache/lsyscache.c
vendored
26
src/backend/utils/cache/lsyscache.c
vendored
@ -7,7 +7,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/cache/lsyscache.c,v 1.88 2002/12/05 04:04:44 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/cache/lsyscache.c,v 1.89 2003/01/15 19:35:44 tgl Exp $
|
||||
*
|
||||
* NOTES
|
||||
* Eventually, the index information should go through here, too.
|
||||
@ -315,11 +315,11 @@ get_opname(Oid opno)
|
||||
/*
|
||||
* op_mergejoinable
|
||||
*
|
||||
* Returns the left and right sort operators and types corresponding to a
|
||||
* mergejoinable operator, or nil if the operator is not mergejoinable.
|
||||
* Returns the left and right sort operators corresponding to a
|
||||
* mergejoinable operator, or false if the operator is not mergejoinable.
|
||||
*/
|
||||
bool
|
||||
op_mergejoinable(Oid opno, Oid ltype, Oid rtype, Oid *leftOp, Oid *rightOp)
|
||||
op_mergejoinable(Oid opno, Oid *leftOp, Oid *rightOp)
|
||||
{
|
||||
HeapTuple tp;
|
||||
bool result = false;
|
||||
@ -332,9 +332,7 @@ op_mergejoinable(Oid opno, Oid ltype, Oid rtype, Oid *leftOp, Oid *rightOp)
|
||||
Form_pg_operator optup = (Form_pg_operator) GETSTRUCT(tp);
|
||||
|
||||
if (optup->oprlsortop &&
|
||||
optup->oprrsortop &&
|
||||
optup->oprleft == ltype &&
|
||||
optup->oprright == rtype)
|
||||
optup->oprrsortop)
|
||||
{
|
||||
*leftOp = optup->oprlsortop;
|
||||
*rightOp = optup->oprrsortop;
|
||||
@ -391,14 +389,13 @@ op_mergejoin_crossops(Oid opno, Oid *ltop, Oid *gtop,
|
||||
/*
|
||||
* op_hashjoinable
|
||||
*
|
||||
* Returns the hash operator corresponding to a hashjoinable operator,
|
||||
* or InvalidOid if the operator is not hashjoinable.
|
||||
* Returns true if the operator is hashjoinable.
|
||||
*/
|
||||
Oid
|
||||
op_hashjoinable(Oid opno, Oid ltype, Oid rtype)
|
||||
bool
|
||||
op_hashjoinable(Oid opno)
|
||||
{
|
||||
HeapTuple tp;
|
||||
Oid result = InvalidOid;
|
||||
bool result = false;
|
||||
|
||||
tp = SearchSysCache(OPEROID,
|
||||
ObjectIdGetDatum(opno),
|
||||
@ -407,10 +404,7 @@ op_hashjoinable(Oid opno, Oid ltype, Oid rtype)
|
||||
{
|
||||
Form_pg_operator optup = (Form_pg_operator) GETSTRUCT(tp);
|
||||
|
||||
if (optup->oprcanhash &&
|
||||
optup->oprleft == ltype &&
|
||||
optup->oprright == rtype)
|
||||
result = opno;
|
||||
result = optup->oprcanhash;
|
||||
ReleaseSysCache(tp);
|
||||
}
|
||||
return result;
|
||||
|
Reference in New Issue
Block a user