Changeset: 314576431257 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/314576431257
Added Files:
        sql/test/BugTracker-2021/Tests/ntile-wrong-result.Bug-7104.sql
        sql/test/BugTracker-2021/Tests/ntile-wrong-result.Bug-7104.stable.err
        sql/test/BugTracker-2021/Tests/ntile-wrong-result.Bug-7104.stable.out
Modified Files:
        gdk/gdk_analytic_func.c
        sql/test/BugTracker-2021/Tests/All
Branch: Oct2020
Log Message:

For the row iterator in the ntile, don't use the same type as the ntile itself, 
otherwise it can overflow in large partitions. This fixes bug #7104


diffs (truncated from 585 to 300 lines):

diff --git a/gdk/gdk_analytic_func.c b/gdk/gdk_analytic_func.c
--- a/gdk/gdk_analytic_func.c
+++ b/gdk/gdk_analytic_func.c
@@ -132,7 +132,7 @@ GDKanalyticaldiff(BAT *r, BAT *b, BAT *p
 
 #define NTILE_CALC(TPE, NEXT_VALUE, LNG_HGE, UPCAST)   \
        do {                                    \
-               for (TPE i = 0; rb < rp; i++, rb++) {   \
+               for (UPCAST i = 0; rb < rp; i++, rb++) {        \
                        TPE val = NEXT_VALUE; \
                        if (is_##TPE##_nil(val)) {      \
                                has_nils = true;        \
@@ -140,7 +140,7 @@ GDKanalyticaldiff(BAT *r, BAT *b, BAT *p
                        } else { \
                                UPCAST nval = (UPCAST) LNG_HGE; \
                                if (nval >= ncnt) { \
-                                       *rb = i + 1;  \
+                                       *rb = (TPE)(i + 1);  \
                                } else { \
                                        UPCAST bsize = ncnt / nval; \
                                        UPCAST top = ncnt - nval * bsize; \
diff --git a/sql/test/BugTracker-2021/Tests/All 
b/sql/test/BugTracker-2021/Tests/All
--- a/sql/test/BugTracker-2021/Tests/All
+++ b/sql/test/BugTracker-2021/Tests/All
@@ -1,3 +1,4 @@
 update-from-count.Bug-7079
 HAVE_PYMONETDB?remote-table-ranges.Bug-7089
 KNOWNFAIL?query-too-complex.Bug-7092
+ntile-wrong-result.Bug-7104
diff --git a/sql/test/BugTracker-2021/Tests/ntile-wrong-result.Bug-7104.sql 
b/sql/test/BugTracker-2021/Tests/ntile-wrong-result.Bug-7104.sql
new file mode 100644
--- /dev/null
+++ b/sql/test/BugTracker-2021/Tests/ntile-wrong-result.Bug-7104.sql
@@ -0,0 +1,169 @@
+START TRANSACTION;
+
+CREATE TABLE stringpower(kw INTEGER);
+
+COPY 160 RECORDS INTO stringpower FROM STDIN USING DELIMITERS E' ',E'\n','"';
+25
+12
+23
+34
+23
+24
+34
+23
+21
+45
+23
+232
+4
+32
+324
+321
+23
+234
+46
+34
+34
+32
+53
+423
+34
+53
+23
+12
+35
+45
+78
+68
+85
+56
+78
+58
+8
+5
+934
+48
+65
+445
+656
+63
+34
+65
+32
+32
+44
+55
+34
+67
+8
+64
+544
+3
+8
+987
+344
+5
+73
+78
+789
+9
+8
+7
+779
+977
+25
+78
+35
+5
+8
+9
+67
+9
+7
+78
+54
+435
+30
+14
+27
+40
+27
+28
+40
+27
+25
+54
+27
+278
+4
+38
+388
+385
+27
+280
+55
+40
+40
+38
+63
+507
+40
+63
+27
+14
+42
+54
+93
+81
+102
+67
+93
+69
+9
+6
+1120
+57
+78
+534
+787
+75
+40
+78
+38
+38
+52
+66
+40
+80
+9
+76
+652
+3
+9
+1184
+412
+6
+87
+93
+946
+10
+9
+8
+934
+1172
+30
+93
+42
+6
+9
+10
+80
+10
+8
+93
+64
+522
+
+SELECT NTILE(2) OVER(ORDER BY kw) as tile, NTILE(CAST(2 AS BIGINT)) OVER(ORDER 
BY kw) as tile2 from stringpower;
+
+ROLLBACK;
diff --git 
a/sql/test/BugTracker-2021/Tests/ntile-wrong-result.Bug-7104.stable.err 
b/sql/test/BugTracker-2021/Tests/ntile-wrong-result.Bug-7104.stable.err
new file mode 100644
--- /dev/null
+++ b/sql/test/BugTracker-2021/Tests/ntile-wrong-result.Bug-7104.stable.err
@@ -0,0 +1,29 @@
+stderr of test 'ntile-wrong-result.Bug-7104` in directory 
'sql/test/BugTracker-2021` itself:
+
+
+# 23:15:06 >  
+# 23:15:06 >  "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set" 
"mapi_listenaddr=all" "--set" "mapi_port=35497" "--set" 
"mapi_usock=/var/tmp/mtest-14496/.s.monetdb.35497" "--forcemito" 
"--dbpath=/home/ferreira/repositories/MonetDB-Oct2020/BUILD/var/MonetDB/mTests_sql_test_BugTracker-2021"
 "--set" "embedded_r=yes" "--set" "embedded_c=true"
+# 23:15:06 >  
+
+# builtin opt  gdk_dbpath = 
/home/ferreira/repositories/MonetDB-Oct2020/BUILD/var/monetdb5/dbfarm/demo
+# builtin opt  mapi_port = 50000
+# builtin opt  sql_optimizer = default_pipe
+# builtin opt  sql_debug = 0
+# builtin opt  raw_strings = false
+# cmdline opt  gdk_nr_threads = 0
+# cmdline opt  mapi_listenaddr = all
+# cmdline opt  mapi_port = 35497
+# cmdline opt  mapi_usock = /var/tmp/mtest-14496/.s.monetdb.35497
+# cmdline opt  gdk_dbpath = 
/home/ferreira/repositories/MonetDB-Oct2020/BUILD/var/MonetDB/mTests_sql_test_BugTracker-2021
+# cmdline opt  embedded_r = yes
+# cmdline opt  embedded_c = true
+
+# 23:15:07 >  
+# 23:15:07 >  "mclient" "-lsql" "-ftest" "-tnone" "-Eutf-8" "-i" "-e" 
"--host=/var/tmp/mtest-14496" "--port=35497"
+# 23:15:07 >  
+
+
+# 23:15:07 >  
+# 23:15:07 >  "Done."
+# 23:15:07 >  
+
diff --git 
a/sql/test/BugTracker-2021/Tests/ntile-wrong-result.Bug-7104.stable.out 
b/sql/test/BugTracker-2021/Tests/ntile-wrong-result.Bug-7104.stable.out
new file mode 100644
--- /dev/null
+++ b/sql/test/BugTracker-2021/Tests/ntile-wrong-result.Bug-7104.stable.out
@@ -0,0 +1,343 @@
+stdout of test 'ntile-wrong-result.Bug-7104` in directory 
'sql/test/BugTracker-2021` itself:
+
+
+# 23:15:06 >  
+# 23:15:06 >  "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set" 
"mapi_listenaddr=all" "--set" "mapi_port=35497" "--set" 
"mapi_usock=/var/tmp/mtest-14496/.s.monetdb.35497" "--forcemito" 
"--dbpath=/home/ferreira/repositories/MonetDB-Oct2020/BUILD/var/MonetDB/mTests_sql_test_BugTracker-2021"
 "--set" "embedded_r=yes" "--set" "embedded_c=true"
+# 23:15:06 >  
+
+# MonetDB 5 server v11.39.16 (hg id: eca29d0d38a6)
+# This is an unreleased version
+# Serving database 'mTests_sql_test_BugTracker-2021', using 8 threads
+# Compiled for x86_64-pc-linux-gnu/64bit with 128bit integers
+# Found 15.493 GiB available main-memory of which we use 12.627 GiB
+# Copyright (c) 1993 - July 2008 CWI.
+# Copyright (c) August 2008 - 2021 MonetDB B.V., all rights reserved
+# Visit https://www.monetdb.org/ for further information
+# Listening for connection requests on 
mapi:monetdb://localhost.localdomain:35497/
+# Listening for UNIX domain connection requests on 
mapi:monetdb:///var/tmp/mtest-14496/.s.monetdb.35497
+# MonetDB/GIS module loaded
+# MonetDB/R   module loaded
+# MonetDB/SQL module loaded
+
+# 23:15:07 >  
+# 23:15:07 >  "mclient" "-lsql" "-ftest" "-tnone" "-Eutf-8" "-i" "-e" 
"--host=/var/tmp/mtest-14496" "--port=35497"
+# 23:15:07 >  
+
+#START TRANSACTION;
+#CREATE TABLE stringpower(kw INTEGER);
+#COPY 160 RECORDS INTO stringpower FROM STDIN USING DELIMITERS E' ',E'\n','"';
+#25
+#12
+#23
+#34
+#23
+#24
+#34
+#23
+#21
+#45
+#23
+#232
+#4
+#32
+#324
+#321
+#23
+#234
+#46
+#34
+#34
+#32
+#53
+#423
+#34
+#53
+#23
+#12
+#35
+#45
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to