Changeset: ac0d35da5cf7 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=ac0d35da5cf7
Modified Files:
        gdk/gdk_sample.c
        sql/backends/monet5/sql.c
        sql/server/sql_parser.y
        sql/server/sql_scan.c
        sql/test/BugTracker-2014/Tests/temporary.Bug-3430.stable.err
Branch: default
Log Message:

Merge with Oct2014 branch.


diffs (truncated from 327 to 300 lines):

diff --git a/gdk/gdk_sample.c b/gdk/gdk_sample.c
--- a/gdk/gdk_sample.c
+++ b/gdk/gdk_sample.c
@@ -21,17 +21,17 @@
  * @a Lefteris Sidirourgos, Hannes Muehleisen
  * @* Low level sample facilities
  *
- * This sampling implementation generates a sorted set of OIDs by calling the
- * random number generator, and uses a binary tree to eliminate duplicates.
- * The elements of the tree are then used to create a sorted sample BAT.
- * This implementation has a logarithmic complexity that only depends on the
- * sample size.
+ * This sampling implementation generates a sorted set of OIDs by
+ * calling the random number generator, and uses a binary tree to
+ * eliminate duplicates.  The elements of the tree are then used to
+ * create a sorted sample BAT.  This implementation has a logarithmic
+ * complexity that only depends on the sample size.
  *
- * There is a pathological case when the sample size is almost the size of the 
BAT.
- * Then, many collisions occur and performance degrades. To catch this, we 
- * switch to antiset semantics when the sample size is larger than half the BAT
- * size. Then, we generate the values that should be omitted from the sample.
- *
+ * There is a pathological case when the sample size is almost the
+ * size of the BAT.  Then, many collisions occur and performance
+ * degrades. To catch this, we switch to antiset semantics when the
+ * sample size is larger than half the BAT size. Then, we generate the
+ * values that should be omitted from the sample.
  */
 
 #include "monetdb_config.h"
@@ -43,34 +43,30 @@
 #ifdef STATIC_CODE_ANALYSIS
 #define DRAND (0.5)
 #else
-#define DRAND ((double)rand()/(double)RAND_MAX)
+/* the range of rand() is [0..RAND_MAX], i.e. inclusive;
+ * cast first, add later: on Linux RAND_MAX == INT_MAX, so adding 1
+ * will overflow, but INT_MAX does fit in a double */
+#if RAND_MAX < 46340       /* 46340*46340 = 2147395600 < INT_MAX */
+/* random range is too small, double it */
+#define DRAND ((double)(rand() * (RAND_MAX + 1) + rand()) / ((double) 
((RAND_MAX + 1) * (RAND_MAX + 1))))
+#else
+#define DRAND ((double)rand() / ((double)RAND_MAX + 1))
+#endif
 #endif
 
 
 /* this is a straightforward implementation of a binary tree */
 struct oidtreenode {
        BUN oid;
-       struct oidtreenode* left;
-       struct oidtreenode* right;
+       struct oidtreenode *left;
+       struct oidtreenode *right;
 };
 
