Changeset: ae297c5be999 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/ae297c5be999 Modified Files: sql/backends/monet5/dict.c sql/backends/monet5/sql.c Branch: dict Log Message:
small fix, ie after alter_storage the table/column is updated, so we need to use that new column added value bat order for the dictionary. diffs (89 lines): diff --git a/sql/backends/monet5/dict.c b/sql/backends/monet5/dict.c --- a/sql/backends/monet5/dict.c +++ b/sql/backends/monet5/dict.c @@ -6,6 +6,15 @@ #include "dict.h" +static sql_column * +get_newcolumn(sql_trans *tr, sql_column *c) +{ + sql_table *t = find_sql_table_id(tr, c->t->s, c->t->base.id); + if (t) + return find_sql_column(t, c->base.name); + return NULL; +} + str DICTcompress(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) { @@ -15,6 +24,7 @@ DICTcompress(Client cntxt, MalBlkPtr mb, const char *sname = *getArgReference_str(stk, pci, 1); const char *tname = *getArgReference_str(stk, pci, 2); const char *cname = *getArgReference_str(stk, pci, 3); + const bit ordered = (pci->argc > 4)?*getArgReference_bit(stk, pci, 4):FALSE; backend *be = NULL; sql_trans *tr = NULL; @@ -41,6 +51,7 @@ DICTcompress(Client cntxt, MalBlkPtr mb, BAT *u = BATunique(b, NULL); if (!u) throw(SQL, "dict.compress", SQLSTATE(HY013) MAL_MALLOC_FAIL); + assert(u->tkey); BUN cnt = BATcount(u); /* create hash on u */ @@ -51,12 +62,23 @@ DICTcompress(Client cntxt, MalBlkPtr mb, throw(SQL, "dict.compress", SQLSTATE(3F000) "dict compress: too many values"); } BAT *uv = BATproject(u, b); /* get values */ + uv->tkey = true; bat_destroy(u); if (!uv) { bat_destroy(b); throw(SQL, "dict.compress", SQLSTATE(HY013) MAL_MALLOC_FAIL); } - BAT *uu = COLcopy(uv, uv->ttype, true, PERSISTENT); + BAT *uu = NULL; + if (ordered) { + if (BATsort(&uu, NULL, NULL, uv, NULL, NULL, false, false, false) != GDK_SUCCEED) { + bat_destroy(uv); + throw(SQL, "dict.compress", SQLSTATE(HY013) MAL_MALLOC_FAIL); + } + bat_destroy(uv); + uv = uu; + } + uu = COLcopy(uv, uv->ttype, true, PERSISTENT); + assert(uu->tkey); if (!uu) { bat_destroy(uv); throw(SQL, "dict.compress", SQLSTATE(HY013) MAL_MALLOC_FAIL); @@ -87,7 +109,7 @@ DICTcompress(Client cntxt, MalBlkPtr mb, o->tnil = b->tnil; o->tnonil = b->tnonil; o->tkey = b->tkey; - if (sql_trans_alter_storage(tr, c, "DICT") != LOG_OK || store->storage_api.col_dict(tr, c, o, u) != LOG_OK) { + if (sql_trans_alter_storage(tr, c, "DICT") != LOG_OK || (c=get_newcolumn(tr, c)) == NULL || store->storage_api.col_dict(tr, c, o, u) != LOG_OK) { bat_iterator_end(&bi); throw(SQL, "dict.compress", SQLSTATE(HY013) "alter_storage failed"); } @@ -105,7 +127,7 @@ DICTcompress(Client cntxt, MalBlkPtr mb, o->tnil = b->tnil; o->tnonil = b->tnonil; o->tkey = b->tkey; - if (sql_trans_alter_storage(tr, c, "DICT") != LOG_OK || store->storage_api.col_dict(tr, c, o, u) != LOG_OK) { + if (sql_trans_alter_storage(tr, c, "DICT") != LOG_OK || (c=get_newcolumn(tr, c)) == NULL || store->storage_api.col_dict(tr, c, o, u) != LOG_OK) { bat_iterator_end(&bi); throw(SQL, "dict.compress", SQLSTATE(HY013) "alter_storage failed"); } 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 @@ -5396,6 +5396,7 @@ static mel_func sql_init_funcs[] = { pattern("sql", "copy_rejects", COPYrejects, false, "", args(4,4, batarg("rowid",lng),batarg("fldid",int),batarg("msg",str),batarg("inp",str))), pattern("sql", "copy_rejects_clear", COPYrejects_clear, true, "", noargs), pattern("dict", "compress", DICTcompress, false, "compress a sql column", args(0, 3, arg("schema", str), arg("table", str), arg("column", str))), + pattern("dict", "compress", DICTcompress, false, "compress a sql column", args(0, 4, arg("schema", str), arg("table", str), arg("column", str), arg("ordered", bit))), pattern("dict", "decompress", DICTdecompress, false, "decompress a dictionary compressed (sub)column", args(1, 3, batargany("", 1), batargany("o", 0), batargany("u", 1))), pattern("dict", "convert", DICTconvert, false, "convert candidate list into compressed offsets", args(1, 2, batargany("", 1), batargany("o", 0))), pattern("dict", "join", DICTjoin, false, "join 2 dictionaries", args(2, 10, batarg("r0", oid), batarg("r1", oid), batargany("lo", 0), batargany("lv", 1), batargany("ro", 0), batargany("rv", 1), batarg("lc", oid), batarg("rc", oid), arg("nil_matches",bit), arg("estimate",lng))), _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list