Changeset: 25c5e55af0c1 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/25c5e55af0c1
Modified Files:
monetdb5/modules/kernel/algebra.c
sql/backends/monet5/rel_bin.c
sql/backends/monet5/sql_statement.c
sql/test/BugTracker-2026/Tests/All
Branch: pp_hashjoin
Log Message:
merged with default
diffs (133 lines):
diff --git a/monetdb5/modules/kernel/algebra.c
b/monetdb5/modules/kernel/algebra.c
--- a/monetdb5/modules/kernel/algebra.c
+++ b/monetdb5/modules/kernel/algebra.c
@@ -1006,6 +1006,10 @@ ALGintersect(Client ctx, bat *r1, const
* nilslast:bit,
* distinct:bit)
* returns :bat[:oid] [ , :bat[:oid] ]
+ *
+ * if asc is nil, there is no sorting and a second return value is not
+ * allowed; the result is a dense sequence starting at offset (default
+ * 0) + hseqbase of length n.
*/
static str
ALGfirstn(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
@@ -1046,7 +1050,9 @@ ALGfirstn(Client cntxt, MalBlkPtr mb, Ma
SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);
}
n = *getArgReference_lng(stk, pci, pci->retc + 3);
- if (n < 0) {
+ if (is_lng_nil(n)) {
+ n = BUN_MAX;
+ } else if (n < 0) {
BBPreclaim(b);
BBPreclaim(s);
BBPreclaim(g);
@@ -1077,7 +1083,21 @@ ALGfirstn(Client cntxt, MalBlkPtr mb, Ma
nilslast = *getArgReference_bit(stk, pci, pci->argc - 2);
distinct = *getArgReference_bit(stk, pci, pci->argc - 1);
- if (o > 0) {
+ if (is_bit_nil(asc)) {
+ if (ret2) {
+ BBPreclaim(b);
+ BBPreclaim(s);
+ BBPreclaim(g);
+ throw(MAL, "algebra.firstn", ILLEGAL_ARGUMENT);
+ }
+ if (o > (lng) BATcount(b))
+ o = (lng) BATcount(b);
+ if ((BUN) o + (BUN) n > BATcount(b))
+ n = (lng) BATcount(b) - o;
+ bn = BATdense(0, b->hseqbase + o, n);
+ if (bn == NULL)
+ rc = GDK_FAIL;
+ } else if (o > 0) {
bn = BATfirstn_offset(b, s, g, (BUN) n, (BUN) o, asc, nilslast,
distinct);
if (bn == NULL)
diff --git a/sql/backends/monet5/rel_bin.c b/sql/backends/monet5/rel_bin.c
--- a/sql/backends/monet5/rel_bin.c
+++ b/sql/backends/monet5/rel_bin.c
@@ -4965,6 +4965,8 @@ sub_topn(backend *be, stmt *sub, stmt **
*Psub = stmt_list(be, npl);
}
+ if (!sub)
+ return sub;
/* also rebuild sub as multiple orderby expressions may use the sub
table (ie aren't part of the result columns) */
pl = sub->op4.lval;
npl = sa_list(be->mvc->sa);
diff --git a/sql/backends/monet5/sql_statement.c
b/sql/backends/monet5/sql_statement.c
--- a/sql/backends/monet5/sql_statement.c
+++ b/sql/backends/monet5/sql_statement.c
@@ -1407,33 +1407,20 @@ stmt_limit(backend *be, stmt *col, stmt
}
}
} else {
- int len;
-
- q = newStmt(mb, calcRef, plusRef);
- if (q == NULL)
- goto bailout;
- q = pushArgument(mb, q, offset->nr);
- q = pushArgument(mb, q, limit->nr);
- len = getDestVar(q);
- pushInstruction(mb, q);
-
- /* since both arguments of algebra.subslice are
- inclusive correct the LIMIT value by
- subtracting 1 */
- q = newStmt(mb, calcRef, minusRef);
- if (q == NULL)
- goto bailout;
- q = pushArgument(mb, q, len);
- q = pushInt(mb, q, 1);
- len = getDestVar(q);
- pushInstruction(mb, q);
-
- q = newStmt(mb, algebraRef, subsliceRef);
+ q = newStmtArgs(mb, algebraRef, firstnRef, 9);
if (q == NULL)
goto bailout;
q = pushArgument(mb, q, c);
+ q = pushNilBat(mb, q);
+ q = pushNilBat(mb, q);
+ q = pushArgument(mb, q, limit->nr);
q = pushArgument(mb, q, offset->nr);
- q = pushArgument(mb, q, len);
+ q = pushBit(mb, q, false); /* return skipped */
+ q = pushBit(mb, q, bit_nil); /* no direction */
+ q = pushBit(mb, q, bit_nil); /* nulls not handled specialy */
+ q = pushBit(mb, q, false); /* no info on distinct */
+
+ l = getArg(q, 0);
l = getDestVar(q);
pushInstruction(mb, q);
}
diff --git a/sql/test/BugTracker-2026/Tests/All
b/sql/test/BugTracker-2026/Tests/All
--- a/sql/test/BugTracker-2026/Tests/All
+++ b/sql/test/BugTracker-2026/Tests/All
@@ -149,7 +149,7 @@ KNOWNFAIL?7957-tail_type-crash
KNOWNFAIL?7961-list_empty-crash
KNOWNFAIL?7963-having-sum-or-exists-or-sum-bug
7964-optimize-limit-0-queries
-KNOWNFAIL?7965-select-1-limit-0-bug
+7965-select-1-limit-0-bug
PIPELINE?7966-optimize-select-distinct-from-union-queries
7967-optimize-in-select-distinct-queries
7968-optimize-distinct-from-q1-except-q2
diff --git a/sql/test/Tests/limit_offset_fetchfirst.test
b/sql/test/Tests/limit_offset_fetchfirst.test
--- a/sql/test/Tests/limit_offset_fetchfirst.test
+++ b/sql/test/Tests/limit_offset_fetchfirst.test
@@ -18,8 +18,9 @@ select * from limittest ORDER BY value L
statement error
select * from limittest LIMIT +5
-statement error
+query I
select * from limittest LIMIT 0
+----
statement error
select * from limittest LIMIT -5
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]