Changeset: a8560005bdfc for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=a8560005bdfc
Added Files:
sql/backends/monet5/sql_orderidx.c
sql/backends/monet5/sql_orderidx.h
Modified Files:
clients/Tests/exports.stable.out
monetdb5/modules/mal/Tests/inspect05.stable.out.int128
monetdb5/modules/mal/orderidx.c
monetdb5/modules/mal/orderidx.h
monetdb5/modules/mal/orderidx.mal
sql/backends/monet5/Makefile.ag
sql/backends/monet5/sql.mal
sql/scripts/18_index.sql
sql/test/Tests/systemfunctions.stable.out
sql/test/Tests/systemfunctions.stable.out.int128
sql/test/leaks/Tests/check1.stable.out.int128
sql/test/leaks/Tests/check2.stable.out.int128
sql/test/leaks/Tests/check3.stable.out.int128
sql/test/leaks/Tests/check4.stable.out.int128
sql/test/leaks/Tests/check5.stable.out.int128
sql/test/orderidx/Tests/simpletable.sql
sql/test/orderidx/Tests/simpletable.stable.out
sql/test/orderidx/Tests/smalltable.sql
Branch: leftmart
Log Message:
Addition of sql commands
Extended SQL to trigger creation of order index.
To be done:
- in orderidx.c OIDXdropImplementation needs a call to remove the orderidx heap
- in orderidx.c and sql.c there is a reference to torderidx, which should
become a proper inspection of order index existence
- in orderidx.c OIDXgetorderindex should produce a new bat with the sorted oid
list based on the new heap
diffs (truncated from 793 to 300 lines):
diff --git a/clients/Tests/exports.stable.out b/clients/Tests/exports.stable.out
--- a/clients/Tests/exports.stable.out
+++ b/clients/Tests/exports.stable.out
@@ -1561,7 +1561,9 @@ str MTIMEtzone_tostr(str *s, const tzone
str MTIMEunix_epoch(timestamp *ret);
str OIDXcreate(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci);
str OIDXcreateImplementation(Client cntxt, int tpe, BAT *b, int pieces);
+str OIDXdropImplementation(Client cntxt, BAT *b);
str OIDXgetorderidx(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci);
+str OIDXhasorderidx(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci);
str OIDXmerge(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci);
void OPTaliasRemap(InstrPtr p, int *alias);
int OPTaliasesImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk,
InstrPtr p);
@@ -2455,7 +2457,6 @@ str recycleRef;
str reenterMAL(Client cntxt, MalBlkPtr mb, int startpc, int stoppc, MalStkPtr
stk);
str refineRef;
str registerRef;
-void register_http_handler(http_request_handler handler);
void releaseBAT(MalBlkPtr mb, MalStkPtr stk, int bid);
str remapRef;
str remoteRef;
diff --git a/monetdb5/modules/mal/Tests/inspect05.stable.out.int128
b/monetdb5/modules/mal/Tests/inspect05.stable.out.int128
--- a/monetdb5/modules/mal/Tests/inspect05.stable.out.int128
+++ b/monetdb5/modules/mal/Tests/inspect05.stable.out.int128
@@ -47,14 +47,14 @@ end user.main;
[ 6@0, "delete", "command", "bat",
"(b:bat[:oid,:any_1]):bat[:oid,:any_1] ", "BKCdelete_all;" ]
[ 7@0, "delete", "command", "bat",
"(b:bat[:oid,:any_1],h:oid):bat[:oid,:any_1] ", "BKCdelete;" ]
[ 8@0, "densebat", "command", "bat",
"(b:bat[:oid,:any_1],src:bat[:oid,:any_1]):bat[:oid,:any_1] ",
"BKCdelete_bat_bun;" ]
-[ 9@0, "getAccess", "pattern", "bat",
"(bv:bat[:oid,:any_1]):bat[:oid,:oid] ", "OIDXgetorderidx;" ]
-[ 10@0, "getCapacity", "command", "bat",
"(b:bat[:oid,:any_1]):str ", "BKCgetBBPname;" ]
-[ 11@0, "getColumnType", "command", "bat",
"(b:bat[:oid,:any_1]):oid ", "BKCgetSequenceBase;" ]
-[ 12@0, "getName", "command", "bat",
"(b:bat[:oid,:any_1]):str ", "BKCgetAccess;" ]
-[ 13@0, "getRole", "command", "bat",
"(bid:bat[:oid,:any_1]):str ", "BKCgetRole;" ]
-[ 14@0, "getSequenceBase", "command", "bat",
"(b:bat[:oid,:any_1]):str ", "BKCgetColumnType;" ]
-[ 15@0, "getSize", "command", "bat",
"(b:bat[:oid,:any_1]):lng ", "BKCgetCapacity;" ]
-[ 16@0, "getorderidx", "command", "bat",
"(b:bat[:oid,:any_1]):lng ", "BKCgetSize;" ]
+[ 9@0, "getAccess", "command", "bat", "(b:bat[:oid,:any_1]):str ",
"BKCgetBBPname;" ]
+[ 10@0, "getCapacity", "command", "bat",
"(b:bat[:oid,:any_1]):oid ", "BKCgetSequenceBase;" ]
+[ 11@0, "getColumnType", "command", "bat",
"(b:bat[:oid,:any_1]):str ", "BKCgetAccess;" ]
+[ 12@0, "getName", "command", "bat",
"(bid:bat[:oid,:any_1]):str ", "BKCgetRole;" ]
+[ 13@0, "getRole", "command", "bat",
"(b:bat[:oid,:any_1]):str ", "BKCgetColumnType;" ]
+[ 14@0, "getSequenceBase", "command", "bat",
"(b:bat[:oid,:any_1]):lng ", "BKCgetCapacity;" ]
+[ 15@0, "getSize", "command", "bat",
"(b:bat[:oid,:any_1]):lng ", "BKCgetSize;" ]
+[ 16@0, "hasorderidx", "pattern", "bat",
"(bv:bat[:oid,:any_1]):bat[:oid,:oid] ", "OIDXhasorderidx;" ]
[ 17@0, "imprints", "command", "bat", "(b:bat[:oid,:hge]):lng
", "CMDBATimprintsize;" ]
[ 18@0, "imprints", "command", "bat",
"(b:bat[:oid,:hge]):void ", "CMDBATimprints;" ]
[ 19@0, "imprints", "command", "bat", "(b:bat[:oid,:dbl]):lng
", "CMDBATimprintsize;" ]
diff --git a/monetdb5/modules/mal/orderidx.c b/monetdb5/modules/mal/orderidx.c
--- a/monetdb5/modules/mal/orderidx.c
+++ b/monetdb5/modules/mal/orderidx.c
@@ -17,6 +17,18 @@
#define MIN_PIECE 2 /* TODO use realistic size in production */
str
+OIDXdropImplementation(Client cntxt, BAT *b)
+{
+ str msg = MAL_SUCCEED;
+ (void) cntxt;
+ (void) b;
+ if ( b->torderidx){
+ // drop the order index heap
+ }
+ return msg;
+}
+
+str
OIDXcreateImplementation(Client cntxt, int tpe, BAT *b, int pieces)
{
int i, loopvar, arg;
@@ -156,6 +168,26 @@ OIDXcreate(Client cntxt, MalBlkPtr mb, M
}
str
+OIDXhasorderidx(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
+{
+ BAT *b;
+ int *ret = getArgReference_bat(stk,pci,0);
+ bat bid = *getArgReference_bat(stk, pci, 1);
+
+ (void) cntxt;
+ (void) mb;
+
+ b = BATdescriptor(bid);
+ if (b == NULL)
+ throw(MAL, "bat.hasorderidx", RUNTIME_OBJECT_MISSING);
+
+ *ret = b->torderidx;
+
+ BBPunfix(b->batCacheid);
+ return MAL_SUCCEED;
+}
+
+str
OIDXgetorderidx(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
{
BAT *b;
@@ -165,12 +197,12 @@ OIDXgetorderidx(Client cntxt, MalBlkPtr
(void) cntxt;
(void) mb;
-
b = BATdescriptor(bid);
if (b == NULL)
throw(MAL, "bat.getorderidx", RUNTIME_OBJECT_MISSING);
- *ret = b->torderidx;
+ // make a copy of the order index for inpection
+ *ret = 0;
BBPunfix(b->batCacheid);
return MAL_SUCCEED;
diff --git a/monetdb5/modules/mal/orderidx.h b/monetdb5/modules/mal/orderidx.h
--- a/monetdb5/modules/mal/orderidx.h
+++ b/monetdb5/modules/mal/orderidx.h
@@ -28,6 +28,8 @@
//#define _DEBUG_OIDX_
orderidx_export str OIDXcreate(Client cntxt, MalBlkPtr mb, MalStkPtr stk,
InstrPtr pci);
orderidx_export str OIDXcreateImplementation(Client cntxt, int tpe, BAT *b,
int pieces);
+orderidx_export str OIDXdropImplementation(Client cntxt, BAT *b);
orderidx_export str OIDXmerge(Client cntxt, MalBlkPtr mb, MalStkPtr stk,
InstrPtr pci);
+orderidx_export str OIDXhasorderidx(Client cntxt, MalBlkPtr mb, MalStkPtr stk,
InstrPtr pci);
orderidx_export str OIDXgetorderidx(Client cntxt, MalBlkPtr mb, MalStkPtr stk,
InstrPtr pci);
#endif /* _OIDX_H */
diff --git a/monetdb5/modules/mal/orderidx.mal
b/monetdb5/modules/mal/orderidx.mal
--- a/monetdb5/modules/mal/orderidx.mal
+++ b/monetdb5/modules/mal/orderidx.mal
@@ -10,9 +10,9 @@ pattern bat.orderidx(bv:bat[:oid,:any_1]
address OIDXmerge
comment "Consolidates the OID index arrangement";
-pattern bat.getorderidx(bv:bat[:oid,:any_1]):bat[:oid,:oid]
-address OIDXgetorderidx
-comment "Return the order index oid bat if exists (not safe, for debug)";
+pattern bat.hasorderidx(bv:bat[:oid,:any_1]):bat[:oid,:oid]
+address OIDXhasorderidx
+comment "Return true if order index exists";
function algebra.orderidx(bv:bat[:oid,:any_1], reverse:bit, stable:bit
):bat[:oid,:oid];
(v,o):= algebra.subsort(bv,reverse,stable);
diff --git a/sql/backends/monet5/Makefile.ag b/sql/backends/monet5/Makefile.ag
--- a/sql/backends/monet5/Makefile.ag
+++ b/sql/backends/monet5/Makefile.ag
@@ -46,6 +46,7 @@ lib__sql = {
sql_cast_impl_up_to_int.h \
sql_round.c sql_round_impl.h sql_bat2time.c \
sql_fround.c sql_fround_impl.h \
+ sql_orderidx.c sql_orderidx_impl.h \
sql_rank.c sql_rank.h
LIBS = ../../server/libsqlserver \
../../storage/libstore \
diff --git a/sql/backends/monet5/sql.mal b/sql/backends/monet5/sql.mal
--- a/sql/backends/monet5/sql.mal
+++ b/sql/backends/monet5/sql.mal
@@ -483,6 +483,14 @@ pattern storage()(
address sql_storage
comment "return a table with storage information ";
+pattern createorderindex(sch:str,tbl:str,col:str)
+address sql_createorderindex
+comment "Instantiate the order index on a column";
+
+pattern droporderindex(sch:str,tbl:str,col:str)
+address sql_droporderindex
+comment "Drop the order index on a column";
+
command calc.identity(:any_2) :oid
address SQLidentity
comment "Returns a unique row identitfier.";
diff --git a/sql/backends/monet5/sql_orderidx.c
b/sql/backends/monet5/sql_orderidx.c
new file mode 100644
--- /dev/null
+++ b/sql/backends/monet5/sql_orderidx.c
@@ -0,0 +1,131 @@
+/*
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * Copyright 2008-2015 MonetDB B.V.
+ */
+
+/* (c) M.L. Kersten
+ * The order index interface routines are defined here.
+*/
+#include "monetdb_config.h"
+#include "mal_backend.h"
+#include "sql_scenario.h"
+#include "sql_result.h"
+#include "sql_gencode.h"
+#include "sql_optimizer.h"
+#include "sql_env.h"
+#include "sql_mvc.h"
+#include "sql_orderidx.h"
+#include "orderidx.h"
+#include "sql_scenario.h"
+
+str
+sql_createorderindex(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
+{
+ mvc *m = NULL;
+ str msg = getSQLContext(cntxt, mb, &m, NULL);
+ sql_trans *tr = m->session->tr;
+ str sch,tbl,col;
+ node *nsch, *ntab, *ncol;
+ BAT *bn;
+
+ if (msg != MAL_SUCCEED || (msg = checkSQLContext(cntxt)) != NULL)
+ return msg;
+
+ sch = *getArgReference_str(stk, pci, 1);
+ tbl = *getArgReference_str(stk, pci, 2);
+ col = *getArgReference_str(stk, pci, 3);
+
+#ifdef DEBUG_SQL_ORDERIDX
+ mnstr_printf(cntxt->fdout, "#orderindex layout %s.%s.%s \n", sch, tbl,
col);
+#endif
+ for (nsch = tr->schemas.set->h; nsch; nsch = nsch->next) {
+ sql_base *b = nsch->data;
+ sql_schema *s = (sql_schema *) nsch->data;
+ if (!isalpha((int) b->name[0]))
+ continue;
+ if (sch && strcmp(sch, b->name))
+ continue;
+ if (s->tables.set)
+ for (ntab = (s)->tables.set->h; ntab; ntab =
ntab->next) {
+ sql_base *bt = ntab->data;
+ sql_table *t = (sql_table *) bt;
+
+ if (tbl && strcmp(bt->name, tbl))
+ continue;
+ if (isTable(t) && t->columns.set)
+ for (ncol = (t)->columns.set->h; ncol;
ncol = ncol->next) {
+ sql_base *bc = ncol->data;
+ sql_column *c = (sql_column *)
ncol->data;
+ if (col && strcmp(bc->name,
col))
+ continue;
+ bn =
store_funcs.bind_col(m->session->tr, c, 0);
+ if ( bn == 0){
+ msg =
createException(SQL,"sql","Column can not be accessed");
+ break;
+ }
+ // create the ordered index on
the column
+ msg =
OIDXcreateImplementation(cntxt, newBatType(TYPE_void,bn->ttype), bn, -1);
+ BBPunfix(bn->batCacheid);
+ if( msg)
+ break;
+ }
+ }
+ }
+ return msg;
+}
+
+str
+sql_droporderindex(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
+{
+ mvc *m = NULL;
+ str msg = getSQLContext(cntxt, mb, &m, NULL);
+ str sch,tbl,col;
+ sql_trans *tr = m->session->tr;
+ node *nsch, *ntab, *ncol;
+ BAT *bn;
+
+ if (msg != MAL_SUCCEED || (msg = checkSQLContext(cntxt)) != NULL)
+ return msg;
+
+ sch = *getArgReference_str(stk, pci, 1);
+ tbl = *getArgReference_str(stk, pci, 2);
+ col = *getArgReference_str(stk, pci, 3);
+
+#ifdef DEBUG_SQL_ORDERIDX
+ mnstr_printf(cntxt->fdout, "#orderindex layout %s.%s.%s \n", sch, tbl,
col);
+#endif
+ for (nsch = tr->schemas.set->h; nsch; nsch = nsch->next) {
+ sql_base *b = nsch->data;
+ sql_schema *s = (sql_schema *) nsch->data;
+ if (!isalpha((int) b->name[0]))
+ continue;
+ if (sch && strcmp(sch, b->name))
+ continue;
+ if (s->tables.set)
+ for (ntab = (s)->tables.set->h; ntab; ntab =
ntab->next) {
+ sql_base *bt = ntab->data;
+ sql_table *t = (sql_table *) bt;
+
+ if (tbl && strcmp(bt->name, tbl))
+ continue;
+ if (isTable(t) && t->columns.set)
+ for (ncol = (t)->columns.set->h; ncol;
ncol = ncol->next) {
+ sql_base *bc = ncol->data;
+ sql_column *c = (sql_column *)
ncol->data;
+ if (col && strcmp(bc->name,
col))
+ continue;
+ bn =
store_funcs.bind_col(m->session->tr, c, 0);
+ // create the ordered index on
the column
+ msg =
OIDXdropImplementation(cntxt, bn);
+
+ BBPunfix(bn->batCacheid);
+ (void) c;
+ }
+ }
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list