Changeset: 56e5fab72fb4 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/56e5fab72fb4
Removed Files:
        sql/server/rel_out2inner_join.txt
        sql/server/rel_planner.c
        sql/server/rel_planner.h
Modified Files:
        sql/server/CMakeLists.txt
        sql/server/rel_optimize_sel.c
Branch: default
Log Message:

Remove legacy rel_planner code. Remove out2inner txt.


diffs (truncated from 1128 to 300 lines):

diff --git a/sql/server/CMakeLists.txt b/sql/server/CMakeLists.txt
--- a/sql/server/CMakeLists.txt
+++ b/sql/server/CMakeLists.txt
@@ -51,7 +51,6 @@ target_sources(sqlserver
   rel_optimize_others.c
   rel_optimize_proj.c
   rel_optimize_sel.c
-  rel_planner.c rel_planner.h
   rel_distribute.c
   rel_remote.c rel_remote.h
   rel_propagate.c rel_propagate.h
diff --git a/sql/server/rel_optimize_sel.c b/sql/server/rel_optimize_sel.c
--- a/sql/server/rel_optimize_sel.c
+++ b/sql/server/rel_optimize_sel.c
@@ -10,7 +10,6 @@
 
 #include "monetdb_config.h"
 #include "rel_optimizer_private.h"
-#include "rel_planner.h"
 #include "rel_exp.h"
 #include "rel_select.h"
 #include "rel_rewriter.h"
@@ -2309,10 +2308,6 @@ order_joins(visitor *v, list *rels, list
                sql_exp *e = djn->data;
                list_remove_data(exps, NULL, e);
        }
-       if (list_length(rels) > 2 && mvc_debug_on(v->sql, 256)) {
-               top =  rel_planner(v->sql, rels, sdje, exps);
-               return top;
-       }
 
        allocator *ta = MT_thread_getallocator();
        int nr_exps = list_length(sdje), nr_rels = list_length(rels), ci = 1;
@@ -3922,7 +3917,7 @@ rel_push_select_down(visitor *v, sql_rel
                        set_distinct(rel);
                v->changes++;
        }
-       if (is_select(rel->op) && !exps_has_group_filter(rel->exps) && 
+       if (is_select(rel->op) && !exps_has_group_filter(rel->exps) &&
            r && is_munion(r->op) && !is_recursive(r) && !list_empty(r->exps) 
&& !rel_is_ref(r) && !is_single(r) && !list_empty(exps)) {
                sql_rel *u = r;
                list *rels = u->l, *nrels = sa_list(v->sql->sa);
diff --git a/sql/server/rel_out2inner_join.txt 
b/sql/server/rel_out2inner_join.txt
deleted file mode 100644
--- a/sql/server/rel_out2inner_join.txt
+++ /dev/null
@@ -1,95 +0,0 @@
-Introduction 
-
-Say we have two single integer column tables foo and bar with the following 
content:
-
-create table foo (i int);
-insert into foo values (10), (40), (20), (5);
-
-create table bar (i int, j int);
-insert into bar values (30, 300), (20, 200), (50, 500), (40, 400);
-
-select * from foo;
-+------+
-| i    |
-+======+
-|   10 |
-|   40 |
-|   20 |
-|    5 |
-+------+
-select * from bar;
-+------+
-| i    |
-+======+
-|   30 |
-|   20 |
-|   50 |
-|   40 |
-+------+
-
-We compute the following outer join
-select foo.i, bar.i from foo left join bar on foo.i = bar.i where bar.j is not 
null;
-+------+------+
-| i    | i    |
-+======+======+
-|   40 |   40 |
-|   20 |   20 |
-+------+------+
-
-The plan currently generated for this query is given by
-+---------------------------------------------------+
-| rel                                               |
-+===================================================+
-| project (                                         |
-| | select (                                        |
-| | | left outer join (                             |
-| | | | table(sys.foo) [ "foo"."i" ] COUNT ,        |
-| | | | table(sys.bar) [ "bar"."i" ] COUNT          |
-| | | ) [ "foo"."i" = "bar"."i" ]                   |
-| | ) [ int "NULL" ! <= "bar"."i" ! <= int "NULL" ] |
-| ) [ "foo"."i", "bar"."i" ]                        |
-+---------------------------------------------------+
-
-Notice that the select's filter expression 'bar.i is not null' has the effect 
that all tuples that are in the asymmetric difference foo excluding bar are 
filtered from the result set of the outer join. For any outer join X left join 
Y, we call such a filter that depends on the inner part Y of the outer join, a 
null-rejecting predicate in Y if the predicate evaluates to false if one or 
more of the attributes in Y is NULL.
-
-We can improve the plan in the case of an outer join followed by a select 
containing a null-rejecting predicate on the inner part of the outer join by 
transforming the outer join into an inner join.
-
-So in the above example we can change the plan to 
-
-+---------------------------------------------------+
-| rel                                               |
-+===================================================+
-| project (                                         |
-| | select (                                        |
-| | | join (                                        |
-| | | | table(sys.foo) [ "foo"."i" ] COUNT ,        |
-| | | | table(sys.bar) [ "bar"."i" ] COUNT          |
-| | | ) [ "foo"."i" = "bar"."i" ]                   |
-| | ) [ int "NULL" ! <= "bar"."i" ! <= int "NULL" ] |
-| ) [ "foo"."i", "bar"."i" ]                        |
-+---------------------------------------------------+
-
-This should even allow for more optimization like potentially pushing down the 
select underneath the join or even removing it in its entirety.
-
-step 1: figure out at a suitable moment in the relational optimizer when a 
plan containing a select and an outer join has a high probability of looking 
like this
-
-select(
-    left_join(
-        L,
-        R,
-        j_pred
-    ),
-    s_pred
-)
-
-step 2: create a temporary copy of the s_pred
-step 2: assume that j_pred is always a list of expressions type e_cmp or e_or. 
where the comma in the list represents logical AND.
-step 3: create a list of the sub-expression's of s_pred.
-step 3: find all column references to the inner side R of the left join and 
for each subset of the total set column references replace them with an atomic 
null in this list of expressions. 
-step 4: for each element in the j_pred's list of filter expressions that is of 
type e_cmp. check
-
-1) if e_cmp is of type =-semantics or is-semantics.
-    if =-semantics apply is_null check on each of the operand terms in the 
e_cmp expression if there  is a null term then null rejection applies 
-    else if is-semantics we must check if the e_cmp expression is of the form 
'r is not null' to have null rejection
-    else we are not sure and null-jection is false.
-2) else if the expression is of type e_or, we require that both terms of e_or 
are null rejecting which is a recursive traversal until we have reached terms 
of e_cmp for which the previously described procedure 1) applies to check null 
rejection.
diff --git a/sql/server/rel_planner.c b/sql/server/rel_planner.c
deleted file mode 100644
--- a/sql/server/rel_planner.c
+++ /dev/null
@@ -1,957 +0,0 @@
-/*
- * SPDX-License-Identifier: MPL-2.0
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0.  If a copy of the MPL was not distributed with this
- * file, You can obtain one at https://mozilla.org/MPL/2.0/.
- *
- * For copyright information, see the file debian/copyright.
- */
-
-#include "monetdb_config.h"
-#include "rel_planner.h"
-#include "rel_rel.h"
-#include "rel_exp.h"
-#include "rel_prop.h"
-#include "rel_rewriter.h"
-#include "sql_storage.h"
-
-typedef struct memoitem {
-       const char *name;
-       list *rels;
-       list *exps;
-       list *joins;
-       int done;
-       int level;
-       lng count;
-       lng width;
-       dbl cost;
-       void *data;
-} memoitem;
-
-#define p_pkey 1
-#define p_fkey 2
-#define p_ukey 3
-
-typedef struct memojoin {
-       memoitem *l, *r;
-       int rules;      /* handled rules */
-       int prop;       /* pkey, fkey, ukey */
-       dbl cost;
-       dbl sel;
-       sql_exp *e;
-} memojoin;
-
-static int
-memoitem_key( memoitem *mi )
-{
-       return hash_key(mi->name);
-}
-
-static memoitem*
-memo_find(list *memo, const char *name)
-{
-       int key = hash_key(name);
-       sql_hash_e *he;
-
-       he = memo->ht->buckets[key&(memo->ht->size-1)];
-       for (; he; he = he->chain) {
-               memoitem *mi = he->value;
-
-               if (mi->name && strcmp(mi->name, name) == 0)
-                       return mi;
-       }
-       return NULL;
-}
-
-static char *
-merge_names( allocator *sa, const char *lname, const char *rname)
-{
-       size_t l = strlen(lname) + strlen(rname) + 2;
-       char *n = SA_NEW_ARRAY(sa, char, l);
-       const char *p = lname;
-       const char *c;
-
-       while ((c = strchr(p, ',')) != NULL) {
-               if (strncmp(p, rname, c - p) > 0) {
-                       if (p > lname)
-                               snprintf(n, l, "%.*s,%s,%s", (int) (c - lname),
-                                        lname, rname, c + 1);
-                       else
-                               snprintf(n, l, "%s,%s", rname, lname);
-                       return n;
-               }
-               p = c + 1;
-       }
-       snprintf(n, l, "%s,%s", lname, rname);
-       return n;
-}
-
-static memoitem *
-memoitem_create( list *memo, allocator *sa, const char *lname, const char 
*rname, int level)
-{
-       const char *name = lname;
-       memoitem *mi;
-
-       if (level > 1)
-               name = merge_names(sa, lname, rname);
-       if (memo_find(memo, name))
-               return NULL;
-               mi = SA_NEW(sa, memoitem);
-       mi->name = ma_strdup(sa, name);
-       mi->joins = (rname)?sa_list(sa):NULL;
-       mi->done = (rname)?0:1;
-       mi->level = level;
-       mi->count = 1;
-       mi->cost = 0;
-       mi->width = 8;
-       mi->data = NULL;
-       mi->rels = sa_list(sa);
-       mi->exps = sa_list(sa);
-       list_append(memo, mi);
-       return mi;
-}
-
-static lng
-rel_getcount(mvc *sql, sql_rel *rel)
-{
-       if (!sql->session->tr)
-               return 0;
-
-       switch(rel->op) {
-       case op_basetable: {
-               sql_table *t = rel->l;
-
-               if (t && isTable(t)) {
-                       sqlstore *store = sql->session->tr->store;
-                       return 
(lng)store->storage_api.count_col(sql->session->tr, 
ol_first_node(t->columns)->data, 0);
-               }
-               return 0;
-       }
-       case op_select:
-       case op_project:
-               if (rel->l)
-                       return rel_getcount(sql, rel->l);
-               return 1;
-       default:
-               return 0;
-       }
-}
-
-static lng
-rel_getwidth(mvc *sql, sql_rel *rel)
-{
-       if (!sql->session->tr)
-               return 0;
-
-       switch(rel->op) {
-       case op_basetable: {
-               sql_table *t = rel->l;
-
-               if (t && isTable(t))
-                       return 4*list_length(rel->exps);
-               return 0;
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to