Changeset: 88586b9bb82c for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=88586b9bb82c Modified Files: sql/backends/monet5/sql.c sql/backends/monet5/sql_scenario.c sql/include/sql_catalog.h sql/server/sql_parser.y sql/server/sql_scan.c sql/storage/bat/bat_storage.c Branch: leftmart Log Message:
added support for create ordered index on sql level. The bat_storage.c - create_idx will now call the OIDXcreateImplemantation. (unfortunately something is still wrong there) diffs (182 lines): diff --git a/sql/backends/monet5/sql.c b/sql/backends/monet5/sql.c --- a/sql/backends/monet5/sql.c +++ b/sql/backends/monet5/sql.c @@ -518,6 +518,13 @@ alter_table(mvc *sql, char *sname, sql_t return sql_message("40000!CONSTRAINT PRIMARY KEY: a table can have only one PRIMARY KEY\n"); } } + if (t->access != TABLE_READONLY) { + for (n = t->idxs.nelm; n; n = n->next) { + sql_idx *i = n->data; + if (i && i->type == ordered_idx) + return sql_message("40000!ORDERED INDEX: only READONLY tables can have an ORDERED INDEX\n"); + } + } } /* check for changes */ diff --git a/sql/backends/monet5/sql_scenario.c b/sql/backends/monet5/sql_scenario.c --- a/sql/backends/monet5/sql_scenario.c +++ b/sql/backends/monet5/sql_scenario.c @@ -435,7 +435,7 @@ SQLinitClient(Client c) MCpushClientInput(c, fdin, 0, ""); } if (c->sqlcontext == 0) { - m = mvc_create(c->idx, 0, SQLdebug, c->fdin, c->fdout); + m = mvc_create(c->idx, c->idx /*0*/, SQLdebug, c->fdin, c->fdout); global_variables(m, "monetdb", "sys"); if (isAdministrator(c) || strcmp(c->scenario, "msql") == 0) /* console should return everything */ m->reply_size = -1; 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 @@ -352,11 +352,13 @@ typedef enum idx_type { join_idx, oph_idx, /* order preserving hash */ no_idx, /* no idx, ie no storage */ + ordered_idx, new_idx_types } idx_type; #define hash_index(t) (t == hash_idx || t == oph_idx ) -#define idx_has_column(t) (hash_index(t) || t == join_idx) +#define idx_has_column(t) (hash_index(t) || t == join_idx || t == ordered_idx) +#define oid_index(t) (t == join_idx || t == ordered_idx) typedef struct sql_idx { sql_base base; diff --git a/sql/server/sql_parser.y b/sql/server/sql_parser.y --- a/sql/server/sql_parser.y +++ b/sql/server/sql_parser.y @@ -486,7 +486,7 @@ int yydebug=1; %token START TRANSACTION READ WRITE ONLY ISOLATION LEVEL %token UNCOMMITTED COMMITTED sqlREPEATABLE SERIALIZABLE DIAGNOSTICS sqlSIZE STORAGE -%token <sval> ASYMMETRIC SYMMETRIC ORDER BY +%token <sval> ASYMMETRIC SYMMETRIC ORDER ORDERED BY %token <operation> EXISTS ESCAPE HAVING sqlGROUP sqlNULL %token <operation> FROM FOR MATCH @@ -1199,6 +1199,7 @@ index_def: opt_index_type: UNIQUE { $$ = hash_idx; } + | ORDERED { $$ = ordered_idx; } | /* empty */ { $$ = hash_idx; } ; diff --git a/sql/server/sql_scan.c b/sql/server/sql_scan.c --- a/sql/server/sql_scan.c +++ b/sql/server/sql_scan.c @@ -157,6 +157,7 @@ scanner_init_keywords(void) keywords_insert("OPTION", OPTION); keywords_insert("OR", OR); keywords_insert("ORDER", ORDER); + keywords_insert("ORDERED", ORDERED); keywords_insert("OUTER", OUTER); keywords_insert("OVER", OVER); keywords_insert("PARTITION", PARTITION); diff --git a/sql/storage/bat/bat_storage.c b/sql/storage/bat/bat_storage.c --- a/sql/storage/bat/bat_storage.c +++ b/sql/storage/bat/bat_storage.c @@ -12,6 +12,7 @@ #include <sql_string.h> #include <algebra.h> #include <gdk_atoms.h> +#include <orderidx.h> #define SNAPSHOT_MINSIZE ((BUN) 1024*128) @@ -123,7 +124,7 @@ bind_uidx(sql_trans *tr, sql_idx * i, in i->t->data = timestamp_dbat(ot->data, tr->stime); } i->base.rtime = i->t->base.rtime = i->t->s->base.rtime = tr->rtime = tr->stime; - u = delta_bind_ubat(i->data, access, (i->type==join_idx)?TYPE_oid:TYPE_wrd); + u = delta_bind_ubat(i->data, access, (oid_index(i->type))?TYPE_oid:TYPE_wrd); return u; } @@ -454,7 +455,7 @@ update_idx(sql_trans *tr, sql_idx * i, v return; if (!i->data || !i->base.allocated) { - int type = (i->type==join_idx)?TYPE_oid:TYPE_wrd; + int type = (oid_index(i->type))?TYPE_oid:TYPE_wrd; sql_idx *oi = tr_find_idx(tr->parent, i); sql_delta *bat = i->data = ZNEW(sql_delta), *obat = timestamp_delta(oi->data, tr->stime); (void)dup_bat(tr, i->t, obat, bat, type, isNew(i), i->base.flag == TR_NEW); @@ -562,7 +563,7 @@ dup_idx(sql_trans *tr, sql_idx *i, sql_i int ok = LOG_OK; if (i->data) { - int type = (ni->type==join_idx)?TYPE_oid:TYPE_wrd; + int type = (oid_index(ni->type))?TYPE_oid:TYPE_wrd; sql_delta *bat = ni->data = ZNEW(sql_delta), *obat = i->data; ok = dup_bat(tr, ni->t, obat, bat, type, isNew(i), ni->base.flag == TR_NEW); ni->base.allocated = 1; @@ -648,7 +649,7 @@ append_idx(sql_trans *tr, sql_idx * i, v return; if (!i->data || !i->base.allocated) { - int type = (i->type==join_idx)?TYPE_oid:TYPE_wrd; + int type = (oid_index(i->type))?TYPE_oid:TYPE_wrd; sql_idx *oi = tr_find_idx(tr->parent, i); sql_delta *bat = i->data = ZNEW(sql_delta), *obat = timestamp_delta(oi->data, tr->stime); (void)dup_bat(tr, i->t, obat, bat, type, isNew(i), i->base.flag == TR_NEW); @@ -1149,7 +1150,7 @@ create_idx(sql_trans *tr, sql_idx *ni) sql_delta *bat = ni->data; int type = TYPE_wrd; - if (ni->type == join_idx) + if (oid_index(ni->type)) type = TYPE_oid; if (!bat) { @@ -1168,6 +1169,8 @@ create_idx(sql_trans *tr, sql_idx *ni) sql_column *c = ni->t->columns.set->h->data; sql_delta *d; + if (ni->type == ordered_idx) + c = ((sql_kc*)ni->columns->h->data)->c; if (!c->data) { sql_column *oc = tr_find_column(tr->parent, c); c->data = timestamp_delta(oc->data, tr->stime); @@ -1176,7 +1179,19 @@ create_idx(sql_trans *tr, sql_idx *ni) /* Here we also handle indices created through alter stmts */ /* These need to be created aligned to the existing data */ - bat->bid = copyBat(d->bid, type, 0); + if (ni->type == ordered_idx) { + Client cntxt = mal_clients+tr->stk; + BAT *b = temp_descriptor(d->bid); + str msg; + + /* what to do with the result msg */ + msg = OIDXcreateImplementation(cntxt, newBatType(TYPE_void,type), b, -1); + assert(msg == NULL); + bat->bid = b->torderidx.o; + (void)msg; + bat_destroy(b); + } else + bat->bid = copyBat(d->bid, type, 0); bat->ibid = copyBat(d->ibid, type, d->ibase); bat->ibase = d->ibase; bat->cnt = d->cnt; @@ -1511,7 +1526,7 @@ static BUN clear_idx(sql_trans *tr, sql_idx *i) { if (!i->data || !i->base.allocated) { - int type = (i->type==join_idx)?TYPE_oid:TYPE_wrd; + int type = (oid_index(i->type))?TYPE_oid:TYPE_wrd; sql_idx *oi = tr_find_idx(tr->parent, i); sql_delta *bat = i->data = ZNEW(sql_delta), *obat = timestamp_delta(oi->data, tr->stime); (void)dup_bat(tr, i->t, obat, bat, type, isNew(i), i->base.flag == TR_NEW); @@ -1560,7 +1575,7 @@ empty_col(sql_column *c) static void empty_idx(sql_idx *i) { - int type = (i->type==join_idx)?TYPE_oid:TYPE_wrd; + int type = (oid_index(i->type))?TYPE_oid:TYPE_wrd; sql_delta *bat = i->data; assert(i->data && i->base.allocated && bat->bid == 0); _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list