-static int OIDTreeLookup(struct oidtreenode* node, BUN target) {
-       if (node == NULL) {
-               return (FALSE);
-       } else {
-               if (target == node->oid)
-                       return (TRUE);
-               else {
-                       if (target < node->oid)
-                               return (OIDTreeLookup(node->left, target));
-                       else
-                               return (OIDTreeLookup(node->right, target));
-               }
-       }
-}
+static struct oidtreenode *
+OIDTreeNew(BUN oid)
+{
+       struct oidtreenode *node = GDKmalloc(sizeof(struct oidtreenode));
 
-static struct oidtreenode* OIDTreeNew(BUN oid) {
-       struct oidtreenode *node = GDKmalloc(sizeof(struct oidtreenode));
        if (node == NULL) {
                GDKerror("#BATsample: memory allocation error");
                return NULL ;
@@ -78,23 +74,29 @@ static struct oidtreenode* OIDTreeNew(BU
        node->oid = oid;
        node->left = NULL;
        node->right = NULL;
-       return (node);
+       return node;
 }
 
-static struct oidtreenode* OIDTreeInsert(struct oidtreenode* node, BUN oid) {
-       if (node == NULL) {
-               return (OIDTreeNew(oid));
-       } else {
-               if (oid <= node->oid)
-                       node->left = OIDTreeInsert(node->left, oid);
+static int
+OIDTreeMaybeInsert(struct oidtreenode **nodep, BUN oid)
+{
+       while (*nodep) {
+               if (oid == (*nodep)->oid)
+                       return 0;
+               if (oid < (*nodep)->oid)
+                       nodep = &(*nodep)->left;
                else
-                       node->right = OIDTreeInsert(node->right, oid);
-               return (node);
+                       nodep = &(*nodep)->right;
        }
+       if ((*nodep = OIDTreeNew(oid)) == NULL)
+               return -1;
+       return 1;
 }
 
 /* inorder traversal, gives us a sorted BAT */
-static void OIDTreeToBAT(struct oidtreenode* node, BAT *bat) {
+static void
+OIDTreeToBAT(struct oidtreenode *node, BAT *bat)
+{
        if (node->left != NULL)
                OIDTreeToBAT(node->left, bat);
        ((oid *) bat->T->heap.base)[bat->batFirst + bat->batCount++] = 
node->oid;
@@ -103,14 +105,17 @@ static void OIDTreeToBAT(struct oidtreen
 }
 
 /* Antiset traversal, give us all values but the ones in the tree */
-static void OIDTreeToBATAntiset(struct oidtreenode* node, BAT *bat, BUN start, 
BUN stop) {
+static void
+OIDTreeToBATAntiset(struct oidtreenode *node, BAT *bat, BUN start, BUN stop)
+{
        BUN noid;
+
        if (node->left != NULL)
                OIDTreeToBATAntiset(node->left, bat, start, node->oid);
-       else 
+       else
                for (noid = start+1; noid < node->oid; noid++)
-                       ((oid *) bat->T->heap.base)[bat->batFirst + 
bat->batCount++] = noid;                    
-       
+                       ((oid *) bat->T->heap.base)[bat->batFirst + 
bat->batCount++] = noid;
+
         if (node->right != NULL)
                OIDTreeToBATAntiset(node->right, bat, node->oid, stop);
        else
@@ -118,7 +123,9 @@ static void OIDTreeToBATAntiset(struct o
                         ((oid *) bat->T->heap.base)[bat->batFirst + 
bat->batCount++] = noid;
 }
 
-static void OIDTreeDestroy(struct oidtreenode* node) {
+static void
+OIDTreeDestroy(struct oidtreenode *node)
+{
        if (node == NULL) {
                return;
        }
@@ -134,11 +141,12 @@ static void OIDTreeDestroy(struct oidtre
 
 /* BATsample implements sampling for void headed BATs */
 BAT *
-BATsample(BAT *b, BUN n) {
+BATsample(BAT *b, BUN n)
+{
        BAT *bn;
        BUN cnt, slen;
        BUN rescnt = 0;
-       struct oidtreenode* tree = NULL;
+       struct oidtreenode *tree = NULL;
 
        BATcheck(b, "BATsample");
        assert(BAThdense(b));
@@ -170,41 +178,41 @@ BATsample(BAT *b, BUN n) {
        } else {
                BUN minoid = b->hseqbase;
                BUN maxoid = b->hseqbase + cnt;
-               /* if someone samples more than half of our tree, we do the 
antiset */
-               bit antiset = n > cnt/2;
+               /* if someone samples more than half of our tree, we
+                * do the antiset */
+               bit antiset = n > cnt / 2;
                slen = n;
-               if (antiset) 
+               if (antiset)
                        n = cnt - n;
-               
+
                bn = BATnew(TYPE_void, TYPE_oid, slen, TRANSIENT);
-               if (bn == NULL ) {
+               if (bn == NULL) {
                        GDKerror("#BATsample: memory allocation error");
                        return NULL;
                }
                /* while we do not have enough sample OIDs yet */
                while (rescnt < n) {
                        BUN candoid;
-                       struct oidtreenode* ttree;
+                       int rc;
                        do {
                                /* generate a new random OID */
-                               /* coverity[dont_call] */
                                candoid = (BUN) (minoid + DRAND * (maxoid - 
minoid));
-                               /* if that candidate OID was already generated, 
try again */
-                       } while (OIDTreeLookup(tree, candoid));
-                       ttree = OIDTreeInsert(tree, candoid);
-                       if (ttree == NULL) {
+                               /* if that candidate OID was already
+                                * generated, try again */
+                       } while ((rc = OIDTreeMaybeInsert(&tree, candoid)) == 
0);
+                       if (rc < 0) {
                                GDKerror("#BATsample: memory allocation error");
-                               /* if malloc fails, we still need to clean up 
the tree */
+                               /* if malloc fails, we still need to
+                                * clean up the tree */
                                OIDTreeDestroy(tree);
                                return NULL;
                        }
-                       tree = ttree;
                        rescnt++;
                }
                if (!antiset) {
                        OIDTreeToBAT(tree, bn);
                } else {
-                       OIDTreeToBATAntiset(tree, bn, minoid-1, maxoid+1);
+                       OIDTreeToBATAntiset(tree, bn, minoid - 1, maxoid + 1);
                }
                OIDTreeDestroy(tree);
 
@@ -223,4 +231,3 @@ BATsample(BAT *b, BUN n) {
        }
        return bn;
 }
-
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
@@ -358,13 +358,13 @@ SQLabort(Client cntxt, MalBlkPtr mb, Mal
 str
 SQLshutdown_wrap(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
 {
-       str answ = *getArgReference_str(stk, pci, 0);
-
-       CLTshutdown(cntxt, mb, stk, pci);
-
-       // administer the shutdown
-       mnstr_printf(GDKstdout, "#%s\n", answ);
-       return MAL_SUCCEED;
+       str msg;
+
+       if ((msg = CLTshutdown(cntxt, mb, stk, pci)) == MAL_SUCCEED) {
+               // administer the shutdown
+               mnstr_printf(GDKstdout, "#%s\n", *getArgReference_str(stk, pci, 
0));
+       }
+       return msg;
 }
 
 str
diff --git a/sql/server/sql_parser.y b/sql/server/sql_parser.y
--- a/sql/server/sql_parser.y
+++ b/sql/server/sql_parser.y
@@ -539,7 +539,7 @@ CONTINUE CURRENT CURSOR FOUND GOTO GO LA
 SQLCODE SQLERROR UNDER WHENEVER
 */
 
-%token TEMPORARY STREAM MERGE REMOTE REPLICA
+%token TEMP TEMPORARY STREAM MERGE REMOTE REPLICA
 %token<sval> ASC DESC AUTHORIZATION
 %token CHECK CONSTRAINT CREATE
 %token TYPE PROCEDURE FUNCTION AGGREGATE RETURNS EXTERNAL sqlNAME DECLARE
@@ -1376,8 +1376,11 @@ table_def:
 
 opt_temp:
     TEMPORARY          { $$ = SQL_LOCAL_TEMP; }
+ |  TEMP               { $$ = SQL_LOCAL_TEMP; }
  |  LOCAL TEMPORARY    { $$ = SQL_LOCAL_TEMP; }
+ |  LOCAL TEMP         { $$ = SQL_LOCAL_TEMP; }
  |  GLOBAL TEMPORARY   { $$ = SQL_GLOBAL_TEMP; }
+ |  GLOBAL TEMP                { $$ = SQL_GLOBAL_TEMP; }
  ;
 
 opt_on_commit: /* only for temporary tables */
@@ -4883,6 +4886,7 @@ non_reserved_word:
 |  URI         { $$ = sa_strdup(SA, "uri"); }
 |  FILTER      { $$ = sa_strdup(SA, "filter"); }
 |  TEMPORARY   { $$ = sa_strdup(SA, "temporary"); }
+|  TEMP                { $$ = sa_strdup(SA, "temp"); }
 |  ANALYZE     { $$ = sa_strdup(SA, "analyze"); }
 ;
 
diff --git a/sql/server/sql_scan.c b/sql/server/sql_scan.c
--- a/sql/server/sql_scan.c
+++ b/sql/server/sql_scan.c
@@ -200,7 +200,7 @@ scanner_init_keywords(void)
        keywords_insert("COLUMN", COLUMN);
        keywords_insert("TABLE", TABLE);
        keywords_insert("TEMPORARY", TEMPORARY);
-       keywords_insert("TEMP", TEMPORARY);
+       keywords_insert("TEMP", TEMP);
        keywords_insert("STREAM", STREAM);
        keywords_insert("REMOTE", REMOTE);
        keywords_insert("MERGE", MERGE);
diff --git a/sql/test/BugTracker-2014/Tests/temporary.Bug-3430.stable.err 
b/sql/test/BugTracker-2014/Tests/temporary.Bug-3430.stable.err
--- a/sql/test/BugTracker-2014/Tests/temporary.Bug-3430.stable.err
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to