Changeset: f7114b6e9212 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=f7114b6e9212
Added Files:
        sql/test/BugTracker-2017/Tests/cleanup_statistics.Bug-6439.sql
        sql/test/BugTracker-2017/Tests/cleanup_statistics.Bug-6439.stable.err
        sql/test/BugTracker-2017/Tests/cleanup_statistics.Bug-6439.stable.out
Modified Files:
        sql/storage/store.c
        sql/test/BugTracker-2017/Tests/All
Branch: Jul2017
Log Message:

cleanup statistics after dropping columns or tables


diffs (191 lines):

diff --git a/sql/storage/store.c b/sql/storage/store.c
--- a/sql/storage/store.c
+++ b/sql/storage/store.c
@@ -3819,6 +3819,22 @@ sys_drop_sequence(sql_trans *tr, sql_seq
 }
 
 static void
+sys_drop_statistics(sql_trans *tr, sql_column *col)
+{
+       if (isGlobal(col->t)) {
+               sql_schema *syss = find_sql_schema(tr, "sys"); 
+               sql_table *sysstats = find_sql_table(syss, "statistics");
+
+               oid rid = table_funcs.column_find_row(tr, 
find_sql_column(sysstats, "column_id"), &col->base.id, NULL);
+
+               if (rid == oid_nil)
+                       return ;
+
+               table_funcs.table_delete(tr, sysstats, rid);
+       }
+}
+
+static void
 sys_drop_column(sql_trans *tr, sql_column *col, int drop_action)
 {
        str seq_pos = NULL;
@@ -3851,6 +3867,7 @@ sys_drop_column(sql_trans *tr, sql_colum
        if (isGlobal(col->t)) 
                tr->schema_updates ++;
 
+       sys_drop_statistics(tr, col);
        if (drop_action) 
                sql_trans_drop_all_dependencies(tr, col->t->s, col->base.id, 
COLUMN_DEPENDENCY);
        if (col->type.type->s) 
diff --git a/sql/test/BugTracker-2017/Tests/All 
b/sql/test/BugTracker-2017/Tests/All
--- a/sql/test/BugTracker-2017/Tests/All
+++ b/sql/test/BugTracker-2017/Tests/All
@@ -94,3 +94,4 @@ HAVE_SAMTOOLS?sqlsmith.Bug-6449
 HAVE_LIBPY?python_loader_clobbers_default_with_null.Bug-6464
 skip_problem_best_effort.Bug-6442
 date_to_str.Bug-6467
+cleanup_statistics.Bug-6439
diff --git a/sql/test/BugTracker-2017/Tests/cleanup_statistics.Bug-6439.sql 
b/sql/test/BugTracker-2017/Tests/cleanup_statistics.Bug-6439.sql
new file mode 100644
--- /dev/null
+++ b/sql/test/BugTracker-2017/Tests/cleanup_statistics.Bug-6439.sql
@@ -0,0 +1,24 @@
+CREATE TABLE sys.abc (a INT, b VARCHAR(10));
+INSERT INTO sys.abc VALUES (1, 'one');
+INSERT INTO sys.abc VALUES (2, 'two');
+SELECT * FROM sys.abc;
+
+DELETE FROM sys.statistics;
+
+ANALYZE sys.abc;
+SELECT /* column_id, */ type, width, /* stamp, */ "sample", "count", "unique", 
nils, minval, maxval, sorted, revsorted FROM sys.statistics;
+-- expected 2 rows
+SELECT /* column_id, */ type, width, /* stamp, */ "sample", "count", "unique", 
nils, minval, maxval, sorted, revsorted FROM sys.statistics where column_id not 
in (select id from sys.columns);
+-- expected 0 rows
+
+ALTER TABLE sys.abc DROP COLUMN b;
+SELECT /* column_id, */ type, width, /* stamp, */ "sample", "count", "unique", 
nils, minval, maxval, sorted, revsorted FROM sys.statistics where column_id not 
in (select id from sys.columns);
+-- expected 0 rows but found 1 row !
+
+DROP TABLE sys.abc CASCADE;
+SELECT /* column_id, */ type, width, /* stamp, */ "sample", "count", "unique", 
nils, minval, maxval, sorted, revsorted FROM sys.statistics where column_id not 
in (select id from sys.columns);
+-- expected 0 rows but found 2 rows !
+
+SELECT /* column_id, */ type, width, /* stamp, */ "sample", "count", "unique", 
nils, minval, maxval, sorted, revsorted FROM sys.statistics;
+-- expected 0 rows but found 2 rows !
+DELETE FROM sys.statistics;
diff --git 
a/sql/test/BugTracker-2017/Tests/cleanup_statistics.Bug-6439.stable.err 
b/sql/test/BugTracker-2017/Tests/cleanup_statistics.Bug-6439.stable.err
new file mode 100644
--- /dev/null
+++ b/sql/test/BugTracker-2017/Tests/cleanup_statistics.Bug-6439.stable.err
@@ -0,0 +1,34 @@
+stderr of test 'cleanup_statistics.Bug-6439` in directory 
'sql/test/BugTracker-2017` itself:
+
+
+# 17:52:04 >  
+# 17:52:04 >  "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set" 
"mapi_open=true" "--set" "mapi_port=33623" "--set" 
"mapi_usock=/var/tmp/mtest-15308/.s.monetdb.33623" "--set" "monet_prompt=" 
"--forcemito" 
"--dbpath=/home/niels/scratch/rc-monetdb/Linux-x86_64/var/MonetDB/mTests_sql_test_BugTracker-2017"
+# 17:52:04 >  
+
+# builtin opt  gdk_dbpath = 
/home/niels/scratch/rc-monetdb/Linux-x86_64/var/monetdb5/dbfarm/demo
+# builtin opt  gdk_debug = 0
+# builtin opt  gdk_vmtrim = no
+# builtin opt  monet_prompt = >
+# builtin opt  monet_daemon = no
+# builtin opt  mapi_port = 50000
+# builtin opt  mapi_open = false
+# builtin opt  mapi_autosense = false
+# builtin opt  sql_optimizer = default_pipe
+# builtin opt  sql_debug = 0
+# cmdline opt  gdk_nr_threads = 0
+# cmdline opt  mapi_open = true
+# cmdline opt  mapi_port = 33623
+# cmdline opt  mapi_usock = /var/tmp/mtest-15308/.s.monetdb.33623
+# cmdline opt  monet_prompt = 
+# cmdline opt  gdk_dbpath = 
/home/niels/scratch/rc-monetdb/Linux-x86_64/var/MonetDB/mTests_sql_test_BugTracker-2017
+# cmdline opt  gdk_debug = 536870922
+
+# 17:52:04 >  
+# 17:52:04 >  "mclient" "-lsql" "-ftest" "-Eutf-8" "-i" "-e" 
"--host=/var/tmp/mtest-15308" "--port=33623"
+# 17:52:04 >  
+
+
+# 17:52:04 >  
+# 17:52:04 >  "Done."
+# 17:52:04 >  
+
diff --git 
a/sql/test/BugTracker-2017/Tests/cleanup_statistics.Bug-6439.stable.out 
b/sql/test/BugTracker-2017/Tests/cleanup_statistics.Bug-6439.stable.out
new file mode 100644
--- /dev/null
+++ b/sql/test/BugTracker-2017/Tests/cleanup_statistics.Bug-6439.stable.out
@@ -0,0 +1,76 @@
+stdout of test 'cleanup_statistics.Bug-6439` in directory 
'sql/test/BugTracker-2017` itself:
+
+
+# 17:52:04 >  
+# 17:52:04 >  "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set" 
"mapi_open=true" "--set" "mapi_port=33623" "--set" 
"mapi_usock=/var/tmp/mtest-15308/.s.monetdb.33623" "--set" "monet_prompt=" 
"--forcemito" 
"--dbpath=/home/niels/scratch/rc-monetdb/Linux-x86_64/var/MonetDB/mTests_sql_test_BugTracker-2017"
+# 17:52:04 >  
+
+# MonetDB 5 server v11.27.6
+# This is an unreleased version
+# Serving database 'mTests_sql_test_BugTracker-2017', using 4 threads
+# Compiled for x86_64-unknown-linux-gnu/64bit with 128bit integers
+# Found 7.330 GiB available main-memory.
+# Copyright (c) 1993-July 2008 CWI.
+# Copyright (c) August 2008-2017 MonetDB B.V., all rights reserved
+# Visit https://www.monetdb.org/ for further information
+# Listening for connection requests on mapi:monetdb://localhost.nes.nl:33623/
+# Listening for UNIX domain connection requests on 
mapi:monetdb:///var/tmp/mtest-15308/.s.monetdb.33623
+# MonetDB/GIS module loaded
+# MonetDB/SQL module loaded
+
+Ready.
+
+# 17:52:04 >  
+# 17:52:04 >  "mclient" "-lsql" "-ftest" "-Eutf-8" "-i" "-e" 
"--host=/var/tmp/mtest-15308" "--port=33623"
+# 17:52:04 >  
+
+#CREATE TABLE sys.abc (a INT, b VARCHAR(10));
+#INSERT INTO sys.abc VALUES (1, 'one');
+[ 1    ]
+#INSERT INTO sys.abc VALUES (2, 'two');
+[ 1    ]
+#SELECT * FROM sys.abc;
+% sys.abc,     sys.abc # table_name
+% a,   b # name
+% int, varchar # type
+% 1,   3 # length
+[ 1,   "one"   ]
+[ 2,   "two"   ]
+#DELETE FROM sys.statistics;
+[ 207  ]
+#SELECT /* column_id, */ type, width, /* stamp, */ "sample", "count", 
"unique", nils, minval, maxval, sorted, revsorted FROM sys.statistics;
+% sys.statistics,      sys.statistics, sys.statistics, sys.statistics, 
sys.statistics, sys.statistics, sys.statistics, sys.statistics, sys.statistics, 
sys.statistics # table_name
+% type,        width,  sample, count,  unique, nils,   minval, maxval, sorted, 
revsorted # name
+% clob,        int,    bigint, bigint, bigint, bigint, clob,   clob,   
boolean,        boolean # type
+% 7,   1,      1,      1,      1,      1,      5,      5,      5,      5 # 
length
+[ "int",       4,      2,      2,      2,      0,      "1",    "2",    true,   
false   ]
+[ "varchar",   1,      2,      2,      2,      0,      "\"one\"",      
"\"two\"",      true,   false   ]
+#SELECT /* column_id, */ type, width, /* stamp, */ "sample", "count", 
"unique", nils, minval, maxval, sorted, revsorted FROM sys.statistics where 
column_id not in (select id from sys.columns);
+% sys.statistics,      sys.statistics, sys.statistics, sys.statistics, 
sys.statistics, sys.statistics, sys.statistics, sys.statistics, sys.statistics, 
sys.statistics # table_name
+% type,        width,  sample, count,  unique, nils,   minval, maxval, sorted, 
revsorted # name
+% clob,        int,    bigint, bigint, bigint, bigint, clob,   clob,   
boolean,        boolean # type
+% 0,   1,      1,      1,      1,      1,      0,      0,      5,      5 # 
length
+#ALTER TABLE sys.abc DROP COLUMN b;
+#SELECT /* column_id, */ type, width, /* stamp, */ "sample", "count", 
"unique", nils, minval, maxval, sorted, revsorted FROM sys.statistics where 
column_id not in (select id from sys.columns);
+% sys.statistics,      sys.statistics, sys.statistics, sys.statistics, 
sys.statistics, sys.statistics, sys.statistics, sys.statistics, sys.statistics, 
sys.statistics # table_name
+% type,        width,  sample, count,  unique, nils,   minval, maxval, sorted, 
revsorted # name
+% clob,        int,    bigint, bigint, bigint, bigint, clob,   clob,   
boolean,        boolean # type
+% 0,   1,      1,      1,      1,      1,      0,      0,      5,      5 # 
length
+#DROP TABLE sys.abc CASCADE;
+#SELECT /* column_id, */ type, width, /* stamp, */ "sample", "count", 
"unique", nils, minval, maxval, sorted, revsorted FROM sys.statistics where 
column_id not in (select id from sys.columns);
+% sys.statistics,      sys.statistics, sys.statistics, sys.statistics, 
sys.statistics, sys.statistics, sys.statistics, sys.statistics, sys.statistics, 
sys.statistics # table_name
+% type,        width,  sample, count,  unique, nils,   minval, maxval, sorted, 
revsorted # name
+% clob,        int,    bigint, bigint, bigint, bigint, clob,   clob,   
boolean,        boolean # type
+% 0,   1,      1,      1,      1,      1,      0,      0,      5,      5 # 
length
+#SELECT /* column_id, */ type, width, /* stamp, */ "sample", "count", 
"unique", nils, minval, maxval, sorted, revsorted FROM sys.statistics;
+% sys.statistics,      sys.statistics, sys.statistics, sys.statistics, 
sys.statistics, sys.statistics, sys.statistics, sys.statistics, sys.statistics, 
sys.statistics # table_name
+% type,        width,  sample, count,  unique, nils,   minval, maxval, sorted, 
revsorted # name
+% clob,        int,    bigint, bigint, bigint, bigint, clob,   clob,   
boolean,        boolean # type
+% 0,   1,      1,      1,      1,      1,      0,      0,      5,      5 # 
length
+#DELETE FROM sys.statistics;
+[ 0    ]
+
+# 17:52:04 >  
+# 17:52:04 >  "Done."
+# 17:52:04 >  
+
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to