You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix non-bulletproof ScalarArrayOpExpr code for extended statistics.
statext_is_compatible_clause_internal() checked that the arguments
of a ScalarArrayOpExpr are one Var and one Const, but it would allow
cases where the Const was on the left. Subsequent uses of the clause
are not expecting that and would suffer assertion failures or core
dumps. mcv.c also had not bothered to cope with the case of a NULL
array constant, which seems really unacceptably sloppy of somebody.
(Although our tools failed us there too, since AFAIK neither Coverity
nor any compiler warned of the obvious use-of-uninitialized-variable
condition.) It seems best to handle that by having
statext_is_compatible_clause_internal() reject it.
Noted while fixing bug #17570. Back-patch to v13 where the
extended stats code grew some awareness of ScalarArrayOpExpr.
Copy file name to clipboardExpand all lines: src/test/regress/sql/stats_ext.sql
+10-4Lines changed: 10 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -923,7 +923,8 @@ CREATE TABLE mcv_lists (
923
923
b VARCHAR,
924
924
filler3 DATE,
925
925
c INT,
926
-
d TEXT
926
+
d TEXT,
927
+
ia INT[]
927
928
)
928
929
WITH (autovacuum_enabled = off);
929
930
@@ -972,8 +973,9 @@ SELECT * FROM check_estimated_rows('SELECT * FROM mcv_lists WHERE mod(a,7) = 1 A
972
973
TRUNCATE mcv_lists;
973
974
DROP STATISTICS mcv_lists_stats;
974
975
975
-
INSERT INTO mcv_lists (a, b, c, filler1)
976
-
SELECT mod(i,100), mod(i,50), mod(i,25), i FROM generate_series(1,5000) s(i);
976
+
INSERT INTO mcv_lists (a, b, c, ia, filler1)
977
+
SELECT mod(i,100), mod(i,50), mod(i,25), array[mod(i,25)], i
978
+
FROM generate_series(1,5000) s(i);
977
979
978
980
ANALYZE mcv_lists;
979
981
@@ -1023,8 +1025,10 @@ SELECT * FROM check_estimated_rows('SELECT * FROM mcv_lists WHERE a < ALL (ARRAY
1023
1025
1024
1026
SELECT*FROM check_estimated_rows('SELECT * FROM mcv_lists WHERE a < ALL (ARRAY[4, 5]) AND b IN (''1'', ''2'', NULL, ''3'') AND c > ANY (ARRAY[1, 2, NULL, 3])');
1025
1027
1028
+
SELECT*FROM check_estimated_rows('SELECT * FROM mcv_lists WHERE a = ANY (ARRAY[4,5]) AND 4 = ANY(ia)');
1029
+
1026
1030
-- create statistics
1027
-
CREATE STATISTICS mcv_lists_stats (mcv) ON a, b, c FROM mcv_lists;
1031
+
CREATE STATISTICS mcv_lists_stats (mcv) ON a, b, c, iaFROM mcv_lists;
1028
1032
1029
1033
ANALYZE mcv_lists;
1030
1034
@@ -1076,6 +1080,8 @@ SELECT * FROM check_estimated_rows('SELECT * FROM mcv_lists WHERE a < ALL (ARRAY
1076
1080
1077
1081
SELECT*FROM check_estimated_rows('SELECT * FROM mcv_lists WHERE a < ALL (ARRAY[4, 5]) AND b IN (''1'', ''2'', NULL, ''3'') AND c > ANY (ARRAY[1, 2, NULL, 3])');
1078
1082
1083
+
SELECT*FROM check_estimated_rows('SELECT * FROM mcv_lists WHERE a = ANY (ARRAY[4,5]) AND 4 = ANY(ia)');
1084
+
1079
1085
-- check change of unrelated column type does not reset the MCV statistics
1080
1086
ALTERTABLE mcv_lists ALTER COLUMN d TYPE VARCHAR(64);
0 commit comments