Changeset: 617cf0f77c6b for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/617cf0f77c6b
Modified Files:
        sql/backends/monet5/sql_statistics.c
        sql/test/BugTracker-2017/Tests/cleanup_statistics.Bug-6439.test
        
sql/test/BugTracker-2017/Tests/crash_after_oidx_on_sys_statistics.Bug-6251.test
        sql/test/BugTracker-2017/Tests/statistics_nils_not_eq_zero.Bug-6331.test
        sql/test/BugTracker-2020/Tests/analyze-stream-table.Bug-6817.test
Branch: analyze-fix
Log Message:

If the readonly bat is a view use the parent. Do a better check for nulls. 
Started to fix tests


diffs (truncated from 970 to 300 lines):

diff --git a/sql/backends/monet5/sql_statistics.c 
b/sql/backends/monet5/sql_statistics.c
--- a/sql/backends/monet5/sql_statistics.c
+++ b/sql/backends/monet5/sql_statistics.c
@@ -122,6 +122,12 @@ sql_analyze(Client cntxt, MalBlkPtr mb, 
                                                continue;
                                        if (!(b = 
store->storage_api.bind_col(tr, c, RDONLY)))
                                                continue; /* At the moment we 
ignore the error, but maybe we can change this */
+                                       if (isVIEW(b)) { /* If it is a view get 
the parent BAT */
+                                               BAT *nb = 
BBP_cache(VIEWtparent(b));
+                                               BBPunfix(b->batCacheid);
+                                               if (!(b = 
BATdescriptor(nb->batCacheid)))
+                                                       continue;
+                                       }
 
                                        /* Collect new sorted and revsorted 
properties */
                                        (void) BATordered(b);
@@ -288,7 +294,7 @@ sql_statistics(Client cntxt, MalBlkPtr m
                                                w = bs->twidth;
                                                cnt = BATcount(bs);
                                                un = bs->tkey;
-                                               hnils = !bs->tnonil;
+                                               hnils = !bs->tnonil || bs->tnil;
                                                issorted = bs->tsorted;
                                                isrevsorted = bs->trevsorted;
 
@@ -314,6 +320,14 @@ sql_statistics(Client cntxt, MalBlkPtr m
                                                                msg = 
createException(SQL, "sql.statistics", SQLSTATE(HY005) "Cannot access column 
descriptor");
                                                                goto bailout;
                                                        }
+                                                       if (isVIEW(fb)) { /* If 
it is a view get the parent BAT, but maybe we can remove this here */
+                                                               BAT *nb = 
BBP_cache(VIEWtparent(fb));
+                                                               
BBPunfix(fb->batCacheid);
+                                                               if (!(fb = 
BATdescriptor(nb->batCacheid))) {
+                                                                       msg = 
createException(SQL, "sql.statistics", SQLSTATE(HY005) "Cannot access column 
descriptor");
+                                                                       goto 
bailout;
+                                                               }
+                                                       }
 
                                                        BATiter bi = 
bat_iterator(fb);
                                                        if (fb->tminpos != 
BUN_NONE || fb->tmaxpos != BUN_NONE) {
diff --git a/sql/test/BugTracker-2017/Tests/cleanup_statistics.Bug-6439.test 
b/sql/test/BugTracker-2017/Tests/cleanup_statistics.Bug-6439.test
--- a/sql/test/BugTracker-2017/Tests/cleanup_statistics.Bug-6439.test
+++ b/sql/test/BugTracker-2017/Tests/cleanup_statistics.Bug-6439.test
@@ -1,10 +1,10 @@
 statement ok
 CREATE TABLE sys.abc (a INT, b VARCHAR(10))
 
-statement ok
+statement ok rowcount 1
 INSERT INTO sys.abc VALUES (1, 'one')
 
-statement ok
+statement ok rowcount 1
 INSERT INTO sys.abc VALUES (2, 'two')
 
 query IT rowsort
@@ -16,62 +16,49 @@ 2
 two
 
 statement ok
-DELETE FROM sys.statistics
-
-statement ok
 ANALYZE sys.abc
 
-query TIIIIITTII rowsort
-SELECT   type, width,   "sample", "count", "unique", nils, minval, maxval, 
sorted, revsorted FROM sys.statistics
+query TTITTTTTT nosort
+SELECT "column", "type", "width", "unique", "nils", "minval", "maxval", 
"sorted", "revsorted" FROM sys.statistics ORDER BY "column"
 ----
+a
 int
 4
-2
-2
-2
-0
+True
+False
 1
 2
-1
-0
+True
+False
+b
 varchar
 1
-2
-2
-2
-0
+True
+False
 one
 two
-1
-0
+True
+False
 
-query TIIIIITTII rowsort
--- expected 2 rows
-SELECT   type, width,   "sample", "count", "unique", nils, minval, maxval, 
sorted, revsorted FROM sys.statistics where column_id not in (select id from 
sys.columns)
+query TTITTTTTT nosort
+SELECT "column", "type", "width", "unique", "nils", "minval", "maxval", 
"sorted", "revsorted" FROM sys.statistics WHERE "column" NOT IN (select "name" 
from sys.columns) ORDER BY "column"
 ----
 
 statement ok
--- expected 0 rows
 ALTER TABLE sys.abc DROP COLUMN b
 
-query TIIIIITTII rowsort
-SELECT   type, width,   "sample", "count", "unique", nils, minval, maxval, 
sorted, revsorted FROM sys.statistics where column_id not in (select id from 
sys.columns)
+query TTITTTTTT nosort
+SELECT "column", "type", "width", "unique", "nils", "minval", "maxval", 
"sorted", "revsorted" FROM sys.statistics WHERE "column" NOT IN (select "name" 
from sys.columns) ORDER BY "column"
 ----
 
 statement ok
--- expected 0 rows but found 1 row !
 DROP TABLE sys.abc CASCADE
 
-query TIIIIITTII rowsort
-SELECT   type, width,   "sample", "count", "unique", nils, minval, maxval, 
sorted, revsorted FROM sys.statistics where column_id not in (select id from 
sys.columns)
+query TTITTTTTT nosort
+SELECT "column", "type", "width", "unique", "nils", "minval", "maxval", 
"sorted", "revsorted" FROM sys.statistics WHERE "column" NOT IN (select "name" 
from sys.columns) ORDER BY "column"
 ----
 
-query TIIIIITTII rowsort
--- expected 0 rows but found 2 rows !
-SELECT   type, width,   "sample", "count", "unique", nils, minval, maxval, 
sorted, revsorted FROM sys.statistics
+query TTITTTTTT rowsort
+SELECT "column", "type", "width", "unique", "nils", "minval", "maxval", 
"sorted", "revsorted" FROM sys.statistics
 ----
 
-statement ok
--- expected 0 rows but found 2 rows !
-DELETE FROM sys.statistics
-
diff --git 
a/sql/test/BugTracker-2017/Tests/crash_after_oidx_on_sys_statistics.Bug-6251.test
 
b/sql/test/BugTracker-2017/Tests/crash_after_oidx_on_sys_statistics.Bug-6251.test
--- 
a/sql/test/BugTracker-2017/Tests/crash_after_oidx_on_sys_statistics.Bug-6251.test
+++ 
b/sql/test/BugTracker-2017/Tests/crash_after_oidx_on_sys_statistics.Bug-6251.test
@@ -1,6 +1,3 @@
-statement ok
-DELETE FROM sys.statistics
-
 statement ok
 CREATE TABLE "sys"."myt" (
        "column_id" INTEGER,
@@ -17,7 +14,7 @@ CREATE TABLE "sys"."myt" (
        "revsorted" BOOLEAN
 )
 
-statement ok
+statement ok rowcount 12
 COPY 12 RECORDS INTO "sys"."myt" FROM stdin USING DELIMITERS E'\t',E'\n','"'
 <COPY_INTO_DATA>
 8125   "int"   4       "2021-03-09 08:10:25.983772"    0       0       0       
0       NULL    NULL    true    true
@@ -34,295 +31,459 @@ 8135      "boolean"       1       "2021-03-09 08:10:25.98
 8136   "boolean"       1       "2021-03-09 08:10:25.985546"    11      11      
2       0       "false" "true"  false   false
 
 statement ok
--- fill "sys"."myt"
-ANALYZE "sys"."myt"
+ANALYZE sys.myt
 
-query TIIIIITT rowsort
-SELECT "type", width, "sample", "count", "unique", nils, sorted, revsorted 
FROM sys.statistics WHERE "type" <> 'timestamp' ORDER BY column_id
+query TTITTTTTT nosort
+SELECT "column", "type", "width", "unique", "nils", "minval", "maxval", 
"sorted", "revsorted" FROM sys.statistics('sys', 'myt') ORDER BY "column"
 ----
-bigint
-8
-12
-12
-12
-0
+column_id
+int
+4
 True
 False
-bigint
-8
-12
-12
-12
-0
+NULL
+NULL
 True
 False
-bigint
-8
-12
-12
-2
-0
-False
-False
+count
 bigint
 8
-12
-12
-8
-0
+True
+False
+NULL
+NULL
+True
+False
+maxval
+clob
+1
+False
+True
+NULL
+NULL
 False
 False
-boolean
+minval
+clob
 1
-12
-12
-2
-0
+False
+True
+NULL
+NULL
 False
 False
+nils
+bigint
+8
+False
+False
+NULL
+NULL
+False
+False
+revsorted
 boolean
 1
-12
-12
-2
-0
+False
+False
+NULL
+NULL
 False
 False
-clob
-1
-12
-12
-5
-0
+sample
+bigint
+8
+True
 False
+NULL
+NULL
+True
 False
-clob
-1
-12
-12
-6
+sorted
+boolean
 1
 False
 False
+NULL
+NULL
+False
+False
+stamp
+timestamp
+8
+True
+False
+NULL
+NULL
+True
+False
+type
 clob
 1
-12
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to