Changeset: 017412cd6d41 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/017412cd6d41
Modified Files:
gdk/gdk_aggr.c
gdk/gdk_join.c
monetdb5/mal/mal_profiler.c
sql/backends/monet5/rel_bin.c
sql/server/rel_dump.c
sql/server/rel_exp.c
sql/server/rel_exp.h
sql/server/rel_optimize_proj.c
sql/server/rel_statistics.c
sql/server/rel_unnest.c
sql/test/BugTracker-2025/Tests/All
sql/test/BugTracker-2026/Tests/All
Branch: default
Log Message:
Merge with Dec2025 branch.
diffs (truncated from 641 to 300 lines):
diff --git a/gdk/gdk_aggr.c b/gdk/gdk_aggr.c
--- a/gdk/gdk_aggr.c
+++ b/gdk/gdk_aggr.c
@@ -2935,7 +2935,7 @@ BATgroupavg3combine(BAT *avg, BAT *rem,
\
/* first try to calculate the sum of all values into a */ \
/* lng/hge */ \
- TIMEOUT_LOOP(ci.ncand, qry_ctx) { \
+ TIMEOUT_LOOP_IDX(idx, ci.ncand, qry_ctx) { \
i = canditer_next(&ci) - b->hseqbase; \
x = ((const TYPE *) src)[i]; \
if (is_##TYPE##_nil(x)) \
@@ -2960,6 +2960,8 @@ BATgroupavg3combine(BAT *avg, BAT *rem,
/* note that n necessarily is > 0 (else no */ \
/* overflow possible) */ \
assert(n > 0); \
+ /* we have to redo the last candidate */ \
+ (void) canditer_prev(&ci); \
if (sum >= 0) { \
a = (TYPE) (sum / n); /* this fits */ \
r = (lng) (sum % n); \
@@ -2972,7 +2974,8 @@ BATgroupavg3combine(BAT *avg, BAT *rem,
r = n - r; \
} \
} \
- TIMEOUT_LOOP(ci.ncand, qry_ctx) { \
+ /* idx is how many we've already done successfully */ \
+ TIMEOUT_LOOP(ci.ncand - idx, qry_ctx) { \
/* loop invariant: */ \
/* a + r/n == average(x[0],...,x[n]); */ \
/* 0 <= r < n */ \
@@ -3015,6 +3018,7 @@ BATcalcavg(BAT *b, BAT *s, dbl *avg, BUN
{
lng n = 0, r = 0;
BUN i = 0;
+ BUN idx;
#ifdef HAVE_HGE
hge sum = 0;
#else
diff --git a/gdk/gdk_calc_private.h b/gdk/gdk_calc_private.h
--- a/gdk/gdk_calc_private.h
+++ b/gdk/gdk_calc_private.h
@@ -33,10 +33,12 @@
#ifdef __has_builtin
#if __has_builtin(__builtin_add_overflow)
-#define OP_WITH_CHECK(lft, rgt, dst, op, max, on_overflow) \
+#define OP_WITH_CHECK(lft, rgt, TYPE3, dst, op, max, on_overflow) \
do { \
+ TYPE3 old = dst; \
if (__builtin_##op##_overflow(lft, rgt, &(dst)) || \
(dst) < -(max) /*|| (dst) > (max)*/) { \
+ dst = old; \
on_overflow; \
} \
} while (0)
@@ -66,7 +68,7 @@
#ifdef OP_WITH_CHECK
/* integer version using Gnu CC builtin function for overflow check */
#define ADDI_WITH_CHECK(lft, rgt, TYPE3, dst, max, on_overflow)
\
- OP_WITH_CHECK(lft, rgt, dst, add, max, on_overflow)
+ OP_WITH_CHECK(lft, rgt, TYPE3, dst, add, max, on_overflow)
#else
/* integer version using generic version */
#define ADDI_WITH_CHECK(lft, rgt, TYPE3, dst, max, on_overflow) \
@@ -100,7 +102,7 @@
#ifdef OP_WITH_CHECK
/* integer version using Gnu CC builtin function for overflow check */
#define SUBI_WITH_CHECK(lft, rgt, TYPE3, dst, max, on_overflow)
\
- OP_WITH_CHECK(lft, rgt, dst, sub, max, on_overflow)
+ OP_WITH_CHECK(lft, rgt, TYPE3, dst, sub, max, on_overflow)
#else
/* integer version using generic version */
#define SUBI_WITH_CHECK(lft, rgt, TYPE3, dst, max, on_overflow) \
@@ -127,7 +129,7 @@
#ifdef OP_WITH_CHECK
/* integer version using Gnu CC builtin function for overflow check */
#define MULI4_WITH_CHECK(lft, rgt, TYPE3, dst, max, TYPE4, on_overflow) \
- OP_WITH_CHECK(lft, rgt, dst, mul, max, on_overflow)
+ OP_WITH_CHECK(lft, rgt, TYPE3, dst, mul, max, on_overflow)
#else
/* integer version using generic version */
#define MULI4_WITH_CHECK(lft, rgt, TYPE3, dst, max, TYPE4, on_overflow) \
@@ -190,7 +192,7 @@
#ifdef HAVE_HGE
#ifdef OP_WITH_CHECK
#define HGEMUL_CHECK(lft, rgt, dst, max, on_overflow) \
- OP_WITH_CHECK(lft, rgt, dst, mul, max, on_overflow)
+ OP_WITH_CHECK(lft, rgt, hge, dst, mul, max, on_overflow)
#else
#define HGEMUL_CHECK(lft, rgt, dst, max, on_overflow) \
do { \
diff --git a/gdk/gdk_join.c b/gdk/gdk_join.c
--- a/gdk/gdk_join.c
+++ b/gdk/gdk_join.c
@@ -4927,7 +4927,7 @@ BATbandjoin(BAT **r1p, BAT **r2p, BAT *l
case TYPE_lng: {
if (is_lng_nil(*(const lng *) vr))
continue;
- lng v1, v2;
+ lng v1 = 0, v2 = 0;
SUBI_WITH_CHECK(*(const lng *)vr,
*(const lng *)c1,
lng, v1,
@@ -4957,7 +4957,7 @@ BATbandjoin(BAT **r1p, BAT **r2p, BAT *l
case TYPE_hge: {
if (is_hge_nil(*(const hge *) vr))
continue;
- hge v1, v2;
+ hge v1 = 0, v2 = 0;
SUBI_WITH_CHECK(*(const hge *)vr,
*(const hge *)c1,
hge, v1,
@@ -4999,7 +4999,7 @@ BATbandjoin(BAT **r1p, BAT **r2p, BAT *l
case TYPE_dbl: {
if (is_dbl_nil(*(const dbl *) vr))
continue;
- dbl v1, v2;
+ dbl v1 = 0, v2 = 0;
SUBF_WITH_CHECK(*(const dbl *)vr,
*(const dbl *)c1,
dbl, v1,
diff --git a/monetdb5/mal/mal_interpreter.c b/monetdb5/mal/mal_interpreter.c
--- a/monetdb5/mal/mal_interpreter.c
+++ b/monetdb5/mal/mal_interpreter.c
@@ -498,12 +498,10 @@ runMALsequence(Client cntxt, MalBlkPtr m
ValPtr backup;
int garbages[16], *garbage;
int stkpc = 0;
- RuntimeProfileRecord runtimeProfile, runtimeProfileFunction;
+ RuntimeProfileRecord runtimeProfile = {0}, runtimeProfileFunction = {0};
lng lastcheck = 0;
bool startedProfileQueue = false;
#define CHECKINTERVAL 1000 /* how often do we check for client
disconnect */
- runtimeProfile.ticks = runtimeProfileFunction.ticks = 0;
-
if (stk == NULL)
throw(MAL, "mal.interpreter", MAL_STACK_FAIL);
@@ -824,8 +822,6 @@ runMALsequence(Client cntxt, MalBlkPtr m
break;
case ENDsymbol:
runtimeProfileExit(cntxt, mb, stk, pci,
&runtimeProfile);
- runtimeProfileExit(cntxt, mb, stk, getInstrPtr(mb, 0),
-
&runtimeProfileFunction);
if (pcicaller && garbageControl(getInstrPtr(mb, 0)))
garbageCollector(cntxt, mb, stk, TRUE);
if (cntxt->qryctx.endtime == QRY_TIMEOUT) {
@@ -1193,9 +1189,6 @@ runMALsequence(Client cntxt, MalBlkPtr m
}
}
if (stkpc == mb->stop) {
- runtimeProfileExit(cntxt, mb, stk, pci,
&runtimeProfile);
- runtimeProfileExit(cntxt, mb, stk,
getInstrPtr(mb, 0),
-
&runtimeProfileFunction);
break;
}
break;
@@ -1217,9 +1210,6 @@ runMALsequence(Client cntxt, MalBlkPtr m
if (garbageControl(getInstrPtr(mb, 0)))
garbageCollector(cntxt, mb, stk, TRUE);
/* reset the clock */
- runtimeProfileExit(cntxt, mb, stk, pp,
&runtimeProfile);
- runtimeProfileExit(cntxt, mb, stk,
getInstrPtr(mb, 0),
-
&runtimeProfileFunction);
}
stkpc = mb->stop;
continue;
@@ -1237,6 +1227,10 @@ runMALsequence(Client cntxt, MalBlkPtr m
}
}
+ if (startpc == 1 && startpc < mb->stop)
+ runtimeProfileExit(cntxt, mb, stk, getInstrPtr(mb, 0),
+ &runtimeProfileFunction);
+
/* if we could not find the exception variable, cascade a new one */
/* don't add 'exception not caught' extra message for MAL sequences
besides main function calls */
if (exceptionVar >= 0 && (ret == MAL_SUCCEED || !pcicaller)) {
diff --git a/monetdb5/mal/mal_profiler.c b/monetdb5/mal/mal_profiler.c
--- a/monetdb5/mal/mal_profiler.c
+++ b/monetdb5/mal/mal_profiler.c
@@ -72,30 +72,13 @@ static struct timeval startup_time;
*/
struct logbuf {
char *logbuffer;
- char *logbase;
size_t loglen;
size_t logcap;
+ allocator *ma;
};
-static inline void
-lognew(struct logbuf *logbuf)
-{
- logbuf->loglen = 0;
- logbuf->logbase = logbuf->logbuffer;
- *logbuf->logbase = 0;
-}
-
-static inline void
-logdel(struct logbuf *logbuf)
-{
- GDKfree(logbuf->logbuffer);
- logbuf->logbuffer = NULL;
-}
-
-static bool logadd(struct logbuf *logbuf,
- _In_z_ _Printf_format_string_ const char
*fmt, ...)
- __attribute__((__format__(__printf__, 2, 3)))
- __attribute__((__warn_unused_result__));
+__attribute__((__format__(__printf__, 2, 3)))
+__attribute__((__warn_unused_result__))
static bool
logadd(struct logbuf *logbuf, const char *fmt, ...)
{
@@ -107,27 +90,34 @@ logadd(struct logbuf *logbuf, const char
tmp_len = vsnprintf(tmp_buff, sizeof(tmp_buff), fmt, va);
va_end(va);
if (tmp_len < 0) {
- logdel(logbuf);
return false;
}
if (logbuf->loglen + (size_t) tmp_len >= logbuf->logcap) {
char *alloc_buff;
+ size_t oldcap = logbuf->logcap;
logbuf->logcap += (size_t) tmp_len + (size_t) tmp_len / 2;
if (logbuf->logcap < LOGLEN)
logbuf->logcap = LOGLEN;
- alloc_buff = GDKrealloc(logbuf->logbuffer, logbuf->logcap);
- if (alloc_buff == NULL) {
- TRC_ERROR(MAL_SERVER,
- "Profiler JSON buffer reallocation
failure\n");
- logdel(logbuf);
- return false;
+ if (logbuf->logbuffer == NULL)
+ logbuf->logbuffer = ma_alloc(logbuf->ma,
logbuf->logcap);
+ else {
+ alloc_buff = ma_realloc(logbuf->ma, logbuf->logbuffer,
+
logbuf->logcap, oldcap);
+ if (alloc_buff == NULL) {
+ TRC_ERROR(MAL_SERVER,
+ "Profiler JSON buffer
reallocation failure\n");
+ return false;
+ }
+ logbuf->logbuffer = alloc_buff;
}
- logbuf->logbuffer = alloc_buff;
- lognew(logbuf);
}
- if (tmp_len > 0) {
+ if ((size_t) tmp_len < sizeof(tmp_buff)) {
+ logbuf->loglen += strtcpy(logbuf->logbuffer + logbuf->loglen,
+ tmp_buff,
+
logbuf->logcap - logbuf->loglen);
+ } else {
va_start(va, fmt);
- logbuf->loglen += vsnprintf(logbuf->logbase + logbuf->loglen,
+ logbuf->loglen += vsnprintf(logbuf->logbuffer + logbuf->loglen,
logbuf->logcap - logbuf->loglen, fmt, va);
va_end(va);
}
@@ -149,15 +139,13 @@ static str phase_descriptions[] = {
};
static str
-prepareMalEvent(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci,
- lng clk, lng ticks)
+prepareMalEvent(allocator *ma, Client cntxt, MalBlkPtr mb, MalStkPtr stk,
+ InstrPtr pci, lng clk, lng ticks)
{
- struct logbuf logbuf;
+ struct logbuf logbuf = {.ma = ma};
uint64_t mclk;
const char *algo = MT_thread_getalgorithm();
- logbuf = (struct logbuf) { 0 };
-
mclk = (uint64_t) clk - ((uint64_t) startup_time.tv_sec * 1000000 -
(uint64_t)
startup_time.tv_usec);
/* make profile event tuple */
@@ -196,7 +184,6 @@ prepareMalEvent(Client cntxt, MalBlkPtr
goto cleanup_and_exit;
return logbuf.logbuffer;
cleanup_and_exit:
- logdel(&logbuf);
return NULL;
}
@@ -384,7 +371,6 @@ sqlProfilerEvent(Client cntxt, MalBlkPtr
lng clk, lng ticks)
{
str stmt, c, ev;
- int errors = 0;
if (cntxt->profticks == NULL)
return;
@@ -398,24 +384,26 @@ sqlProfilerEvent(Client cntxt, MalBlkPtr
c++;
*/
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]