Changeset: 794ba711da4a for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=794ba711da4a
Modified Files:
monetdb5/modules/mosaic/mosaic.c
monetdb5/modules/mosaic/mosaic.h
monetdb5/modules/mosaic/mosaic_hdr.c
sql/backends/monet5/sql_cat.c
Branch: mosaic
Log Message:
Remove MOStask from MOScompressInternal signature.
diffs (270 lines):
diff --git a/monetdb5/modules/mosaic/mosaic.c b/monetdb5/modules/mosaic/mosaic.c
--- a/monetdb5/modules/mosaic/mosaic.c
+++ b/monetdb5/modules/mosaic/mosaic.c
@@ -43,7 +43,23 @@ bool type_allowed(int compression, BAT*
}
static void
-MOSinit(MOStask task, BAT *b){
+MOSinitializeFilter(MOStask task, const char* compressions) {
+ if (!GDK_STRNIL(compressions)) {
+ for(int i = 0; i< MOSAIC_METHODS-1; i++) {
+ task->filter[i] = strstr(compressions,
MOSfiltername[i]) != 0 && type_allowed(i, task->bsrc);
+ task->hdr->elms[i] = task->hdr->blks[i] = 0;
+ }
+ }
+ else {
+ for(int i = 0; i< MOSAIC_METHODS-1; i++) {
+ task->filter[i] = 1;
+ task->hdr->elms[i] = task->hdr->blks[i] = 0;
+ }
+ }
+}
+
+static void
+MOSinit(MOStask task, BAT *b) {
char *base;
if( VIEWmosaictparent(b) != 0)
b= BATdescriptor(VIEWmosaictparent(b));
@@ -234,8 +250,9 @@ MOSoptimizerCost(Client cntxt, MOStask t
/* the source is extended with a BAT mosaic heap */
str
-MOScompressInternal(Client cntxt, BAT* bsrc, MOStask task)
+MOScompressInternal(Client cntxt, BAT* bsrc, const char* compressions)
{
+ MOStask task;
BAT *o = NULL; // the BAT to be augmented with a compressed
heap
str msg = MAL_SUCCEED;
int cand;
@@ -289,6 +306,10 @@ MOScompressInternal(Client cntxt, BAT* b
}
assert(bsrc->tmosaic->parentid == bsrc->batCacheid);
+
+ if((task = (MOStask) GDKzalloc(sizeof(*task))) == NULL) {
+ throw(MAL, "mosaic.compress", MAL_MALLOC_FAIL);
+ }
// initialize the non-compressed read pointer
task->src = Tloc(bsrc, 0);
@@ -299,6 +320,7 @@ MOScompressInternal(Client cntxt, BAT* b
MOSinit(task,bsrc);
task->blk->cnt= 0;
+ MOSinitializeFilter(task, compressions);
MOSinitHeader(task);
// claim the server for exclusive use
@@ -428,8 +450,6 @@ str
MOScompress(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
{
str msg = MAL_SUCCEED;
- int i;
- MOStask task;
BAT *b;
bat *bid =getArgReference_bat(stk,pci,1);
bat *ret =getArgReference_bat(stk,pci,0);
@@ -444,24 +464,17 @@ MOScompress(Client cntxt, MalBlkPtr mb,
}
(void) mb;
- task= (MOStask) GDKzalloc(sizeof(*task));
- if( task == NULL){
- BBPunfix(b->batCacheid);
- throw(MAL, "mosaic.compress", MAL_MALLOC_FAIL);
+
+ const char* compressions;
+ if( pci->argc == 3) {
+ compressions = *getArgReference_str(stk,pci,2);
+ }
+ else {
+ compressions = str_nil;
}
- if( pci->argc == 3)
- msg = *getArgReference_str(stk,pci,2);
- if( msg && !strstr(msg,"mosaic"))
- for( i = 0; i< MOSAIC_METHODS-1; i++)
- task->filter[i]= strstr(msg,MOSfiltername[i]) != 0 &&
type_allowed(i, b);
- else
- for( i = 0; i< MOSAIC_METHODS-1; i++)
- task->filter[i]= type_allowed(i, b);
-
- msg= MOScompressInternal(cntxt, b, task);
+ msg= MOScompressInternal(cntxt, b, compressions);
BBPkeepref(*ret = b->batCacheid);
- GDKfree(task);
return msg;
}
@@ -1201,13 +1214,11 @@ void
MOSanalyseReport(Client cntxt, BAT *b, BAT *btech, BAT *boutput, BAT *bratio,
BAT *bcompress, BAT *bdecompress, str compressions)
{
int i,j,k,cases, bit=1, bid= b->batCacheid;
- MOStask task;
int pattern[CANDIDATES];
char buf[1024]={0}, *t;
- task = (MOStask) GDKzalloc(sizeof(*task));
- if( task == NULL)
- return;
+ int filter[MOSAIC_METHODS];
+
// create the list of all possible 2^6 compression patterns
cases = makepatterns(pattern,CANDIDATES, compressions, b);
memset((char*)pat,0, sizeof(pat));
@@ -1224,43 +1235,47 @@ MOSanalyseReport(Client cntxt, BAT *b, B
t= buf;
*t =0;
+ memset(filter, 0, sizeof(filter));
for(j=0, bit=1; j < MOSAIC_METHODS-1; j++){
- task->filter[j]= (pattern[i] & bit)>0;
- task->range[j]= 0;
- task->factor[j]= 0.0;
+ filter[j]= (pattern[i] & bit)>0;
bit *=2;
- if( task->filter[j]){
+ if( filter[j]){
snprintf(t, 1024-strlen(buf),"%s ",
MOSfiltername[j]);
t= buf + strlen(buf);
}
}
+ *t = '\0';
+
+ t = buf;
+
pat[i].technique= GDKstrdup(buf);
pat[i].clk1 = GDKms();
// TODO: keep a potentially pre-existing mosaic_heap aside.
- MOScompressInternal(cntxt, b, task);
+ const char* compressions = buf;
+ MOScompressInternal(cntxt, b, compressions);
pat[i].clk1 = GDKms()- pat[i].clk1;
#ifdef _DEBUG_MOSAIC_
mnstr_printf(cntxt->fdout,"#run experiment %d ratio %6.4f
"LLFMT" ms %s\n",i, task->ratio, pat[i].clk1, pat[i].technique);
#endif
- if( task->hdr == NULL){
+ if(b->tmosaic == NULL){
// aborted compression experiment
MOSdestroy(BBPdescriptor(bid));
continue;
}
// analyse result block distribution to detect a new
compression combination
for(k=0, j=0, bit=1; j < MOSAIC_METHODS-1; j++){
- if ( task->filter[j] && task->hdr->blks[j])
+ if ( ((MosaicHdr) b->tmosaic->base)->blks[j] > 0)
k |= bit;
bit *=2;
}
for( j=0; j < i; j++)
if (pattern[j] == k )
break;
- pat[i].xsize = (BUN) task->bsrc->tmosaic->free;
- pat[i].xf= task->ratio;
+ pat[i].xsize = (BUN) b->tmosaic->free;
+ pat[i].xf= ((MosaicHdr) b->tmosaic->base)->ratio;
BAT* decompressed;
pat[i].clk2 = GDKms();
@@ -1286,7 +1301,6 @@ MOSanalyseReport(Client cntxt, BAT *b, B
}
if( pat[i].technique) GDKfree(pat[i].technique);
}
- GDKfree(task);
}
/* slice a fixed size atom into thin bte-wide columns, used for experiments */
diff --git a/monetdb5/modules/mosaic/mosaic.h b/monetdb5/modules/mosaic/mosaic.h
--- a/monetdb5/modules/mosaic/mosaic.h
+++ b/monetdb5/modules/mosaic/mosaic.h
@@ -48,6 +48,8 @@
*/
typedef Heap *mosaic; // compressed data is stored on a heap.
+#define METHOD_NOT_AVAILABLE -1
+
typedef struct MOSAICHEADER{
int version;
union{
@@ -98,9 +100,10 @@ typedef struct MOSAICHEADER{
#endif
}frame;
// collect compression statistics for the particular task
+ // A value of METHOD_NOT_AVAILABLE in blks or elms indicates that the
corresponding method wasn't considered as candidate.
flt ratio; //compresion ratio
- lng blks[MOSAIC_METHODS];
- lng elms[MOSAIC_METHODS];
+ lng blks[MOSAIC_METHODS]; // number of blks per method.
+ lng elms[MOSAIC_METHODS]; // number of compressed values in all blocks
for this method.
lng framefreq[256];
} * MosaicHdr;
@@ -191,7 +194,7 @@ mal_export char *MOSfiltername[];
mal_export bool type_allowed(int compression, BAT* b);
mal_export str MOScompress(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr
pci);
mal_export str MOSdecompress(Client cntxt, MalBlkPtr mb, MalStkPtr stk,
InstrPtr pci);
-mal_export str MOScompressInternal(Client cntxt, BAT* bsrc, MOStask task); //
TODO: I don't like to export internal functions
+mal_export str MOScompressInternal(Client cntxt, BAT* bsrc, const char*
compressions);
mal_export str MOSanalyse(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr
pci);
mal_export str MOSselect(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr
pci);
mal_export str MOSthetaselect(Client cntxt, MalBlkPtr mb, MalStkPtr stk,
InstrPtr pci);
diff --git a/monetdb5/modules/mosaic/mosaic_hdr.c
b/monetdb5/modules/mosaic/mosaic_hdr.c
--- a/monetdb5/modules/mosaic/mosaic_hdr.c
+++ b/monetdb5/modules/mosaic/mosaic_hdr.c
@@ -63,7 +63,7 @@ MOSinitHeader(MOStask task)
MosaicHdr hdr = (MosaicHdr) task->hdr;
int i;
for(i=0; i < MOSAIC_METHODS; i++){
- hdr->elms[i] = hdr->blks[i] = 0;
+ hdr->elms[i] = hdr->blks[i] = METHOD_NOT_AVAILABLE;
task->range[i]=0;
task->factor[i]=0.0;
}
diff --git a/sql/backends/monet5/sql_cat.c b/sql/backends/monet5/sql_cat.c
--- a/sql/backends/monet5/sql_cat.c
+++ b/sql/backends/monet5/sql_cat.c
@@ -898,7 +898,7 @@ alter_table(Client cntxt, mvc *sql, char
size_t cnt;
sql_delta *d;
char *msg = MAL_SUCCEED;
- MOStask task;
+ int filter[MOSAIC_METHODS];
/* no restriction
if (c->t->access == TABLE_WRITABLE)
return sql_message("40002!ALTER TABLE: SET
STORAGE for column %s.%s only allowed on READ or INSERT ONLY tables",
c->t->base.name, c->base.name);
@@ -912,27 +912,22 @@ alter_table(Client cntxt, mvc *sql, char
continue;
}
- // TODO check where this task is cleaned up.
- task = (MOStask) GDKzalloc(sizeof(*task));
if( c->storage_type) {
+ memset(filter,0, sizeof(filter));
if (strstr(c->storage_type,"mosaic") != 0)
throw(SQL,
"sql.alter",
MOSAIC_STRATEGY_NOT_ALLOWED);
- if( task == NULL)
- throw(SQL, "sql.alter",
MAL_MALLOC_FAIL);
-
for(int i = 0, nr_strategies = 0; i<
MOSAIC_METHODS-1; i++){
- if ( (task->filter[i] =
strstr(c->storage_type,MOSfiltername[i]) != 0 && type_allowed(i, b) ))
+ if ( (filter[i] =
strstr(c->storage_type,MOSfiltername[i]) != 0 && type_allowed(i, b) ))
{
if
(strstr(c->storage_type,"raw") == 0 && ++nr_strategies > 1)
throw(SQL, "sql.alter",
NON_TRIVIAL_MIX_NOT_ALLOWED);
}
}
- // TODO: check if there should be something
like "else {remove_mosaic_index()}".
- msg = MOScompressInternal(cntxt, b, task);
+ msg = MOScompressInternal(cntxt, b,
c->storage_type);
}
BBPunfix(b->batCacheid);
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list