Skip to content

Commit

Permalink
fixes for issues #7447 and #7448
Browse files Browse the repository at this point in the history
ranges queries can have null's and not return NULL, ie fixed optimizer/statistics
only use full hash index for selects
  • Loading branch information
njnes committed Jan 26, 2024
1 parent 5f7baf0 commit 95516bb
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions sql/backends/monet5/rel_bin.c
Expand Up @@ -2592,6 +2592,8 @@ rel2bin_hash_lookup(backend *be, sql_rel *rel, stmt *left, stmt *right, sql_idx
h = stmt_unop(be, s, NULL, hf);
}
}
if (n != NULL) /* need to use all cols of the index */
return NULL;
if (h && h->nrcols) {
if (!swap_rel) {
return stmt_join(be, idx, h, 0, cmp_equal, 0, semantics, false);
Expand Down
6 changes: 5 additions & 1 deletion sql/server/rel_statistics.c
Expand Up @@ -33,6 +33,10 @@ comparison_find_column(sql_exp *input, sql_exp *e)
}
}

/* multi lo <= col <= hi, maybe still be false even if lo or hi are NULL, possibly similar for filter on multiple
* columns */
#define comp_single_column(c) (!c->f)

static sql_exp *
rel_propagate_column_ref_statistics(mvc *sql, sql_rel *rel, sql_exp *e)
{
Expand Down Expand Up @@ -69,7 +73,7 @@ rel_propagate_column_ref_statistics(mvc *sql, sql_rel *rel, sql_exp *e)
*rval_min = find_prop_and_get(re->p, PROP_MIN), *rval_max = find_prop_and_get(re->p, PROP_MAX);

/* not semantics found or if explicitly filtering not null values from the column */
found_without_semantics |= !is_semantics(comp) || (comp->flag == cmp_equal && lne && is_anti(comp) && exp_is_null(re));
found_without_semantics |= (!is_semantics(comp) && comp_single_column(comp)) || (comp->flag == cmp_equal && lne && is_anti(comp) && exp_is_null(re));
still_unique |= comp->flag == cmp_equal && is_unique(le) && is_unique(re); /* unique if only equi-joins on unique columns are there */
if (is_full(rel->op) || (is_left(rel->op) && found_left) || (is_right(rel->op) && found_right)) /* on outer joins, min and max cannot be propagated on some cases */
continue;
Expand Down
2 changes: 1 addition & 1 deletion sql/test/miscellaneous/Tests/unique_keys.test
Expand Up @@ -91,7 +91,7 @@ project (
| | | | table("sys"."testkeys") [ "testkeys"."a" NOT NULL UNIQUE HASHCOL , "testkeys"."b" UNIQUE HASHCOL ]
| | | ) [ ("testkeys"."b" UNIQUE HASHCOL ) = (int(32) "1") ],
| | | table("sys"."othertable") [ "othertable"."a" UNIQUE ]
| | ) [ ("testkeys"."a" NOT NULL UNIQUE HASHCOL ) = ("othertable"."a" NOT NULL UNIQUE) ]
| | ) [ ("testkeys"."a" NOT NULL UNIQUE HASHCOL ) = ("othertable"."a" UNIQUE) ]
| ) [ (int(32) "2") <= ("othertable"."a" UNIQUE) <= (int(32) "5") ]
) [ "testkeys"."a" NOT NULL UNIQUE HASHCOL ]

Expand Down

0 comments on commit 95516bb

Please sign in to comment.