Changeset: 1c47be926f62 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=1c47be926f62 Modified Files: sql/backends/monet5/sql.mx sql/common/sql_types.c sql/include/sql_catalog.h sql/server/rel_bin.c sql/server/rel_dump.c sql/server/rel_optimizer.c sql/server/rel_schema.c sql/server/rel_select.c sql/server/rel_updates.c sql/server/sql_mvc.c sql/server/sql_mvc.h sql/server/sql_parser.y sql/server/sql_privileges.c sql/server/sql_scan.c sql/server/sql_schema.c sql/server/sql_statement.c sql/sql/21_dependency_functions.sql sql/storage/bat/bat_storage.c sql/storage/bat/bat_storage.h sql/storage/bpm/bpm_storage.c sql/storage/sql_storage.h sql/storage/store.c sql/test/BugDay_2005-10-06_2.9.3/Tests/BATpropcheck_error.SF-1012739.sql sql/test/BugDay_2005-10-06_2.9.3/Tests/BATpropcheck_error.SF-1012739.stable.out sql/test/BugDay_2005-10-06_2.9.3/Tests/CrashMe_SQL_server_crash-2.SF-921673.sql sql/test/BugDay_2005-10-06_2.9.3/Tests/CrashMe_SQL_server_crash-2.SF-921673.stable.out sql/test/BugDay_2005-11-09_2.8/Tests/ORDER_BY_evaluation_error.SF-1023658.sql sql/test/BugDay_2005-11-09_2.8/Tests/ORDER_BY_evaluation_error.SF-1023658.stable.out sql/test/BugTracker-2008/Tests/sql_command_kills_db.SF-2233677.stable.err sql/test/BugTracker/Tests/cardinality_violation.SF-1240701.stable.err sql/test/BugTracker/Tests/rank_over.SF-1691098.stable.out sql/test/BugTracker/Tests/with_only_once.SF-1720293.stable.out sql/test/Dependencies/dependency_DBobjects.sql sql/test/Dependencies/dependency_owner_schema_3.sql sql/test/Skyserver/Tests/Skyserver.SQL.py sql/test/Skyserver/Tests/Skyserver_v6.SQL.py sql/test/Skyserver/run.all sql/test/Skyserver/runv6.all sql/test/Tests/trace.stable.out sql/test/bugs/Tests/groupby_having-bug-sf-947600.stable.err sql/test/bugs/Tests/groupby_having-bug-sf-947600.stable.out sql/test/bugs/Tests/innerjoin_multiple-bug-sf-943661.stable.out sql/test/bugs/Tests/insert_delete-bug-sf-904025.stable.out sql/test/bugs/Tests/select_orderby_alias-bug-sf-1024615.stable.out sql/test/bugs/Tests/simple_view.stable.out sql/test/bugs/Tests/subselect_ambigious_columns-bug-sf-949071.stable.out sql/test/bugs/Tests/union_all-bug-sf-941788.stable.out sql/test/bugs/case_cast-bug-sf-1019506.sql sql/test/bugs/groupby_having-bug-sf-947600.sql sql/test/bugs/groupby_having_charlength-bug-sf-943566.sql sql/test/bugs/innerjoin_multiple-bug-sf-943661.sql sql/test/bugs/select_orderby_alias-bug-sf-1024615.sql sql/test/bugs/subselect_ambigious_columns-bug-sf-949071.sql sql/test/bugs/union_all-bug-sf-941788.sql sql/test/concurrent/Tests/crash_on_concurrent_use.SF-1411926.stable.out sql/test/leaks/Tests/check0.stable.out sql/test/leaks/Tests/check1.stable.out sql/test/leaks/Tests/check2.stable.out sql/test/leaks/Tests/check3.stable.out sql/test/leaks/Tests/check4.stable.out sql/test/leaks/Tests/check5.stable.out sql/test/leaks/Tests/drop3.stable.out sql/test/leaks/Tests/select1.stable.out sql/test/leaks/Tests/select2.stable.out sql/test/leaks/Tests/temp1.stable.out sql/test/leaks/Tests/temp2.stable.out sql/test/leaks/Tests/temp3.stable.out sql/test/mapi/Tests/php_monetdb.stable.out Branch: default Log Message:
added first steps of merge tables on sql level diffs (truncated from 3648 to 300 lines): diff --git a/sql/backends/monet5/sql.mx b/sql/backends/monet5/sql.mx --- a/sql/backends/monet5/sql.mx +++ b/sql/backends/monet5/sql.mx @@ -1740,6 +1740,22 @@ mvc_readonly( sql, nt, t->readonly); /* check for changes */ + if (t->tables.dset) for (n = t->tables.dset->h; n; n = n->next) { + /* propagate alter table .. drop table */ + sql_table *at = n->data; + sql_table *pt = mvc_bind_table(sql, nt->s, at->base.name); + + sql_trans_del_table(sql->session->tr, nt, pt, at->drop_action); + } + for (n = t->tables.nelm; n; n = n->next) { + /* propagate alter table .. add table */ + sql_table *at = n->data; + sql_table *pt = mvc_bind_table(sql, nt->s, at->base.name); + + sql_trans_add_table(sql->session->tr, nt, pt); + } + + /* check for changes */ if (t->columns.dset) for (n = t->columns.dset->h; n; n = n->next) { /* propagate alter table .. drop column */ sql_column *c = n->data; diff --git a/sql/common/sql_types.c b/sql/common/sql_types.c --- a/sql/common/sql_types.c +++ b/sql/common/sql_types.c @@ -1278,6 +1278,12 @@ sql_create_aggr("prod", "aggr", "product", *t, *t); sql_create_func("mod", "calc", "fmod", *t, *t, *t, SCALE_FIX); } + /* + sql_create_aggr("avg", "aggr", "avg", BTE, DBL); + sql_create_aggr("avg", "aggr", "avg", SHT, DBL); + sql_create_aggr("avg", "aggr", "avg", INT, DBL); + sql_create_aggr("avg", "aggr", "avg", LNG, DBL); + */ sql_create_aggr("avg", "aggr", "avg", DBL, DBL); sql_create_aggr("count_no_nil", "aggr", "count_no_nil", NULL, WRD); diff --git a/sql/include/sql_catalog.h b/sql/include/sql_catalog.h --- a/sql/include/sql_catalog.h +++ b/sql/include/sql_catalog.h @@ -106,6 +106,7 @@ SQL_LOCAL_TEMP, SQL_GLOBAL_TEMP, SQL_DECLARED_TABLE, /* variable inside a stored procedure */ + SQL_MERGE_TABLE, SQL_STREAM } temp_t; @@ -258,8 +259,6 @@ typedef enum idx_type { hash_idx, join_idx, - clustered, /* ie has a clustered replica */ - isclustered, /* the table is (kept) clustered */ oph_idx, /* order preserving hash */ no_idx, /* no idx, ie no storage */ new_idx_types @@ -356,14 +355,14 @@ tt_table = 0, /* table */ tt_view = 1, /* view */ tt_generated = 2, /* generated (functions can be sql or c-code) */ - tt_cluster = 3, /* table supporting the clustered index */ + tt_merge_table = 3, /* multiple tables form one table */ tt_stream = 4 /* stream */ } table_types; -#define isTable(x) (x->type==tt_table||x->type==tt_cluster) +#define isTable(x) (x->type==tt_table) #define isView(x) (x->type==tt_view) #define isGenerated(x) (x->type==tt_generated) -#define isCluster(x) (x->type==tt_cluster) +#define isMergeTable(x) (x->type==tt_merge_table) #define isStream(x) (x->type==tt_stream) typedef struct sql_table { @@ -381,12 +380,12 @@ int sz; sql_ukey *pkey; - sql_idx *cluster; /* cluster column list */ - int clustered; /* is clustered or needs a recluster round */ changeset columns; changeset idxs; changeset keys; changeset triggers; + changeset tables; + int drop_action; /* only needed for alter drop table */ int cleared; /* cleared in the current transaction */ void *data; diff --git a/sql/server/rel_bin.c b/sql/server/rel_bin.c --- a/sql/server/rel_bin.c +++ b/sql/server/rel_bin.c @@ -723,6 +723,16 @@ sc = stmt_alias(sql->sa, sc, rnme, sa_strdup(sql->sa, TID)); list_append(l, sc); } + if (t->idxs.set) { + for (n = t->idxs.set->h; n; n = n->next) { + sql_idx *i = n->data; + stmt *sc = stmt_idxbat(sql->sa, i, RDONLY); + char *rnme = sa_strdup(sql->sa, t->base.name); + + sc = stmt_alias(sql->sa, sc, rnme, sa_strdup(sql->sa, i->base.name)); + list_append(l, sc); + } + } sub = stmt_list(sql->sa, l); /* add aliases */ @@ -745,16 +755,6 @@ } sub = stmt_list(sql->sa, l); } - if (t->idxs.set) { - for (n = t->idxs.set->h; n; n = n->next) { - sql_idx *i = n->data; - stmt *sc = stmt_idxbat(sql->sa, i, RDONLY); - char *rnme = sa_strdup(sql->sa, tname); - - sc = stmt_alias(sql->sa, sc, rnme, sa_strdup(sql->sa, i->base.name)); - list_append(l, sc); - } - } return sub; } @@ -1074,6 +1074,8 @@ (also not save loses unique head oids) so we create append on copies. + TODO: mark columns non base columns, ie were no + copy is needed */ s = stmt_append(sql->sa, Column(sql->sa, c1), c2); s = stmt_alias(sql->sa, s, rnme, nme); @@ -2091,7 +2093,7 @@ stmt_atom_int(sql->sa, bits)), (o)?stmt_join(sql->sa, o, is, cmp_equal):is)), xor); - } else if (h) { + } else if (h) { /* order preserving hash */ stmt *h2; sql_subfunc *lsh = sql_bind_func_result(sql->sa, sql->session->schema, "left_shift", wrd, it, wrd); sql_subfunc *lor = sql_bind_func_result(sql->sa, sql->session->schema, "bit_or", wrd, wrd, wrd); diff --git a/sql/server/rel_dump.c b/sql/server/rel_dump.c --- a/sql/server/rel_dump.c +++ b/sql/server/rel_dump.c @@ -97,7 +97,7 @@ if (atom_type(a)->type->localtype == TYPE_ptr) { sql_table *t = a->data.val.pval; mnstr_printf(fout, "%s(%s)", - isStream(t)?"stream":"table", + isStream(t)?"stream":isMergeTable(t)?"merge table":"table", t->base.name); } else { char *s = atom2string(sql->sa, a); diff --git a/sql/server/rel_optimizer.c b/sql/server/rel_optimizer.c --- a/sql/server/rel_optimizer.c +++ b/sql/server/rel_optimizer.c @@ -1890,9 +1890,14 @@ sql_rel *g = rel; sql_rel *l = u->l; sql_rel *r = u->r; - list *lexps = l->exps; - list *rexps = r->exps; - + list *lexps, *rexps; + + if (!is_project(l->op)) + u->l = l = rel_project(sql->sa, l, rel_projections(sql, l, NULL, 1, 1)); + if (!is_project(r->op)) + u->r = r = rel_project(sql->sa, r, rel_projections(sql, r, NULL, 1, 1)); + lexps = l->exps; + rexps = r->exps; /* make sure we don't create group by on group by's */ if (l->op != op_groupby && r->op != op_groupby) { node *n, *m; @@ -1952,6 +1957,8 @@ for(m = ol->h; m; m = m->next){ sql_exp *oe = m->data; + /* TODO: rel_find_exp finds the e_column expression in oe in the union's exp list + * sometimes aggr's include projection expressions (such as converts), these need to be added again! */ int p = list_position(u->exps, rel_find_exp(u, oe)); ne = list_fetch(lexps, p); append(nll, exp_column(sql->sa, exp_find_rel_name(ne), exp_name(ne), exp_subtype(ne), ne->card, has_nil(ne), is_intern(ne))); diff --git a/sql/server/rel_schema.c b/sql/server/rel_schema.c --- a/sql/server/rel_schema.c +++ b/sql/server/rel_schema.c @@ -151,7 +151,8 @@ mvc_create_table_as_subquery( mvc *sql, sql_rel *sq, sql_schema *s, char *tname, dlist *column_spec, int temp, int commit_action ) { char *n; - int tt = (temp != SQL_STREAM)?tt_table:tt_stream; + int tt = (temp == SQL_STREAM)?tt_stream: + ((temp == SQL_MERGE_TABLE)?tt_merge_table:tt_table); sql_table *t = mvc_create_table(sql, s, tname, tt, 0, SQL_DECLARED_TABLE, commit_action, -1); if ((n = as_subquery( sql, t, sq, column_spec)) != NULL) { @@ -566,10 +567,13 @@ { int res = SQL_OK; - if (alter && !isTable(t)) { + if (alter && (isView(t) || (isMergeTable(t) && s->token != SQL_TABLE && s->token != SQL_DROP_TABLE) || (isTable(t) && (s->token == SQL_TABLE || s->token == SQL_DROP_TABLE)) )){ char *msg = ""; switch (s->token) { + case SQL_TABLE: + msg = "add table to"; + break; case SQL_COLUMN: msg = "add column to"; break; @@ -585,6 +589,9 @@ case SQL_DROP_DEFAULT: msg = "drop default column option from"; break; + case SQL_DROP_TABLE: + msg = "drop table from"; + break; case SQL_DROP_COLUMN: msg = "drop column from"; break; @@ -592,8 +599,10 @@ msg = "drop constraint from"; break; } - sql_error(sql, 02, "ALTER TABLE: cannot %s VIEW '%s'\n", - msg, t->base.name); + sql_error(sql, 02, "ALTER TABLE: cannot %s %s '%s'\n", + msg, + isMergeTable(t)?"MERGE TABLE":"VIEW", + t->base.name); return SQL_ERR; } @@ -740,16 +749,19 @@ int instantiate = (sql->emode == m_instantiate); int deps = (sql->emode == m_deps); int create = (!instantiate && !deps); + int tt = (temp == SQL_STREAM)?tt_stream: + ((temp == SQL_MERGE_TABLE)?tt_merge_table:tt_table); (void)create; if (sname && !(s = mvc_bind_schema(sql, sname))) return sql_error(sql, 02, "CREATE TABLE: no such schema '%s'", sname); - if (temp != SQL_PERSIST && temp != SQL_STREAM && commit_action == CA_COMMIT) + if (temp != SQL_PERSIST && tt == tt_table && + commit_action == CA_COMMIT) commit_action = CA_DELETE; if (temp != SQL_DECLARED_TABLE) { - if (temp != SQL_PERSIST) { + if (temp != SQL_PERSIST && tt == tt_table) { s = mvc_bind_schema(sql, "tmp"); } else if (s == NULL) { s = ss; @@ -766,7 +778,6 @@ return sql_error(sql, 02, "CREATE TABLE: insufficient privileges for user '%s' in schema '%s'", stack_get_string(sql, "current_user"), s->base.name); } else if (table_elements_or_subquery->token == SQL_CREATE_TABLE) { /* table element list */ - int tt = (temp != SQL_STREAM)?tt_table:tt_stream; sql_table *t = mvc_create_table(sql, s, name, tt, 0, SQL_DECLARED_TABLE, commit_action, -1); dnode *n; dlist *columns = table_elements_or_subquery->data.lval; @@ -778,7 +789,7 @@ if (res == SQL_ERR) return NULL; } - temp = (temp == SQL_STREAM)?SQL_PERSIST:temp; + temp = (tt == tt_table)?temp:SQL_PERSIST; return rel_table(sql->sa, DDL_CREATE_TABLE, sname, t, temp); } else { /* [col name list] as subquery with or without data */ sql_rel *sq = NULL, *res = NULL; @@ -800,7 +811,7 @@ } /* insert query result into this table */ - temp = (temp == SQL_STREAM)?SQL_PERSIST:temp; + temp = (tt == tt_table)?temp:SQL_PERSIST; res = rel_table(sql->sa, DDL_CREATE_TABLE, sname, t, temp); if (with_data) { res = rel_insert(sql->sa, res, sq); @@ -1045,6 +1056,27 @@ res = rel_table(sql->sa, DDL_ALTER_TABLE, sname, nt, 0); if (!te) /* Set Read only */ return res; + /* table add table */ + if (te->token == SQL_TABLE) { + char *ntname = te->data.lval->h->data.sval; + sql_table *nnt = mvc_bind_table(sql, s, ntname); + _______________________________________________ Checkin-list mailing list Checkin-list@monetdb.org http://mail.monetdb.org/mailman/listinfo/checkin-list