Changeset: 133d16b386d6 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=133d16b386d6
Modified Files:
sql/backends/monet5/sql.c
sql/backends/monet5/sql.h
sql/backends/monet5/sql.mal
Branch: mosaic
Log Message:
Add (de)compress command
diffs (165 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
@@ -43,6 +43,7 @@
#include <cluster.h>
#include <opt_pipes.h>
#include "clients.h"
+#include "mosaic.h"
#ifdef HAVE_RAPTOR
# include <rdf.h>
#endif
@@ -3882,6 +3883,123 @@ SQLargRecord(Client cntxt, MalBlkPtr mb,
}
/*
+ * Table (de-)compression schemes
+ */
+str
+SQLcompress(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
+{
+ str *sch = (str *) getArgReference(stk, pci, 1);
+ str *tbl = (str *) getArgReference(stk, pci, 2);
+ sql_trans *tr;
+ sql_schema *s;
+ sql_table *t;
+ sql_column *c;
+ mvc *m = NULL;
+ str msg;
+ bat bid;
+ BAT *b;
+ node *o;
+
+ if ((msg = getSQLContext(cntxt, mb, &m, NULL)) != NULL)
+ return msg;
+ if ((msg = checkSQLContext(cntxt)) != NULL)
+ return msg;
+ s = mvc_bind_schema(m, *sch);
+ if (s == NULL)
+ throw(SQL, "sql.compress", "3F000!Schema missing");
+ t = mvc_bind_table(m, s, *tbl);
+ if (t == NULL)
+ throw(SQL, "sql.compress", "42S02!Table missing");
+ if ( !t->readonly)
+ throw(SQL, "sql.compress", "!Table must be read only");
+ tr = m->session->tr;
+ t->base.wtime = s->base.wtime = tr->wtime = tr->wstime;
+ t->base.rtime = s->base.rtime = tr->rtime = tr->stime;
+
+ for (o = t->columns.set->h; o; o = o->next) {
+ sql_delta *d;
+ c = o->data;
+ b = store_funcs.bind_col(tr, c, 0);
+ if (b == NULL)
+ throw(SQL, "sql.compress", "Can not access descriptor");
+ msg =MOScompressInternal(cntxt, &bid, &b->batCacheid,0);
+ BBPreleaseref(b->batCacheid);
+ if (msg)
+ return msg;
+ d = c->data;
+ if (d->bid)
+ BBPdecref(d->bid, TRUE);
+ if (d->ibid)
+ BBPdecref(d->ibid, TRUE);
+ d->bid = bid;
+ d->ibase = 0;
+ d->ibid = 0; /* use the insert bat */
+ c->base.wtime = tr->wstime;
+ c->base.rtime = tr->stime;
+ }
+ /* bat was cleared */
+ t->cleared = 1;
+ return MAL_SUCCEED;
+}
+
+str
+SQLdecompress(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
+{
+ str *sch = (str *) getArgReference(stk, pci, 1);
+ str *tbl = (str *) getArgReference(stk, pci, 2);
+ sql_trans *tr;
+ sql_schema *s;
+ sql_table *t;
+ sql_column *c;
+ mvc *m = NULL;
+ str msg;
+ bat bid;
+ BAT *b;
+ node *o;
+
+ if ((msg = getSQLContext(cntxt, mb, &m, NULL)) != NULL)
+ return msg;
+ if ((msg = checkSQLContext(cntxt)) != NULL)
+ return msg;
+ s = mvc_bind_schema(m, *sch);
+ if (s == NULL)
+ throw(SQL, "sql.decompress", "3F000!Schema missing");
+ t = mvc_bind_table(m, s, *tbl);
+ if (t == NULL)
+ throw(SQL, "sql.decompress", "42S02!Table missing");
+ if ( !t->readonly)
+ throw(SQL, "sql.compress", "!Table must be read only");
+ tr = m->session->tr;
+ t->base.wtime = s->base.wtime = tr->wtime = tr->wstime;
+ t->base.rtime = s->base.rtime = tr->rtime = tr->stime;
+
+ for (o = t->columns.set->h; o; o = o->next) {
+ sql_delta *d;
+ c = o->data;
+ b = store_funcs.bind_col(tr, c, 0);
+ if (b == NULL)
+ throw(SQL, "sql.decompress", "Can not access
descriptor");
+ msg =MOSdecompressInternal(cntxt, &bid, &b->batCacheid);
+ BBPreleaseref(b->batCacheid);
+ if (msg)
+ return msg;
+ d = c->data;
+ if (d->bid)
+ BBPdecref(d->bid, TRUE);
+ if (d->ibid)
+ BBPdecref(d->ibid, TRUE);
+ d->bid = bid;
+ d->ibase = 0;
+ d->ibid = 0; /* use the insert bat */
+ c->base.wtime = tr->wstime;
+ c->base.rtime = tr->stime;
+ }
+ /* bat was cleared */
+ t->cleared = 1;
+ return MAL_SUCCEED;
+}
+
+/*
* The table is searched for all columns and they are
* re-clustered on the hash value over the primary key.
* Initially the first column
diff --git a/sql/backends/monet5/sql.h b/sql/backends/monet5/sql.h
--- a/sql/backends/monet5/sql.h
+++ b/sql/backends/monet5/sql.h
@@ -130,6 +130,8 @@ sql5_export str mvc_restart_seq(Client c
sql5_export str zero_or_one(ptr ret, int *bid);
sql5_export str not_unique(bit *ret, int *bid);
sql5_export str not_unique_oids(bat *ret, bat *bid);
+sql5_export str SQLcompress(Client cntxt, MalBlkPtr mb, MalStkPtr stk,
InstrPtr pci);
+sql5_export str SQLdecompress(Client cntxt, MalBlkPtr mb, MalStkPtr stk,
InstrPtr pci);
sql5_export str SQLcluster1(Client cntxt, MalBlkPtr mb, MalStkPtr stk,
InstrPtr pci);
sql5_export str SQLcluster2(Client cntxt, MalBlkPtr mb, MalStkPtr stk,
InstrPtr pci);
sql5_export str SQLshrink(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr
pci);
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
@@ -958,6 +958,14 @@ command calc.rowid(v:any_1, schema:str,
address sql_rowid
comment "return the next rowid";
+pattern compress(sch:str, tbl:str)
+address SQLcompress
+comment "Compress all columns of a readonly table";
+
+pattern decompress(sch:str, tbl:str)
+address SQLdecompress
+comment "Decompress all columns of a readonly table";
+
pattern cluster1(sch:str, tbl:str)
address SQLcluster1
comment "Cluster the columns of a table on the (first) primary key";
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list