Changeset: 1f9133b9ad1a for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/1f9133b9ad1a
Modified Files:
        clients/odbc/tests/ODBCtester.c
        gdk/gdk.h
        gdk/gdk_utils.c
        sql/backends/monet5/rel_bin.c
        sql/server/rel_select.c
        sql/server/rel_unnest.c
        sql/server/sql_parser.y
        sql/test/BugTracker-2025/Tests/All
Branch: default
Log Message:

Merge with Mar2025 branch


diffs (truncated from 807 to 300 lines):

diff --git a/clients/odbc/driver/ODBCConvert.c 
b/clients/odbc/driver/ODBCConvert.c
--- a/clients/odbc/driver/ODBCConvert.c
+++ b/clients/odbc/driver/ODBCConvert.c
@@ -49,7 +49,7 @@ typedef struct {
  * 0 is returned if the string is not a number, or if scale doesn't fit.
  */
 static int
-parseint(const char *data, bignum_t *nval)
+parsebignum(const char *data, bignum_t *nval)
 {
        int fraction = 0;       /* inside the fractional part */
        int scale = 0;
@@ -57,7 +57,7 @@ parseint(const char *data, bignum_t *nva
 
        nval->val = 0;
        nval->precision = 0;
-       scale = 0;
+
        while (space(*data))
                data++;
        if (*data == '-') {
@@ -1103,7 +1103,7 @@ ODBCFetch(ODBCStmt *stmt,
        case SQL_INTERVAL_MINUTE:
        case SQL_INTERVAL_MINUTE_TO_SECOND:
        case SQL_INTERVAL_SECOND:
-               switch (parseint(data, &nval)) {
+               switch (parsebignum(data, &nval)) {
                case 0:
                        /* shouldn't happen: getting here means SQL
                         * server told us a value was of a certain
@@ -2098,7 +2098,7 @@ ODBCFetch(ODBCStmt *stmt,
                case SQL_FLOAT:
                case SQL_REAL:
                        /* reparse double and float, parse char */
-                       if (!parseint(data, &nval)) {
+                       if (!parsebignum(data, &nval)) {
                                /* Invalid character value for cast
                                 * specification */
                                addStmtError(stmt, "22018", NULL, 0);
@@ -2301,7 +2301,7 @@ ODBCFetch(ODBCStmt *stmt,
                case SQL_FLOAT:
                case SQL_REAL:
                        /* reparse double and float, parse char */
-                       if (!parseint(data, &nval)) {
+                       if (!parsebignum(data, &nval)) {
                                /* Invalid character value for cast
                                 * specification */
                                addStmtError(stmt, "22018", NULL, 0);
@@ -2370,7 +2370,7 @@ ODBCFetch(ODBCStmt *stmt,
                case SQL_FLOAT:
                case SQL_REAL:
                        /* reparse double and float, parse char */
-                       if (!(i = parseint(data, &nval))) {
+                       if (!(i = parsebignum(data, &nval))) {
                                /* Invalid character value for cast
                                 * specification */
                                addStmtError(stmt, "22018", NULL, 0);
@@ -3779,7 +3779,7 @@ ODBCStore(ODBCStmt *stmt,
                case SQL_C_BINARY:
                        /* parse character data, reparse floating
                         * point number */
-                       if (!parseint(sval, &nval)) {
+                       if (!parsebignum(sval, &nval)) {
                                /* Invalid character value for cast
                                 * specification */
                                addStmtError(stmt, "22018", NULL, 0);
diff --git a/clients/odbc/tests/ODBCtester.c b/clients/odbc/tests/ODBCtester.c
--- a/clients/odbc/tests/ODBCtester.c
+++ b/clients/odbc/tests/ODBCtester.c
@@ -409,6 +409,7 @@ testGetDataIntervalDay(SQLHANDLE stmt, i
        return ret;
 }
 
+#ifdef HAVE_HGE
 static SQLRETURN
 testGetDataDecimal(SQLHANDLE stmt, int sqlquery)
 {
@@ -420,10 +421,12 @@ testGetDataDecimal(SQLHANDLE stmt, int s
        char * outp = malloc(outp_len);
        size_t pos = 0;
 
-       char * sql1 = "select cast(92345678901234567890.123456789 as 
decimal(29,9)) as val1, cast(-92345678901234567890.123456789 as decimal(29,9)) 
as val2;";
-       char * sql2 = "select cast(92345678901234567890.123456789012345678 as 
decimal(38,18)) as val1, cast(-9234567890123456789.1234567890123456789 as 
decimal(38,19)) as val2;";
-       char * sql3 = "select cast(987654321.12345678901234567890123456789 as 
decimal(38,29)) as val1, cast(-987654321.12345678901234567890123456789 as 
decimal(38,29)) as val2;";
-       char * sql = (sqlquery == 1) ? sql1 : (sqlquery == 2) ? sql2 : sql3;
+       char * sql1 = "select cast(99999999909999999990999999999012345678. as 
decimal(38,0)) as val1, cast(-99999999909999999990999999999012345678. as 
decimal(38,0)) as val2;";
+       char * sql2 = "select cast(92345678901234567890.123456789 as 
decimal(29,9)) as val1, cast(-92345678901234567890.123456789 as decimal(29,9)) 
as val2;";
+       char * sql3 = "select cast(92345678901234567890.123456789012345678 as 
decimal(38,18)) as val1, cast(-9234567890123456789.1234567890123456789 as 
decimal(38,19)) as val2;";
+       char * sql4 = "select cast(987654321.12345678901234567890123456789 as 
decimal(38,29)) as val1, cast(-987654321.12345678901234567890123456789 as 
decimal(38,29)) as val2;";
+       char * sql5 = "select cast(.99999999909999999990999999999012345678 as 
decimal(38,38)) as val1, cast(-.99999999909999999990999999999012345678 as 
decimal(38,38)) as val2;";
+       char * sql = (sqlquery == 1) ? sql1 : (sqlquery == 2) ? sql2 : 
(sqlquery == 3) ? sql3 : (sqlquery == 4) ? sql4 : sql5;
 
        ret = SQLExecDirect(stmt, (SQLCHAR *) sql, SQL_NTS);
        pos += snprintf(outp + pos, outp_len - pos, "SQLExecDirect query %d: 
%s\n", sqlquery, sql);
@@ -479,37 +482,60 @@ testGetDataDecimal(SQLHANDLE stmt, int s
 
        compareResult("testGetDataDecimal()", outp,
                (sqlquery == 1)
-               ?       "SQLExecDirect query 1: select 
cast(92345678901234567890.123456789 as decimal(29,9)) as val1, 
cast(-92345678901234567890.123456789 as decimal(29,9)) as val2;\n"
+               ?       "SQLExecDirect query 1: select 
cast(99999999909999999990999999999012345678. as decimal(38,0)) as val1, 
cast(-99999999909999999990999999999012345678. as decimal(38,0)) as val2;\n"
+                       "SQLRowCount is 1\nSQLNumResultCols is 2\nSQLFetch\n"
+                       "SQLColAttribute(1, SQL_DESC_CONCISE_TYPE) returns 0, 
NumAttr 3\n"
+                       "SQLColAttribute(1, SQL_DESC_DISPLAY_SIZE) returns 0, 
NumAttr 40\n"
+                       "SQLGetData(1, SQL_C_CHAR, 42) returns 0, vallen 38, 
str_val: '99999999909999999990999999999012345678'\n"
+                       "SQLGetData(1, SQL_C_NUMERIC, 19) returns 0, vallen 19, 
data_val: 0 0 0 96 117 10 24 156 203 180 104 23 167 76 59 75\n"
+                       "SQLColAttribute(2, SQL_DESC_CONCISE_TYPE) returns 0, 
NumAttr 3\n"
+                       "SQLColAttribute(2, SQL_DESC_DISPLAY_SIZE) returns 0, 
NumAttr 40\n"
+                       "SQLGetData(2, SQL_C_CHAR, 42) returns 0, vallen 39, 
str_val: '-99999999909999999990999999999012345678'\n"
+                       "SQLGetData(2, SQL_C_NUMERIC, 19) returns 0, vallen 19, 
data_val: 0 0 0 96 117 10 24 156 203 180 104 23 167 76 59 75\n"
+               : (sqlquery == 2)
+               ?       "SQLExecDirect query 2: select 
cast(92345678901234567890.123456789 as decimal(29,9)) as val1, 
cast(-92345678901234567890.123456789 as decimal(29,9)) as val2;\n"
                        "SQLRowCount is 1\nSQLNumResultCols is 2\nSQLFetch\n"
                        "SQLColAttribute(1, SQL_DESC_CONCISE_TYPE) returns 0, 
NumAttr 3\n"
                        "SQLColAttribute(1, SQL_DESC_DISPLAY_SIZE) returns 0, 
NumAttr 31\n"
-                       "SQLGetData(1, SQL_C_CHAR, 42) returns 0, vallen 30, 
str_val: '92345678901234567890.123456789'\n" /* SQLGetData(col): Error: 
SQLstate 22003, Numeric value out of range */
+                       "SQLGetData(1, SQL_C_CHAR, 42) returns 0, vallen 30, 
str_val: '92345678901234567890.123456789'\n"
                        "SQLGetData(1, SQL_C_NUMERIC, 19) returns 0, vallen 19, 
data_val: 0 8 201 240 176 193 141 1 5 0 0 0 0 0 0 0\n"
                        "SQLColAttribute(2, SQL_DESC_CONCISE_TYPE) returns 0, 
NumAttr 3\n"
                        "SQLColAttribute(2, SQL_DESC_DISPLAY_SIZE) returns 0, 
NumAttr 31\n"
-                       "SQLGetData(2, SQL_C_CHAR, 42) returns 0, vallen 31, 
str_val: '-92345678901234567890.123456789'\n" /* SQLGetData(col): Error: 
SQLstate 22003, Numeric value out of range */
+                       "SQLGetData(2, SQL_C_CHAR, 42) returns 0, vallen 31, 
str_val: '-92345678901234567890.123456789'\n"
                        "SQLGetData(2, SQL_C_NUMERIC, 19) returns 0, vallen 19, 
data_val: 0 8 201 240 176 193 141 1 5 0 0 0 0 0 0 0\n"
-               : (sqlquery == 2)
-               ?       "SQLExecDirect query 2: select 
cast(92345678901234567890.123456789012345678 as decimal(38,18)) as val1, 
cast(-9234567890123456789.1234567890123456789 as decimal(38,19)) as val2;\n"
+               : (sqlquery == 3)
+               ?       "SQLExecDirect query 3: select 
cast(92345678901234567890.123456789012345678 as decimal(38,18)) as val1, 
cast(-9234567890123456789.1234567890123456789 as decimal(38,19)) as val2;\n"
                        "SQLRowCount is 1\nSQLNumResultCols is 2\nSQLFetch\n"
                        "SQLColAttribute(1, SQL_DESC_CONCISE_TYPE) returns 0, 
NumAttr 3\n"
                        "SQLColAttribute(1, SQL_DESC_DISPLAY_SIZE) returns 0, 
NumAttr 40\n"
-                       "SQLGetData(1, SQL_C_CHAR, 42) returns 0, vallen 39, 
str_val: '92345678901234567890.123456789012345678'\n" /* SQLGetData(col): 
Error: SQLstate 22003, Numeric value out of range */
+                       "SQLGetData(1, SQL_C_CHAR, 42) returns 0, vallen 39, 
str_val: '92345678901234567890.123456789012345678'\n"
                        "SQLGetData(1, SQL_C_NUMERIC, 19) returns 0, vallen 19, 
data_val: 0 8 201 240 176 193 141 1 5 0 0 0 0 0 0 0\n"
                        "SQLColAttribute(2, SQL_DESC_CONCISE_TYPE) returns 0, 
NumAttr 3\n"
                        "SQLColAttribute(2, SQL_DESC_DISPLAY_SIZE) returns 0, 
NumAttr 40\n"
                        "SQLGetData(2, SQL_C_CHAR, 42) returns 0, vallen 40, 
str_val: '-9234567890123456789.1234567890123456789'\n"
                        "SQLGetData(2, SQL_C_NUMERIC, 19) returns 0, vallen 19, 
data_val: 0 180 173 177 145 198 39 128 0 0 0 0 0 0 0 0\n"
-               :       "SQLExecDirect query 3: select 
cast(987654321.12345678901234567890123456789 as decimal(38,29)) as val1, 
cast(-987654321.12345678901234567890123456789 as decimal(38,29)) as val2;\n"
+               : (sqlquery == 4)
+               ?       "SQLExecDirect query 4: select 
cast(987654321.12345678901234567890123456789 as decimal(38,29)) as val1, 
cast(-987654321.12345678901234567890123456789 as decimal(38,29)) as val2;\n"
                        "SQLRowCount is 1\nSQLNumResultCols is 2\nSQLFetch\n"
                        "SQLColAttribute(1, SQL_DESC_CONCISE_TYPE) returns 0, 
NumAttr 3\n"
                        "SQLColAttribute(1, SQL_DESC_DISPLAY_SIZE) returns 0, 
NumAttr 40\n"
-                       "SQLGetData(1, SQL_C_CHAR, 42) returns 0, vallen 39, 
str_val: '987654321.12345678901234567890123456789'\n" /* SQLGetData(col): Info: 
SQLstate 01004, String data, right truncated */
+                       "SQLGetData(1, SQL_C_CHAR, 42) returns 0, vallen 39, 
str_val: '987654321.12345678901234567890123456789'\n"
                        "SQLGetData(1, SQL_C_NUMERIC, 19) returns 0, vallen 19, 
data_val: 177 104 222 58 0 0 0 0 0 0 0 0 0 0 0 0\n"
                        "SQLColAttribute(2, SQL_DESC_CONCISE_TYPE) returns 0, 
NumAttr 3\n"
                        "SQLColAttribute(2, SQL_DESC_DISPLAY_SIZE) returns 0, 
NumAttr 40\n"
-                       "SQLGetData(2, SQL_C_CHAR, 42) returns 0, vallen 40, 
str_val: '-987654321.12345678901234567890123456789'\n" /* SQLGetData(col): 
Info: SQLstate 01004, String data, right truncated */
-                       "SQLGetData(2, SQL_C_NUMERIC, 19) returns 0, vallen 19, 
data_val: 177 104 222 58 0 0 0 0 0 0 0 0 0 0 0 0\n");
+                       "SQLGetData(2, SQL_C_CHAR, 42) returns 0, vallen 40, 
str_val: '-987654321.12345678901234567890123456789'\n"
+                       "SQLGetData(2, SQL_C_NUMERIC, 19) returns 0, vallen 19, 
data_val: 177 104 222 58 0 0 0 0 0 0 0 0 0 0 0 0\n"
+               :       "SQLExecDirect query 5: select 
cast(.99999999909999999990999999999012345678 as decimal(38,38)) as val1, 
cast(-.99999999909999999990999999999012345678 as decimal(38,38)) as val2;\n"
+                       "SQLRowCount is 1\nSQLNumResultCols is 2\nSQLFetch\n"
+                       "SQLColAttribute(1, SQL_DESC_CONCISE_TYPE) returns 0, 
NumAttr 3\n"
+                       "SQLColAttribute(1, SQL_DESC_DISPLAY_SIZE) returns 0, 
NumAttr 40\n"
+                       "SQLGetData(1, SQL_C_CHAR, 42) returns 0, vallen 40, 
str_val: '0.99999999909999999990999999999012345678'\n"
+                       "SQLGetData(1, SQL_C_NUMERIC, 19) returns 0, vallen 19, 
data_val: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n"
+                       "SQLColAttribute(2, SQL_DESC_CONCISE_TYPE) returns 0, 
NumAttr 3\n"
+                       "SQLColAttribute(2, SQL_DESC_DISPLAY_SIZE) returns 0, 
NumAttr 40\n"
+                       "SQLGetData(2, SQL_C_CHAR, 42) returns 0, vallen 41, 
str_val: '-0.99999999909999999990999999999012345678'\n"
+                       "SQLGetData(2, SQL_C_NUMERIC, 19) returns 0, vallen 19, 
data_val: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n"
+               );
 
        ret = SQLCloseCursor(stmt);
        check(ret, SQL_HANDLE_STMT, stmt, "SQLCloseCursor");
@@ -518,6 +544,7 @@ testGetDataDecimal(SQLHANDLE stmt, int s
        free(outp);
        return ret;
 }
+#endif
 
 int
 main(int argc, char **argv)
@@ -566,7 +593,6 @@ main(int argc, char **argv)
        /**** run tests ****/
        ret = testGetDataTruncatedString(stmt, SQL_C_CHAR);
        check(ret, SQL_HANDLE_STMT, stmt, "testGetDataTruncatedString(STMT, 
SQL_C_CHAR)");
-
        ret = testGetDataTruncatedString(stmt, SQL_C_WCHAR);
        check(ret, SQL_HANDLE_STMT, stmt, "testGetDataTruncatedString(STMT, 
SQL_C_WCHAR)");
 
@@ -575,18 +601,21 @@ main(int argc, char **argv)
 
        ret = testGetDataIntervalDay(stmt, 1);
        check(ret, SQL_HANDLE_STMT, stmt, "testGetDataIntervalDay(STMT, 99, 
-99)");
-
        ret = testGetDataIntervalDay(stmt, 2);
        check(ret, SQL_HANDLE_STMT, stmt, "testGetDataIntervalDay(STMT, 101, 
-102)");
 
-       ret = testGetDataDecimal(stmt, 1); /* SQLGetData(col): Error: SQLstate 
22003, Numeric value out of range */
+#ifdef HAVE_HGE
+       ret = testGetDataDecimal(stmt, 1);
+       check(ret, SQL_HANDLE_STMT, stmt, "testGetDataDecimal(STMT, 
dec(38,0))");
+       ret = testGetDataDecimal(stmt, 2);
        check(ret, SQL_HANDLE_STMT, stmt, "testGetDataDecimal(STMT, 
dec(29,9))");
-
-       ret = testGetDataDecimal(stmt, 2); /* SQLGetData(col): Error: SQLstate 
22003, Numeric value out of range */
+       ret = testGetDataDecimal(stmt, 3);
        check(ret, SQL_HANDLE_STMT, stmt, "testGetDataDecimal(STMT, 
dec(38,19))");
-
-       ret = testGetDataDecimal(stmt, 3); /* SQLGetData(col): Info: SQLstate 
01004, String data, right truncated */
+       ret = testGetDataDecimal(stmt, 4);
        check(ret, SQL_HANDLE_STMT, stmt, "testGetDataDecimal(STMT, 
dec(38,29))");
+       ret = testGetDataDecimal(stmt, 5);
+       check(ret, SQL_HANDLE_STMT, stmt, "testGetDataDecimal(STMT, 
dec(38,38))");
+#endif
 
        /* cleanup */
        ret = SQLFreeHandle(SQL_HANDLE_STMT, stmt);
diff --git a/gdk/gdk.h b/gdk/gdk.h
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -2530,7 +2530,9 @@ typedef struct allocator {
        size_t size;
        size_t nr;
        char **blks;
+       char *first_block; /* the special block in blks that also holds our 
bookkeeping */
        size_t used;    /* memory used in last block */
+       size_t reserved;  /* space in first_block is reserved up to here  */
        size_t usedmem; /* used memory */
        void *freelist; /* list of freed blocks */
        exception_buffer eb;
diff --git a/gdk/gdk_atoms.c b/gdk/gdk_atoms.c
--- a/gdk/gdk_atoms.c
+++ b/gdk/gdk_atoms.c
@@ -649,11 +649,12 @@ numFromStr(const char *src, size_t *len,
        int sign = 1;
 
        /* a valid number has the following syntax:
-        * [-+]?[0-9]+([eE][0-9]+)?(LL)? -- PCRE syntax, or in other words
+        * [-+]?[0-9]+(_[0-9]+)*([eE][0-9]+(_[0-9]+)*)?(LL)? -- PCRE syntax, or 
in other words
         * optional sign, one or more digits, optional exponent, optional LL
         * the exponent has the following syntax:
         * lower or upper case letter E, one or more digits
-        * embedded spaces are not allowed
+        * embedded spaces are not allowed but embedded underscores are
+        * (but not more than one consecutively)
         * the optional LL at the end are only allowed for lng and hge
         * values */
        atommem(sz);
@@ -699,6 +700,8 @@ numFromStr(const char *src, size_t *len,
                }
                base = 10 * base + dig;
                p++;
+               if (*p == '_' && GDKisdigit(p[1]))
+                       p++;
        } while (GDKisdigit(*p));
        if ((*p == 'e' || *p == 'E') && GDKisdigit(p[1])) {
                p++;
@@ -717,6 +720,8 @@ numFromStr(const char *src, size_t *len,
                                        goto overflow;
                                }
                                p++;
+                               if (*p == '_' && GDKisdigit(p[1]))
+                                       p++;
                        } while (GDKisdigit(*p));
                        if (base > maxdiv[exp].maxval) {
                                /* overflow */
diff --git a/gdk/gdk_utils.c b/gdk/gdk_utils.c
--- a/gdk/gdk_utils.c
+++ b/gdk/gdk_utils.c
@@ -2092,7 +2092,7 @@ eb_error(exception_buffer *eb, const cha
 #endif
 }
 
-#define SA_BLOCK (64*1024)
+#define SA_BLOCK (128*1024)
 
 typedef struct freed_t {
        struct freed_t *n;
@@ -2146,49 +2146,71 @@ sa_use_freed(allocator *pa, size_t sz)
        return f;
 }
 
+#define round16(sz) ((sz+15)&~15)
+
 allocator *
 sa_create(allocator *pa)
 {
-       allocator *sa = (pa)?(allocator*)sa_alloc(pa, 
sizeof(allocator)):(allocator*)GDKmalloc(sizeof(allocator));
-       if (sa == NULL)
+       const size_t initial_blks_size = 1024;
+       // The above choice only consumes only 8 of the 128 kB of the first
+       // block but allows for up to 128 MB of memory to be allocated before a
+       // blks reallocation is needed. This is useful because blks 
reallocations
+       // consume memory from the parent allocator that currently will not be 
reused
+       // until the parent allocator itself is destroyed.
+
+       char *first_block = pa?(char*)sa_alloc(pa, 
SA_BLOCK):(char*)GDKmalloc(SA_BLOCK);
+       if (first_block == NULL)
                return NULL;
+
+       // The start of the first block holds our bookkeeping.
+       // First our blks array, until that needs to be reallocated.
+       // Then the allocator struct itself.
+       //
+       // It's important that the blks come first so we can easily
+       // check if the blks have been reallocated by comparing pointers.
+       size_t reserved = 0;
+       char **blks = (char**)first_block;
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to