summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorTom Lane2014-04-29 17:12:26 +0000
committerTom Lane2014-04-29 17:12:46 +0000
commit95811032d782049642a672e3db0a5382616ab084 (patch)
treeb9a5bc2f915f6c4763231c0639bd10c58f344e31 /src/test
parentdbe31616c9be7380b8a88cdfbeaa68dbdcdebc36 (diff)
Improve planner to drop constant-NULL inputs of AND/OR where it's legal.
In general we can't discard constant-NULL inputs, since they could change the result of the AND/OR to be NULL. But at top level of WHERE, we do not need to distinguish a NULL result from a FALSE result, so it's okay to treat NULL as FALSE and then simplify AND/OR accordingly. This is a very ancient oversight, but in 9.2 and later it can lead to failure to optimize queries that previous releases did optimize, as a result of more aggressive parameter substitution rules making it possible to reduce more subexpressions to NULL constants. This is the root cause of bug #10171 from Arnold Scheffler. We could alternatively have fixed that by teaching orclauses.c to ignore constant-NULL OR arms, but it seems better to get rid of them globally. I resisted the temptation to back-patch this change into all active branches, but it seems appropriate to back-patch as far as 9.2 so that there will not be performance regressions of the kind shown in this bug.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/regress/expected/create_index.out11
-rw-r--r--src/test/regress/sql/create_index.sql7
2 files changed, 18 insertions, 0 deletions
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index f13b4f8a08d..f6f55163211 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -2771,3 +2771,14 @@ ORDER BY thousand;
1 | 1001
(2 rows)
+--
+-- Check elimination of constant-NULL subexpressions
+--
+explain (costs off)
+ select * from tenk1 where (thousand, tenthous) in ((1,1001), (null,null));
+ QUERY PLAN
+------------------------------------------------------
+ Index Scan using tenk1_thous_tenthous on tenk1
+ Index Cond: ((thousand = 1) AND (tenthous = 1001))
+(2 rows)
+
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index cd5c58d468c..d4d24ef82b4 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -931,3 +931,10 @@ ORDER BY thousand;
SELECT thousand, tenthous FROM tenk1
WHERE thousand < 2 AND tenthous IN (1001,3000)
ORDER BY thousand;
+
+--
+-- Check elimination of constant-NULL subexpressions
+--
+
+explain (costs off)
+ select * from tenk1 where (thousand, tenthous) in ((1,1001), (null,null));