Changeset: 36bf09df0b9c for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=36bf09df0b9c Modified Files: Branch: default Log Message:
Merge git master into default diffs (truncated from 359 to 300 lines): diff -r dbec6606e6ec -r 36bf09df0b9c pathfinder/compiler/algebra/algebra.c --- a/pathfinder/compiler/algebra/algebra.c Thu Jul 29 08:53:57 2010 +0200 +++ b/pathfinder/compiler/algebra/algebra.c Thu Jul 29 13:26:07 2010 +0200 @@ -1196,6 +1196,7 @@ case alg_fun_fn_lower_case: return "fn:lower-case"; case alg_fun_fn_translate: return "fn:translate"; case alg_fun_fn_contains: return "fn:contains"; + case alg_fun_fn_like: return "fn:like"; case alg_fun_fn_starts_with: return "fn:starts-with"; case alg_fun_fn_ends_with: return "fn:ends-with"; case alg_fun_fn_substring_before: return "fn:substring-before"; @@ -1211,6 +1212,7 @@ case alg_fun_fn_number_lax: return "fn:number"; case alg_fun_fn_qname: return "fn:QName"; case alg_fun_fn_doc_available: return "fn:doc-available"; + case alg_fun_fn_similar_to: return "fn:similar_to"; case alg_fun_pf_fragment: return "#pf:fragment"; case alg_fun_pf_supernode: return "#pf:supernode"; case alg_fun_pf_add_doc_str: return "pf:add-doc"; diff -r dbec6606e6ec -r 36bf09df0b9c pathfinder/compiler/algebra/logical.c --- a/pathfinder/compiler/algebra/logical.c Thu Jul 29 08:53:57 2010 +0200 +++ b/pathfinder/compiler/algebra/logical.c Thu Jul 29 13:26:07 2010 +0200 @@ -1473,9 +1473,11 @@ break; case alg_fun_fn_contains: + case alg_fun_fn_like: case alg_fun_fn_starts_with: case alg_fun_fn_ends_with: case alg_fun_fn_matches: + case alg_fun_fn_similar_to: assert (clsize (refs) == 2); /* make sure both columns are of type string */ assert (n->schema.items[ix[0]].type == aat_str && diff -r dbec6606e6ec -r 36bf09df0b9c pathfinder/compiler/algebra/opt/opt_reqval.c --- a/pathfinder/compiler/algebra/opt/opt_reqval.c Thu Jul 29 08:53:57 2010 +0200 +++ b/pathfinder/compiler/algebra/opt/opt_reqval.c Thu Jul 29 13:26:07 2010 +0200 @@ -97,23 +97,6 @@ if (p->bit_dag) return; - /* Using the required values property as well as the constant - property we can replace every expression, where at least one - column has a constant value that differs its required value, - by an empty table. */ - for (unsigned int i = 0; i < p->schema.count; i++) { - PFalg_col_t cur_col = p->schema.items[i].name; - - if (PFprop_req_bool_val (p->prop, cur_col) && - PFprop_const (p->prop, cur_col) && - (PFprop_const_val (p->prop, cur_col)).val.bln != - PFprop_req_bool_val_val (p->prop, cur_col)) { - /* create an empty table instead */ - *p = *PFla_empty_tbl_ (p->schema); - return; - } - } - /* Replace rowrank operators whose real values are not needed by rank operators. Note that we do not need to check for the order @@ -185,6 +168,41 @@ p->bit_dag = true; } +/* worker for PFalgopt_reqval */ +static void +opt_req_bool_vals (PFla_op_t *p) +{ + assert (p); + + /* nothing to do if we already visited that node */ + if (p->bit_dag) + return; + + /* Using the required values property as well as the constant + property we can replace every expression, where at least one + column has a constant value that differs its required value, + by an empty table. */ + for (unsigned int i = 0; i < p->schema.count; i++) { + PFalg_col_t cur_col = p->schema.items[i].name; + + if (PFprop_req_bool_val (p->prop, cur_col) && + PFprop_const (p->prop, cur_col) && + (PFprop_const_val (p->prop, cur_col)).val.bln != + PFprop_req_bool_val_val (p->prop, cur_col)) { + /* create an empty table instead */ + *p = *PFla_empty_tbl_ (p->schema); + return; + } + } + + /* infer properties for children */ + for (unsigned int i = 0; i < PFLA_OP_MAXCHILD && p->child[i]; i++) + opt_req_bool_vals (p->child[i]); + + /* mark node as visited */ + p->bit_dag = true; +} + /** * Invoke algebra optimization. */ @@ -202,7 +220,10 @@ schema_dirty = false; - /* Optimize algebra tree */ + /* Optimize algebra tree. + Note: the rewrites modifying the column types have to be performed + before empty tables are introduced in opt_req_bool_vals() to avoid + inconsistent types. */ opt_reqvals (root); PFla_dag_reset (root); @@ -212,6 +233,15 @@ if (schema_dirty) PFprop_infer_ocol (root); + schema_dirty = false; + + /* Get rid of superfluous branches. + Make sure to take the rewrites that might have changed column types + into account. */ + opt_req_bool_vals (root); + PFla_dag_reset (root); + assert (!schema_dirty); + return root; } diff -r dbec6606e6ec -r 36bf09df0b9c pathfinder/compiler/algebra/physical.c --- a/pathfinder/compiler/algebra/physical.c Thu Jul 29 08:53:57 2010 +0200 +++ b/pathfinder/compiler/algebra/physical.c Thu Jul 29 13:26:07 2010 +0200 @@ -1680,9 +1680,11 @@ break; case alg_fun_fn_contains: + case alg_fun_fn_like: case alg_fun_fn_starts_with: case alg_fun_fn_ends_with: case alg_fun_fn_matches: + case alg_fun_fn_similar_to: assert (clsize (refs) == 2); /* make sure both columns are of type string */ assert (n->schema.items[ix[0]].type == aat_str && diff -r dbec6606e6ec -r 36bf09df0b9c pathfinder/compiler/algebra/prop/prop_ocol.c --- a/pathfinder/compiler/algebra/prop/prop_ocol.c Thu Jul 29 08:53:57 2010 +0200 +++ b/pathfinder/compiler/algebra/prop/prop_ocol.c Thu Jul 29 13:26:07 2010 +0200 @@ -391,9 +391,11 @@ break; case alg_fun_fn_contains: + case alg_fun_fn_like: case alg_fun_fn_starts_with: case alg_fun_fn_ends_with: case alg_fun_fn_matches: + case alg_fun_fn_similar_to: assert (clsize (n->sem.fun_1to1.refs) == 2); /* make sure both columns are of type string */ assert (ocol_at (L(n), ix[0]).type == aat_str && diff -r dbec6606e6ec -r 36bf09df0b9c pathfinder/compiler/include/algebra.h --- a/pathfinder/compiler/include/algebra.h Thu Jul 29 08:53:57 2010 +0200 +++ b/pathfinder/compiler/include/algebra.h Thu Jul 29 13:26:07 2010 +0200 @@ -391,6 +391,7 @@ , alg_fun_fn_lower_case /**< fn:lower-case */ , alg_fun_fn_translate /**< fn:translate */ , alg_fun_fn_contains /**< fn:contains */ + , alg_fun_fn_like /**< fn:like */ , alg_fun_fn_starts_with /**< fn:starts-with */ , alg_fun_fn_ends_with /**< fn:ends-with */ , alg_fun_fn_substring_before /**< fn:substring-before */ @@ -406,6 +407,7 @@ , alg_fun_fn_number_lax /**< fn:number (ignoring NaN) */ , alg_fun_fn_qname /**< fn:QName */ , alg_fun_fn_doc_available /**< fn:doc-available */ + , alg_fun_fn_similar_to /**< fn:similar_to */ , alg_fun_pf_fragment /**< #pf:fragment */ , alg_fun_pf_supernode /**< #pf:supernode */ , alg_fun_pf_add_doc_str /**< pf:add-doc */ diff -r dbec6606e6ec -r 36bf09df0b9c pathfinder/compiler/include/sql.h --- a/pathfinder/compiler/include/sql.h Thu Jul 29 08:53:57 2010 +0200 +++ b/pathfinder/compiler/include/sql.h Thu Jul 29 13:26:07 2010 +0200 @@ -174,6 +174,7 @@ , sql_gteq /* >= comparison */ , sql_between /* range predicate */ , sql_like /* like comparison */ + , sql_similar_to /* similar to comparison */ , sql_in /* in comparison */ , sql_stmt_list /* an item of a list of statments (second argument of a sql_in operator) */ @@ -793,6 +794,14 @@ * with a certain pattern. */ PFsql_t * PFsql_like (const PFsql_t *a, const PFsql_t *b); + +/** + * Create a tree node representing the SQL99 + * 'similar to' statement to compare a string with + * a certain pattern. + */ +PFsql_t * PFsql_similar_to (const PFsql_t *a, const PFsql_t *b); + /** * Create a SQL tree node representing the in operator */ diff -r dbec6606e6ec -r 36bf09df0b9c pathfinder/compiler/include/sql_mnemonic.h --- a/pathfinder/compiler/include/sql_mnemonic.h Thu Jul 29 08:53:57 2010 +0200 +++ b/pathfinder/compiler/include/sql_mnemonic.h Thu Jul 29 13:26:07 2010 +0200 @@ -117,6 +117,7 @@ #define gteq(a,b) PFsql_gteq(a,b) #define between(c,a,b) PFsql_between(c,a,b) #define like(a,b) PFsql_like(a,b) +#define similar_to(a,b) PFsql_similar_to(a,b) #define in(a,b) PFsql_in(a,b) #define stmt_list(...) PFsql_stmt_list(__VA_ARGS__) #define not_(a) PFsql_not(a) diff -r dbec6606e6ec -r 36bf09df0b9c pathfinder/compiler/mil/milgen.brg --- a/pathfinder/compiler/mil/milgen.brg Thu Jul 29 08:53:57 2010 +0200 +++ b/pathfinder/compiler/mil/milgen.brg Thu Jul 29 13:26:07 2010 +0200 @@ -5517,6 +5517,7 @@ VAR (L(p)->env, col2, aat_str), VAR (L(p)->env, col3, aat_str)))); } break; /* fold) */ + case alg_fun_fn_like: case alg_fun_fn_contains: /* fold( */ { PFalg_col_t col1, col2; @@ -5534,6 +5535,9 @@ VAR (L(p)->env, col2, aat_str)), lit_int (-1))))); } break; /* fold) */ + case alg_fun_fn_similar_to: + PFoops (OOPS_FATAL, + "fn:similar_to not implemented for MIL"); #ifdef HAVE_GEOXML case alg_fun_geo_wkb: /* fold( */ { diff -r dbec6606e6ec -r 36bf09df0b9c pathfinder/compiler/sql/lalg2sql.brg --- a/pathfinder/compiler/sql/lalg2sql.brg Thu Jul 29 08:53:57 2010 +0200 +++ b/pathfinder/compiler/sql/lalg2sql.brg Thu Jul 29 13:26:07 2010 +0200 @@ -3676,15 +3676,29 @@ case alg_fun_num_divide: res_expr = div (expr[0], expr[1]); break; case alg_fun_fn_contains: + { + /* adding check for constant expression */ + if (!PFprop_const (L(p)->prop, col[1]) || + ty[1] != aat_str || + expr[1]->kind == sql_column_name) + PFoops (OOPS_FATAL, "fn_contains works only with constant " + "string expressions"); + char *str = PFmalloc (strlen(expr[1]->sem.atom.val.s)+2); + sprintf (str, "%%%s%%", expr[1]->sem.atom.val.s); + res_expr = like (expr[0], PFsql_lit_str(str)); + } + break; + case alg_fun_fn_like: /* adding check for constant expression */ if (!PFprop_const (L(p)->prop, col[1]) || ty[1] != aat_str || expr[1]->kind == sql_column_name) - PFoops (OOPS_FATAL, "fn_contains works only with constant " + PFoops (OOPS_FATAL, "fn_like works only with constant " "string expressions"); - res_expr = like (expr[0], expr[1]); break; + case alg_fun_fn_similar_to: + res_expr = similar_to (expr[0], expr[1]); break; /**< fn:ceiling */ case alg_fun_fn_ceiling: res_expr = ceil (expr[0]); break; diff -r dbec6606e6ec -r 36bf09df0b9c pathfinder/compiler/sql/sql.c --- a/pathfinder/compiler/sql/sql.c Thu Jul 29 08:53:57 2010 +0200 +++ b/pathfinder/compiler/sql/sql.c Thu Jul 29 13:26:07 2010 +0200 @@ -870,6 +870,17 @@ } /** + * Create a tree node representing the SQL99 + * 'similar to' statement to compare a string with + * a certain pattern. + */ +PFsql_t * +PFsql_similar_to (const PFsql_t *a, const PFsql_t *b) +{ + return wire2 (sql_similar_to, a, b); +} + +/** * Create a SQL tree node representing the in operator */ PFsql_t * diff -r dbec6606e6ec -r 36bf09df0b9c pathfinder/compiler/sql/sqlprint.c --- a/pathfinder/compiler/sql/sqlprint.c Thu Jul 29 08:53:57 2010 +0200 +++ b/pathfinder/compiler/sql/sqlprint.c Thu Jul 29 13:26:07 2010 +0200 @@ -70,7 +70,7 @@ } _______________________________________________ Checkin-list mailing list Checkin-list@monetdb.org http://mail.monetdb.org/mailman/listinfo/checkin-list