Changeset: a5f6d3ab4598 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/a5f6d3ab4598
Added Files:
sql/backends/monet5/rel_util.c
sql/backends/monet5/rel_util.h
Modified Files:
sql/backends/monet5/CMakeLists.txt
sql/backends/monet5/rel_bin.c
sql/backends/monet5/rel_bin.h
sql/backends/monet5/rel_physical.c
sql/backends/monet5/rel_physical.h
sql/backends/monet5/rel_pphash.c
Branch: default
Log Message:
moved shared functions into a new rel_util.{c,h} and merged split_join_exps_pp()
into split_join_exps()
diffs (truncated from 489 to 300 lines):
diff --git a/sql/backends/monet5/CMakeLists.txt
b/sql/backends/monet5/CMakeLists.txt
--- a/sql/backends/monet5/CMakeLists.txt
+++ b/sql/backends/monet5/CMakeLists.txt
@@ -147,6 +147,7 @@ target_sources(sql
rel_pptopn.c rel_pptopn.h
rel_physical.c rel_physical.h
rel_predicates.c rel_predicates.h
+ rel_util.c rel_util.h
bin_partition.c bin_partition.h
bin_partition_by_slice.c bin_partition_by_slice.h
bin_partition_by_value.c bin_partition_by_value.h
diff --git a/sql/backends/monet5/rel_bin.c b/sql/backends/monet5/rel_bin.c
--- a/sql/backends/monet5/rel_bin.c
+++ b/sql/backends/monet5/rel_bin.c
@@ -25,6 +25,7 @@
#include "rel_updates.h"
#include "rel_predicates.h"
#include "rel_rewriter.h"
+#include "rel_util.h"
#include "bin_partition.h"
#include "bin_partition_by_slice.h"
#include "bin_partition_by_value.h"
@@ -3079,124 +3080,6 @@ releqjoin(backend *be, list *l1, list *l
return res;
}
-bool
-can_join_exp(sql_rel *rel, sql_exp *e, bool anti)
-{
- bool can_join = 0;
-
- if (e->type == e_cmp) {
- int flag = e->flag;
- /* check if its a select or join expression, ie use only
expressions of one relation left and of the other right (than join) */
- if (flag < cmp_filter) { /* theta and range joins */
- /* join or select ? */
- sql_exp *l = e->l, *r = e->r, *f = e->f;
-
- if (f) {
- int ll = rel_has_exp(rel->l, l, true) == 0;
- int rl = rel_has_exp(rel->r, l, true) == 0;
- int lr = rel_has_exp(rel->l, r, true) == 0;
- int rr = rel_has_exp(rel->r, r, true) == 0;
- int lf = rel_has_exp(rel->l, f, true) == 0;
- int rf = rel_has_exp(rel->r, f, true) == 0;
- int nrcr1 = 0, nrcr2 = 0, nrcl1 = 0, nrcl2 = 0;
-
- if ((ll && !rl &&
- ((rr && !lr) || (nrcr1 = r->card ==
CARD_ATOM && exp_is_atom(r))) &&
- ((rf && !lf) || (nrcr2 = f->card ==
CARD_ATOM && exp_is_atom(f))) && (nrcr1+nrcr2) <= 1) ||
- (rl && !ll &&
- ((lr && !rr) || (nrcl1 = r->card ==
CARD_ATOM && exp_is_atom(r))) &&
- ((lf && !rf) || (nrcl2 = f->card ==
CARD_ATOM && exp_is_atom(f))) && (nrcl1+nrcl2) <= 1)) {
- can_join = 1;
- }
- } else {
- int ll = 0, lr = 0, rl = 0, rr = 0, cst = 0;
- if (l->card != CARD_ATOM || !exp_is_atom(l)) {
- ll = rel_has_exp(rel->l, l, true) == 0;
- rl = rel_has_exp(rel->r, l, true) == 0;
- } else if (anti) {
- ll = 1;
- cst = 1;
- }
- if (r->card != CARD_ATOM || !exp_is_atom(r)) {
- lr = rel_has_exp(rel->l, r, true) == 0;
- rr = rel_has_exp(rel->r, r, true) == 0;
- } else if (anti) {
- rr = cst?0:1;
- }
- if ((ll && !lr && !rl && rr) || (!ll && lr &&
rl && !rr))
- can_join = 1;
- }
- } else if (flag == cmp_filter) {
- list *l = e->l, *r = e->r;
- int ll = 0, lr = 0, rl = 0, rr = 0;
-
- for (node *n = l->h ; n ; n = n->next) {
- sql_exp *ee = n->data;
-
- if (ee->card != CARD_ATOM || !exp_is_atom(ee)) {
- ll |= rel_has_exp(rel->l, ee, true) ==
0;
- rl |= rel_has_exp(rel->r, ee, true) ==
0;
- }
- }
- for (node *n = r->h ; n ; n = n->next) {
- sql_exp *ee = n->data;
-
- if (ee->card != CARD_ATOM || !exp_is_atom(ee)) {
- lr |= rel_has_exp(rel->l, ee, true) ==
0;
- rr |= rel_has_exp(rel->r, ee, true) ==
0;
- }
- }
- if ((ll && !lr && !rl && rr) || (!ll && lr && rl &&
!rr))
- can_join = 1;
- }
- }
- return can_join;
-}
-
-static void
-split_join_exps(sql_rel *rel, list *joinable, list *not_joinable, bool anti)
-{
- if (!list_empty(rel->exps)) {
- for (node *n = rel->exps->h; n; n = n->next) {
- sql_exp *e = n->data;
-
- /* we can handle thetajoins, rangejoins and filter
joins (like) */
- /* ToDo how about atom expressions? */
- if (can_join_exp(rel, e, anti)) {
- append(joinable, e);
- } else {
- append(not_joinable, e);
- }
- }
- }
-}
-
-
-#define is_equi_exp_(e) ((e)->flag == cmp_equal)
-
-list *
-get_simple_equi_joins_first(mvc *sql, sql_rel *rel, list *exps)
-{
- list *new_exps = sa_list(sql->sa);
-
- if (!exps)
- return new_exps;
-
- for (node *n = exps->h; n; n = n->next) {
- sql_exp *e = n->data;
-
- if (can_join_exp(rel, e, false) && is_equi_exp_(e) &&
!is_any(e))
- list_append(new_exps, e);
- }
- for (node *n = exps->h; n; n = n->next) {
- sql_exp *e = n->data;
-
- if (!is_equi_exp_(e) || !can_join_exp(rel, e, false) ||
is_any(e))
- list_append(new_exps, e);
- }
- return new_exps;
-}
-
static stmt *
rel2bin_groupjoin(backend *be, sql_rel *rel, list *refs)
{
@@ -3526,7 +3409,7 @@ rel2bin_join(backend *be, sql_rel *rel,
list *jexps = sa_list(sql->sa);
sexps = sa_list(sql->sa);
- split_join_exps(rel, jexps, sexps, false);
+ split_join_exps(rel, jexps, sexps, false /* eqonly */, false /*
anti */);
if (list_empty(jexps)) { /* cross product and continue after
project */
stmt *l = bin_find_smallest_column(be, left);
stmt *r = bin_find_smallest_column(be, right);
@@ -3773,7 +3656,7 @@ rel2bin_antijoin(backend *be, sql_rel *r
jexps = sa_list(sql->sa);
sexps = sa_list(sql->sa);
- split_join_exps(rel, jexps, sexps, true);
+ split_join_exps(rel, jexps, sexps, false /* eqonly */, true /* anti */);
if (list_empty(jexps)) {
stmt *l = bin_find_smallest_column(be, left);
stmt *r = bin_find_smallest_column(be, right);
@@ -3999,7 +3882,7 @@ rel2bin_semijoin(backend *be, sql_rel *r
list *jexps = sa_list(sql->sa);
sexps = sa_list(sql->sa);
- split_join_exps(rel, jexps, sexps, false);
+ split_join_exps(rel, jexps, sexps, false /* eqonly */, false /*
anti */);
if (list_empty(jexps)) { /* cross product and continue after
project */
right = subrel_project(be, right, refs, rel->r);
stmt *l = bin_find_smallest_column(be, left);
diff --git a/sql/backends/monet5/rel_bin.h b/sql/backends/monet5/rel_bin.h
--- a/sql/backends/monet5/rel_bin.h
+++ b/sql/backends/monet5/rel_bin.h
@@ -25,8 +25,6 @@ extern stmt *rel2bin_sql_table(backend *
/* private */
-#define is_equi_exp_(e) ((e)->flag == cmp_equal)
-
extern int add_to_rowcount_accumulator(backend *be, int nr);
extern stmt* stmt_selectnil(backend *be, stmt *col, stmt *sel);
@@ -40,9 +38,6 @@ extern stmt *refs_find_rel(list *refs, s
extern stmt *sql_Nop_(backend *be, const char *fname, stmt *a1, stmt *a2, stmt
*a3, stmt *a4);
extern stmt *sql_unop_(backend *be, const char *fname, stmt *rs);
-extern bool can_join_exp(sql_rel *rel, sql_exp *e, bool anti);
-extern list *get_simple_equi_joins_first(mvc *sql, sql_rel *rel, list *exps);
-
extern stmt *subres_assign_resultvars(backend *be, stmt *rel_stmt, list *vars);
extern stmt *rel_rename(backend *be, sql_rel *rel, stmt *sub);
diff --git a/sql/backends/monet5/rel_physical.c
b/sql/backends/monet5/rel_physical.c
--- a/sql/backends/monet5/rel_physical.c
+++ b/sql/backends/monet5/rel_physical.c
@@ -16,7 +16,7 @@
#include "rel_rel.h"
#include "sql_storage.h"
#include "sql_scenario.h"
-#include "rel_bin.h"
+#include "rel_util.h"
#include "bin_partition_by_slice.h"
#define IS_ORDER_BASED_AGGR(fname, argc) (\
@@ -889,7 +889,7 @@ rel_pipeline(visitor *v, sql_rel *rel, b
} else if (is_semi(rel->op)) {
list *eq_exps = sa_list(v->sql->sa);
list *other = sa_list(v->sql->sa);
- split_join_exps_pp(rel, eq_exps, other, true);
+ split_join_exps(rel, eq_exps, other, true /* eqonly */, true /*
anti */);
bool needs_payload = (!list_empty(other));
bool need_all = false;
bool cross = list_empty(eq_exps);
@@ -1012,7 +1012,7 @@ rel_pipeline(visitor *v, sql_rel *rel, b
list *other = sa_list(v->sql->sa);
if (!list_empty(rel->attr))
rel->exps = get_simple_equi_joins_first(v->sql,
rel, rel->exps);
- split_join_exps_pp(rel, eq_exps, other, true);
+ split_join_exps(rel, eq_exps, other, true /* eqonly */,
true /* anti */);
sql_rel *l = rel->l, *r = rel->r;
sql_rel *rel_hsh = NULL, *rel_prb = NULL, *iprj = NULL,
*pprj = NULL;
@@ -1610,24 +1610,6 @@ rel_push_down_topn(visitor *v, sql_rel *
return rel;
}
-void
-split_join_exps_pp(sql_rel *rel, list *joinable, list *not_joinable, bool anti)
-{
- if (!list_empty(rel->exps)) {
- for (node *n = rel->exps->h; n; n = n->next) {
- sql_exp *e = n->data;
-
- /* we can handle thetajoins, rangejoins and filter
joins (like) */
- /* ToDo how about atom expressions? */
- if (can_join_exp(rel, e, anti) && is_equi_exp_(e) &&
!exp_is_atom(e->r) && !exp_is_atom(e->l)) {
- append(joinable, e);
- } else {
- append(not_joinable, e);
- }
- }
- }
-}
-
static sql_rel *
rel_add_project(visitor *v, sql_rel *rel)
{
diff --git a/sql/backends/monet5/rel_physical.h
b/sql/backends/monet5/rel_physical.h
--- a/sql/backends/monet5/rel_physical.h
+++ b/sql/backends/monet5/rel_physical.h
@@ -15,6 +15,5 @@
#include "sql_mvc.h"
extern sql_rel *rel_physical(mvc *sql, sql_rel *rel);
-extern void split_join_exps_pp(sql_rel *rel, list *joinable, list
*not_joinable, bool anti);
#endif /*_REL_PHYSICAL_H_*/
diff --git a/sql/backends/monet5/rel_pphash.c b/sql/backends/monet5/rel_pphash.c
--- a/sql/backends/monet5/rel_pphash.c
+++ b/sql/backends/monet5/rel_pphash.c
@@ -16,6 +16,7 @@
#include "rel_pphash.h"
#include "rel_rewriter.h"
#include "rel_physical.h"
+#include "rel_util.h"
#include "sql_pp_statement.h"
#include "bin_partition_by_value.h"
#include "mal_builder.h"
@@ -756,7 +757,7 @@ rel2bin_oahash_groupjoin(backend *be, sq
assert(!list_empty(rel->attr));
stmt *sub = NULL, *probe_sub = NULL;
list *jexps = sa_list(be->mvc->sa), *sexps = sa_list(be->mvc->sa),
*probe_side = NULL, *hash_side = NULL;
- split_join_exps_pp(rel, jexps, sexps, false);
+ split_join_exps(rel, jexps, sexps, true /* eqonly */, false /* anti */);
stmt *probed_ids = NULL, *hash_ids = NULL;
stmt *prb_mrk = NULL;
bool mark = false, exist = true;
@@ -842,7 +843,7 @@ rel2bin_oahash_innerjoin(backend *be, sq
bool hf = false;
stmt *sub = NULL, *probed_ids = NULL;
list *jexps = sa_list(be->mvc->sa), *sexps = sa_list(be->mvc->sa),
*probe_side = NULL, *hash_side = NULL;
- split_join_exps_pp(rel, jexps, sexps, false);
+ split_join_exps(rel, jexps, sexps, true /* eqonly */, false /* anti */);
bool single = rel->single && !list_empty(sexps);
/* start new parallel block after join. NB get_need_pipeline has side
effect! */
@@ -873,7 +874,7 @@ rel2bin_oahash_leftouterjoin(backend *be
{
stmt *sub = NULL, *probe_sub = NULL;
list *jexps = sa_list(be->mvc->sa), *sexps = sa_list(be->mvc->sa),
*probe_side = NULL, *hash_side = NULL;
- split_join_exps_pp(rel, jexps, sexps, false);
+ split_join_exps(rel, jexps, sexps, true /* eqonly */, false /* anti */);
stmt *probed_ids = NULL, *hash_ids = NULL;
stmt *prb_mrk = NULL;
@@ -969,7 +970,7 @@ rel2bin_oahash_rightouterjoin(backend *b
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]