Changeset: 22aff1f226e8 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=22aff1f226e8 Removed Files: monetdb5/modules/mal/statistics.c monetdb5/modules/mal/statistics.h monetdb5/modules/mal/statistics.mal Branch: default Log Message:
Put statistics module into the attic diffs (truncated from 1042 to 300 lines): diff --git a/monetdb5/modules/mal/statistics.c b/monetdb5/modules/mal/statistics.c deleted file mode 100644 --- a/monetdb5/modules/mal/statistics.c +++ /dev/null @@ -1,859 +0,0 @@ -/* - * The contents of this file are subject to the MonetDB Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.monetdb.org/Legal/MonetDBLicense - * - * Software distributed under the License is distributed on an "AS IS" - * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the - * License for the specific language governing rights and limitations - * under the License. - * - * The Original Code is the MonetDB Database System. - * - * The Initial Developer of the Original Code is CWI. - * Portions created by CWI are Copyright (C) 1997-July 2008 CWI. - * Copyright August 2008-2012 MonetDB B.V. - * All Rights Reserved. -*/ -/* - * author M.L. Kersten - * Statistics box. - * Most optimizers need easy access to key information - * for proper plan generation. Amongst others, this - * volatile information consists of the tuple count, size, - * min- and max-value, the null-density, and - * a histogram of the value distribution. - * - * The statistics are management by a Box, which gives - * a controlled environment to manage a collection of BATs - * and system variables. - * - * BATs have to be deposit into the statistics box - * separately, because the costs attached maintaining them are high. - * The consistency of the statistics box is partly - * the responsibility of the upper layers. There is - * no automatic triggering when the BATs referenced - * are heavily modified or are being destroyed. - * They disappear from the statistics box the first time - * an invalid access is attempted or during system reboot. - * - * The staleness of the information can be controlled in several - * ways. The easiest, and most expensive, is to assure that - * the statistics are updated when you start the server. - * Alternative, you can set a expiration interval, which will - * update the information only when it is considered expired. - * This test will be triggered either at server restart or - * your explicit call to update the statistics tables. - * The statistics table is commited each time you change it. - * - * A forced update can be called upon when the front-end - * expects the situation to be changed drastically. - * - * The statistics table is mostly used internally, but - * once in a while you need a dump for closed inspection. - * in your MAL program for inspection. Just - * use the BBP bind operation to locate them in the buffer pool. - */ -#include "monetdb_config.h" -#include "statistics.h" -#include "algebra.h" - -BAT *STAT_id_inuse; /* BATs information taken from the box */ -BAT *STAT_id_nme; /* mapping from BBP index */ -BAT *STAT_id_expire; -BAT *STAT_id_stamp; /* BAT last time stamp */ -BAT *STAT_id_count; -BAT *STAT_id_size; -BAT *STAT_id_min_lng; -BAT *STAT_id_max_lng; -BAT *STAT_id_histogram; - -/* - * The statistics are currently limited to the server session. - * Upon need we can turn it into a persistent mode. - */ -static int statisticsMode= TRANSIENT; - -static BAT * -STAT_create(str hnme, str tnme, int ht, int tt) -{ - BAT *b; - char buf[128]; - - snprintf(buf, 128, "stat_%s_%s", hnme, tnme); - b = BATdescriptor(BBPindex(buf)); - if (b) - return b; - - b = BATnew(ht, tt, 256); - if (b == NULL) - return NULL; - - BATkey(b, TRUE); - BBPrename(b->batCacheid, buf); - BATmode(b, statisticsMode); -#ifdef DEBUG_STATISTICS - printf("created %s\n", buf); -#endif - return b; -} - -static void -STATcommit(void) -{ - bat b[10]; - - b[0] = 0; - b[1] = ABS(STAT_id_inuse->batCacheid); - b[2] = ABS(STAT_id_nme->batCacheid); - b[3] = ABS(STAT_id_expire->batCacheid); - b[4] = ABS(STAT_id_stamp->batCacheid); - b[5] = ABS(STAT_id_count->batCacheid); - b[6] = ABS(STAT_id_size->batCacheid); - b[7] = ABS(STAT_id_min_lng->batCacheid); - b[8] = ABS(STAT_id_max_lng->batCacheid); - b[9] = ABS(STAT_id_histogram->batCacheid); - TMsubcommit_list(b, 10); -} - -static void -STATinit(void) -{ - if( STAT_id_inuse) - return; - mal_set_lock(mal_contextLock, "statistics"); - STAT_id_inuse = STAT_create("id", "inuse", TYPE_void, TYPE_int); - STAT_id_nme = STAT_create("id", "nme", TYPE_void, TYPE_str); - STAT_id_expire = STAT_create("id", "expire", TYPE_void, TYPE_int); - STAT_id_stamp = STAT_create("id", "stamp", TYPE_void, TYPE_int); - STAT_id_count = STAT_create("id", "count", TYPE_void, TYPE_lng); - STAT_id_size = STAT_create("id", "size", TYPE_void, TYPE_lng); - STAT_id_min_lng = STAT_create("id", "min_lng", TYPE_void, TYPE_lng); - STAT_id_max_lng = STAT_create("id", "max_lng", TYPE_void, TYPE_lng); - STAT_id_histogram = STAT_create("id", "histogram", TYPE_void, TYPE_str); - if (STAT_id_inuse == NULL || - STAT_id_nme == NULL || - STAT_id_expire == NULL || - STAT_id_stamp == NULL || - STAT_id_count == NULL || - STAT_id_size == NULL || - STAT_id_min_lng == NULL || - STAT_id_max_lng == NULL || - STAT_id_histogram == NULL - ) { - if ( STAT_id_inuse != NULL ) - BBPclear(STAT_id_inuse->batCacheid); - STAT_id_inuse = NULL; - if ( STAT_id_nme != NULL ) - BBPclear(STAT_id_nme->batCacheid); - STAT_id_nme = NULL; - if ( STAT_id_expire != NULL ) - BBPclear(STAT_id_expire->batCacheid); - STAT_id_expire = NULL; - if ( STAT_id_stamp != NULL ) - BBPclear(STAT_id_stamp->batCacheid); - STAT_id_stamp = NULL; - if ( STAT_id_count != NULL ) - BBPclear(STAT_id_count->batCacheid); - STAT_id_count = NULL; - if ( STAT_id_size != NULL ) - BBPclear(STAT_id_size->batCacheid); - STAT_id_size = NULL; - if ( STAT_id_min_lng != NULL ) - BBPclear(STAT_id_min_lng->batCacheid); - STAT_id_min_lng = NULL; - if ( STAT_id_max_lng != NULL ) - BBPclear(STAT_id_max_lng->batCacheid); - STAT_id_max_lng = NULL; - if ( STAT_id_histogram != NULL ) - BBPclear(STAT_id_histogram->batCacheid); - STAT_id_histogram = NULL; - } else - STATcommit(); - mal_unset_lock(mal_contextLock, "statistics"); -} - -static void -STATexit(void) -{ - if(STAT_id_inuse ==0) return; - mal_set_lock(mal_contextLock, "statistics"); - - BBPreclaim(STAT_id_inuse); - BBPreclaim(STAT_id_nme); - BBPreclaim(STAT_id_expire); - BBPreclaim(STAT_id_stamp); - BBPreclaim(STAT_id_count); - BBPreclaim(STAT_id_size); - BBPreclaim(STAT_id_min_lng); - BBPreclaim(STAT_id_max_lng); - BBPreclaim(STAT_id_histogram); - - STAT_id_inuse= NULL; - STAT_id_nme= NULL; - STAT_id_expire= NULL; - STAT_id_stamp= NULL; - STAT_id_count= NULL; - STAT_id_size= NULL; - STAT_id_min_lng= NULL; - STAT_id_max_lng= NULL; - STAT_id_histogram= NULL; - - mal_unset_lock(mal_contextLock, "statistics"); -} - -str -STATdrop(str nme) -{ - BATiter STAT_id_nmei; - BUN p; - int idx; - - if(STAT_id_inuse ==0) - throw(MAL, "statistics.drop","Statistics not initialized"); - p = BUNfnd(BATmirror(STAT_id_nme), nme); - if (p == BUN_NONE) - throw(MAL, "statistics.drop", "BAT not enrolled"); - STAT_id_nmei = bat_iterator(STAT_id_nme); - idx = *(int *) BUNhead(STAT_id_nmei,p); - BUNdelHead(STAT_id_nme, &idx, FALSE); - BUNdelHead(STAT_id_expire, &idx, FALSE); - BUNdelHead(STAT_id_stamp, &idx, FALSE); - BUNdelHead(STAT_id_count, &idx, FALSE); - BUNdelHead(STAT_id_size, &idx, FALSE); - BUNdelHead(STAT_id_min_lng, &idx, FALSE); - BUNdelHead(STAT_id_max_lng, &idx, FALSE); - BUNdelHead(STAT_id_histogram, &idx, FALSE); - BUNdelHead(STAT_id_inuse, &idx, FALSE); - STATcommit(); - return MAL_SUCCEED; -} - -str -STATenroll(int *ret, str *nme) -{ - return STATforceUpdate(ret, nme); -} - -str -STATenrollHistogram(int *ret, str *nme) -{ - (void) ret; - (void) nme; - return MAL_SUCCEED; -} - -/* - * An update on all BATs in use can be requested. - * The amount of work is somewhat limited by ensuring - * that the underlying store has been changed - */ -str -STATupdateAll(int *ret, int forced) -{ - BAT *b; - BUN p, q; - str name; - int i; - - if (STAT_id_nme) { - BATiter STAT_id_nmei = bat_iterator(STAT_id_nme); - BATloop(STAT_id_nme, p, q) { - name = (str) BUNtail(STAT_id_nmei, p); - i = BBPindex(name); - if (i == 0) - continue; - if (forced == FALSE && BUNfnd(STAT_id_inuse, &i) == BUN_NONE) - continue; - b = BATdescriptor(i); - if (b == 0) { - /* BAT disappeared */ - if ((b = BATdescriptor(i)) == NULL) { - throw(MAL, "statistics.discard", RUNTIME_OBJECT_MISSING); - } - BBPunfix(b->batCacheid); - continue; - } - /* check the modification time with histogram */ - /* if BBPolder(i,j) ) */ { - STATforceUpdate(ret, &name); - } - } - } - return MAL_SUCCEED; -} - -str -STATupdate(int *ret) -{ - return STATupdateAll(ret, FALSE); -} - -str -STATforceUpdateAll(int *ret) -{ _______________________________________________ Checkin-list mailing list Checkin-list@monetdb.org http://mail.monetdb.org/mailman/listinfo/checkin-list