1
0
mirror of https://github.com/postgres/postgres.git synced 2025-05-01 01:04:50 +03:00

subselect regress test was kind of silly; it claimed to test correlation

cases but actually did no such thing.  Make it test some more cases than
before (including things that didn't work in 6.5).
This commit is contained in:
Tom Lane 2000-03-23 07:42:13 +00:00
parent 5c63975504
commit 3097788f66
2 changed files with 63 additions and 41 deletions

View File

@ -78,40 +78,60 @@ SELECT '' AS six, f1 AS "Uncorrelated Field" FROM SUBSELECT_TBL
| 3 | 3
(6 rows) (6 rows)
SELECT '' AS three, f1, f2
FROM SUBSELECT_TBL
WHERE (f1, f2) NOT IN (SELECT f2, CAST(f3 AS int4) FROM SUBSELECT_TBL
WHERE f3 IS NOT NULL);
three | f1 | f2
-------+----+----
| 1 | 2
| 6 | 7
| 8 | 9
(3 rows)
-- Correlated subselects -- Correlated subselects
SELECT '' AS six, f1 AS "Correlated Field", f3 AS "Second Field" SELECT '' AS six, f1 AS "Correlated Field", f2 AS "Second Field"
FROM SUBSELECT_TBL FROM SUBSELECT_TBL upper
WHERE f1 IN (SELECT f2 FROM SUBSELECT_TBL WHERE f2 = f1); WHERE f1 IN (SELECT f2 FROM SUBSELECT_TBL WHERE f1 = upper.f1);
six | Correlated Field | Second Field six | Correlated Field | Second Field
-----+------------------+-------------- -----+------------------+--------------
| 1 | 3 | 1 | 2
| 2 | 4 | 2 | 3
| 3 | 5 | 3 | 4
| 1 | 1 | 1 | 1
| 2 | 2 | 2 | 2
| 3 | 3 | 3 | 3
(6 rows) (6 rows)
SELECT '' AS six, f1 AS "Correlated Field", f3 AS "Second Field" SELECT '' AS six, f1 AS "Correlated Field", f3 AS "Second Field"
FROM SUBSELECT_TBL FROM SUBSELECT_TBL upper
WHERE f1 IN (SELECT f2 FROM SUBSELECT_TBL WHERE CAST(f2 AS float) = f3); WHERE f1 IN
(SELECT f2 FROM SUBSELECT_TBL WHERE CAST(upper.f2 AS float) = f3);
six | Correlated Field | Second Field six | Correlated Field | Second Field
-----+------------------+-------------- -----+------------------+--------------
| 1 | 3
| 2 | 4 | 2 | 4
| 3 | 5 | 3 | 5
| 1 | 1 | 1 | 1
| 2 | 2 | 2 | 2
| 3 | 3 | 3 | 3
(6 rows) (5 rows)
SELECT '' AS six, f1 AS "Correlated Field", f3 AS "Second Field" SELECT '' AS six, f1 AS "Correlated Field", f3 AS "Second Field"
FROM SUBSELECT_TBL FROM SUBSELECT_TBL upper
WHERE f1 IN (SELECT f2 FROM SUBSELECT_TBL WHERE f2 = CAST(f3 AS integer)); WHERE f3 IN (SELECT upper.f1 + f2 FROM SUBSELECT_TBL
ERROR: dtoi4: unable to convert null WHERE f2 = CAST(f3 AS integer));
six | Correlated Field | Second Field
-----+------------------+--------------
| 1 | 3
| 2 | 4
| 3 | 5
| 6 | 8
(4 rows)
SELECT '' AS five, f1 AS "Correlated Field" SELECT '' AS five, f1 AS "Correlated Field"
FROM SUBSELECT_TBL FROM SUBSELECT_TBL
WHERE (f1, f2) IN (SELECT f2, CAST(f3 AS int4) FROM SUBSELECT_TBL WHERE f3 IS NOT NULL); WHERE (f1, f2) IN (SELECT f2, CAST(f3 AS int4) FROM SUBSELECT_TBL
WHERE f3 IS NOT NULL);
five | Correlated Field five | Correlated Field
------+------------------ ------+------------------
| 2 | 2
@ -121,31 +141,27 @@ SELECT '' AS five, f1 AS "Correlated Field"
| 3 | 3
(5 rows) (5 rows)
SELECT '' AS three, f1 AS "Correlated Field"
FROM SUBSELECT_TBL
WHERE (f1, f2) NOT IN (SELECT f2, CAST(f3 AS int4) FROM SUBSELECT_TBL WHERE f3 IS NOT NULL);
three | Correlated Field
-------+------------------
| 1
| 6
| 8
(3 rows)
-- --
-- Use some existing tables in the regression test -- Use some existing tables in the regression test
-- --
SELECT '' AS eight, ss.f1 AS "Correlated Field", ss.f3 AS "Second Field" SELECT '' AS eight, ss.f1 AS "Correlated Field", ss.f3 AS "Second Field"
FROM SUBSELECT_TBL ss FROM SUBSELECT_TBL ss
WHERE f1 NOT IN (SELECT f1 FROM INT4_TBL WHERE f1 != ss.f1); WHERE f1 NOT IN (SELECT f1+1 FROM INT4_TBL WHERE f1 != ss.f1);
eight | Correlated Field | Second Field eight | Correlated Field | Second Field
-------+------------------+-------------- -------+------------------+--------------
| 1 | 3
| 2 | 4 | 2 | 4
| 3 | 5 | 3 | 5
| 1 | 1
| 2 | 2 | 2 | 2
| 3 | 3 | 3 | 3
| 6 | 8 | 6 | 8
| 8 | | 8 |
(8 rows) (6 rows)
select q1, float8(count(*)) / (select count(*) from int8_tbl)
from int8_tbl group by q1;
q1 | ?column?
------------------+----------
123 | 0.4
4567890123456789 | 0.6
(2 rows)

View File

@ -39,27 +39,31 @@ SELECT '' AS six, f1 AS "Uncorrelated Field" FROM SUBSELECT_TBL
WHERE f1 IN (SELECT f2 FROM SUBSELECT_TBL WHERE WHERE f1 IN (SELECT f2 FROM SUBSELECT_TBL WHERE
f2 IN (SELECT f1 FROM SUBSELECT_TBL)); f2 IN (SELECT f1 FROM SUBSELECT_TBL));
SELECT '' AS three, f1, f2
FROM SUBSELECT_TBL
WHERE (f1, f2) NOT IN (SELECT f2, CAST(f3 AS int4) FROM SUBSELECT_TBL
WHERE f3 IS NOT NULL);
-- Correlated subselects -- Correlated subselects
SELECT '' AS six, f1 AS "Correlated Field", f3 AS "Second Field" SELECT '' AS six, f1 AS "Correlated Field", f2 AS "Second Field"
FROM SUBSELECT_TBL FROM SUBSELECT_TBL upper
WHERE f1 IN (SELECT f2 FROM SUBSELECT_TBL WHERE f2 = f1); WHERE f1 IN (SELECT f2 FROM SUBSELECT_TBL WHERE f1 = upper.f1);
SELECT '' AS six, f1 AS "Correlated Field", f3 AS "Second Field" SELECT '' AS six, f1 AS "Correlated Field", f3 AS "Second Field"
FROM SUBSELECT_TBL FROM SUBSELECT_TBL upper
WHERE f1 IN (SELECT f2 FROM SUBSELECT_TBL WHERE CAST(f2 AS float) = f3); WHERE f1 IN
(SELECT f2 FROM SUBSELECT_TBL WHERE CAST(upper.f2 AS float) = f3);
SELECT '' AS six, f1 AS "Correlated Field", f3 AS "Second Field" SELECT '' AS six, f1 AS "Correlated Field", f3 AS "Second Field"
FROM SUBSELECT_TBL FROM SUBSELECT_TBL upper
WHERE f1 IN (SELECT f2 FROM SUBSELECT_TBL WHERE f2 = CAST(f3 AS integer)); WHERE f3 IN (SELECT upper.f1 + f2 FROM SUBSELECT_TBL
WHERE f2 = CAST(f3 AS integer));
SELECT '' AS five, f1 AS "Correlated Field" SELECT '' AS five, f1 AS "Correlated Field"
FROM SUBSELECT_TBL FROM SUBSELECT_TBL
WHERE (f1, f2) IN (SELECT f2, CAST(f3 AS int4) FROM SUBSELECT_TBL WHERE f3 IS NOT NULL); WHERE (f1, f2) IN (SELECT f2, CAST(f3 AS int4) FROM SUBSELECT_TBL
WHERE f3 IS NOT NULL);
SELECT '' AS three, f1 AS "Correlated Field"
FROM SUBSELECT_TBL
WHERE (f1, f2) NOT IN (SELECT f2, CAST(f3 AS int4) FROM SUBSELECT_TBL WHERE f3 IS NOT NULL);
-- --
-- Use some existing tables in the regression test -- Use some existing tables in the regression test
@ -67,5 +71,7 @@ SELECT '' AS three, f1 AS "Correlated Field"
SELECT '' AS eight, ss.f1 AS "Correlated Field", ss.f3 AS "Second Field" SELECT '' AS eight, ss.f1 AS "Correlated Field", ss.f3 AS "Second Field"
FROM SUBSELECT_TBL ss FROM SUBSELECT_TBL ss
WHERE f1 NOT IN (SELECT f1 FROM INT4_TBL WHERE f1 != ss.f1); WHERE f1 NOT IN (SELECT f1+1 FROM INT4_TBL WHERE f1 != ss.f1);
select q1, float8(count(*)) / (select count(*) from int8_tbl)
from int8_tbl group by q1;