Merge pull request #2659 from citusdata/fix_more_order_bys

Add missing ORDER BYs
pull/2661/head
Hadi Moshayedi 2019-04-09 14:00:22 -07:00 committed by GitHub
commit 1706813dd7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 87 additions and 64 deletions

View File

@ -75,15 +75,17 @@ SELECT
FROM
raw_events_first, raw_events_second
WHERE
raw_events_first.user_id = raw_events_second.user_id;
raw_events_first.user_id = raw_events_second.user_id
ORDER BY
user_id DESC;
user_id
---------
3
4
1
5
2
6
5
4
3
2
1
(6 rows)
-- see that we get unique vialitons

View File

@ -514,15 +514,15 @@ SELECT master_create_worker_shards('nation_hash_collation_search_path', 4, 2);
(1 row)
\copy nation_hash_collation_search_path FROM STDIN with delimiter '|';
SELECT * FROM nation_hash_collation_search_path;
SELECT * FROM nation_hash_collation_search_path ORDER BY 1 DESC, 2 DESC, 3 DESC, 4 DESC;
n_nationkey | n_name | n_regionkey | n_comment
-------------+---------------------------+-------------+-------------------------------------------------------------------------------------------------------------
1 | ARGENTINA | 1 | al foxes promise slyly according to the regular accounts. bold requests alon
5 | ETHIOPIA | 0 | ven packages wake quickly. regu
0 | ALGERIA | 0 | haggle. carefully final deposits detect slyly agai
3 | CANADA | 1 | eas hang ironic, silent packages. slyly regular packages are furiously over the tithes. fluffily bold
4 | EGYPT | 4 | y above the carefully unusual theodolites. final dugouts are quickly across the furiously regular d
3 | CANADA | 1 | eas hang ironic, silent packages. slyly regular packages are furiously over the tithes. fluffily bold
2 | BRAZIL | 1 | y alongside of the pending deposits. carefully special packages are about the ironic forges. slyly special
1 | ARGENTINA | 1 | al foxes promise slyly according to the regular accounts. bold requests alon
0 | ALGERIA | 0 | haggle. carefully final deposits detect slyly agai
(6 rows)
SELECT n_comment FROM nation_hash_collation_search_path ORDER BY n_comment COLLATE english;

View File

@ -106,10 +106,12 @@ INSERT INTO users_test_table (user_id, value_3) VALUES(16,1), (20,16), (7,1), (2
SET citus.multi_shard_modify_mode to sequential;
UPDATE users_test_table SET value_3 = 1;
END;
SELECT COUNT()SUM(value_3) FROM users_test_table;
ERROR: syntax error at or near "("
LINE 1: SELECT COUNT()SUM(value_3) FROM users_test_table;
^
SELECT SUM(value_3) FROM users_test_table;
sum
-----
16
(1 row)
SET citus.multi_shard_modify_mode to 'sequential';
-- Run multiple multi shard updates (with sequential executor)
BEGIN;
@ -205,15 +207,15 @@ SELECT * FROM master_append_table_to_shard(1440011, 'append_stage_table_2', 'loc
(1 row)
UPDATE test_append_table SET col_2 = 5;
SELECT * FROM test_append_table;
SELECT * FROM test_append_table ORDER BY 1 DESC, 2 DESC;
id | col_2
----+-------
8 | 5
9 | 5
10 | 5
1 | 5
3 | 5
9 | 5
8 | 5
5 | 5
3 | 5
1 | 5
(6 rows)
DROP TABLE append_stage_table;
@ -235,7 +237,7 @@ NOTICE: Copying data from local table...
UPDATE tt1 SET col_2 = 13;
DELETE FROM tt1 WHERE id = 1 or id = 3 or id = 5;
SELECT * FROM tt1;
SELECT * FROM tt1 ORDER BY 1 DESC, 2 DESC;
id | col_2
----+-------
8 | 13
@ -743,11 +745,12 @@ ERROR: cannot push down this subquery
DETAIL: Shards of relations in subquery need to have 1-to-1 shard partitioning
-- Should error out due to multiple row return from subquery, but we can not get this information within
-- subquery pushdown planner. This query will be sent to worker with recursive planner.
\set VERBOSITY terse
DELETE FROM users_test_table
WHERE users_test_table.user_id = (SELECT user_id
FROM events_test_table);
ERROR: more than one row returned by a subquery used as an expression
CONTEXT: while executing command on localhost:57637
\set VERBOSITY default
-- Cursors are not supported
BEGIN;
DECLARE test_cursor CURSOR FOR SELECT * FROM users_test_table ORDER BY user_id;
@ -761,12 +764,12 @@ UPDATE users_test_table SET value_2 = 5 WHERE CURRENT OF test_cursor;
ERROR: cannot run DML queries with cursors
ROLLBACK;
-- Stable functions are supported
SELECT * FROM test_table_1;
SELECT * FROM test_table_1 ORDER BY 1 DESC, 2 DESC, 3 DESC;
id | date_col | col_3
----+------------------------------+-------
1 | Sat Apr 05 08:32:12 2014 PDT | 5
3 | Mon Jan 12 08:35:19 2111 PST | 9
2 | Sun Feb 01 08:31:16 2015 PST | 7
1 | Sat Apr 05 08:32:12 2014 PDT | 5
(3 rows)
UPDATE test_table_1 SET col_3 = 3 WHERE date_col < now();

View File

@ -1373,7 +1373,7 @@ FROM
lastseen DESC
LIMIT 10) "some_users"
ORDER BY
user_id DESC
user_id DESC, lastseen DESC
LIMIT 10;
user_id | lastseen
---------+---------------------------------
@ -1497,7 +1497,7 @@ FROM
lastseen DESC
LIMIT 10) "some_users"
ORDER BY
user_id DESC
user_id DESC, lastseen DESC
LIMIT 10;
DEBUG: generating subplan 53_1 for subquery SELECT user_id FROM public.users_table users WHERE ((user_id OPERATOR(pg_catalog.>) 1) AND (user_id OPERATOR(pg_catalog.<) 4) AND (value_2 OPERATOR(pg_catalog.>) 3))
DEBUG: skipping recursive planning for the subquery since it contains references to outer queries
@ -1557,7 +1557,7 @@ FROM
lastseen DESC
LIMIT 10) "some_users"
ORDER BY
user_id DESC
user_id DESC, lastseen DESC
LIMIT 10;
DEBUG: generating subplan 56_1 for subquery SELECT user_id, value_1 FROM public.users_table users WHERE ((user_id OPERATOR(pg_catalog.>) 1) AND (user_id OPERATOR(pg_catalog.<) 4) AND (value_2 OPERATOR(pg_catalog.>) 3))
ERROR: cannot push down this subquery
@ -1615,7 +1615,7 @@ FROM
lastseen DESC
LIMIT 10) "some_users"
ORDER BY
user_id DESC
user_id DESC, lastseen DESC
LIMIT 10;
ERROR: complex joins are only supported when all distributed tables are joined on their distribution columns with equal operator
-- not pushdownable since lower LATERAL JOIN is not on the partition key
@ -1671,7 +1671,7 @@ FROM
lastseen DESC
LIMIT 10) "some_users"
ORDER BY
user_id DESC
user_id DESC, lastseen DESC
LIMIT 10;
ERROR: cannot push down this subquery
DETAIL: Limit in subquery is currently unsupported when a subquery references a column from another query
@ -1977,19 +1977,19 @@ FROM
value_3 DESC
LIMIT 10) "some_users"
ORDER BY
value_3 DESC
value_3 DESC, user_id ASC
LIMIT 10;
user_id | value_3
---------+---------
3 | 5
3 | 5
3 | 5
3 | 5
3 | 5
2 | 5
2 | 5
2 | 5
2 | 5
3 | 5
3 | 5
3 | 5
3 | 5
3 | 5
(9 rows)
-- nested lateral join at top most level

View File

@ -159,9 +159,10 @@ FROM
users_table.user_id = events_table.user_id AND
event_type IN (1,2,3,4)
) SELECT * FROM cte ORDER BY 1 DESC
) as foo;
) as foo
ORDER BY 1 DESC;
DEBUG: generating subplan 18_1 for CTE cte: SELECT DISTINCT users_table.user_id FROM subquery_and_ctes.users_table, subquery_and_ctes.events_table WHERE ((users_table.user_id OPERATOR(pg_catalog.=) events_table.user_id) AND (events_table.event_type OPERATOR(pg_catalog.=) ANY (ARRAY[1, 2, 3, 4])))
DEBUG: Plan 18 query after replacing subqueries and CTEs: SELECT user_id FROM (SELECT cte.user_id FROM (SELECT intermediate_result.user_id FROM read_intermediate_result('18_1'::text, 'binary'::citus_copy_format) intermediate_result(user_id integer)) cte ORDER BY cte.user_id DESC) foo
DEBUG: Plan 18 query after replacing subqueries and CTEs: SELECT user_id FROM (SELECT cte.user_id FROM (SELECT intermediate_result.user_id FROM read_intermediate_result('18_1'::text, 'binary'::citus_copy_format) intermediate_result(user_id integer)) cte ORDER BY cte.user_id DESC) foo ORDER BY user_id DESC
user_id
---------
6
@ -198,17 +199,18 @@ FROM
event_type IN (1,2,3,4)
) as bar
WHERE foo.user_id = bar.user_id;
WHERE foo.user_id = bar.user_id
ORDER BY 1 DESC;
DEBUG: generating subplan 20_1 for CTE cte: SELECT DISTINCT users_table.user_id FROM subquery_and_ctes.users_table, subquery_and_ctes.events_table WHERE ((users_table.user_id OPERATOR(pg_catalog.=) events_table.user_id) AND (events_table.event_type OPERATOR(pg_catalog.=) ANY (ARRAY[1, 2, 3, 4])))
DEBUG: Plan 20 query after replacing subqueries and CTEs: SELECT bar.user_id FROM (SELECT cte.user_id FROM (SELECT intermediate_result.user_id FROM read_intermediate_result('20_1'::text, 'binary'::citus_copy_format) intermediate_result(user_id integer)) cte ORDER BY cte.user_id DESC) foo, (SELECT DISTINCT users_table.user_id FROM subquery_and_ctes.users_table, subquery_and_ctes.events_table WHERE ((users_table.user_id OPERATOR(pg_catalog.=) events_table.user_id) AND (events_table.event_type OPERATOR(pg_catalog.=) ANY (ARRAY[1, 2, 3, 4])))) bar WHERE (foo.user_id OPERATOR(pg_catalog.=) bar.user_id)
DEBUG: Plan 20 query after replacing subqueries and CTEs: SELECT bar.user_id FROM (SELECT cte.user_id FROM (SELECT intermediate_result.user_id FROM read_intermediate_result('20_1'::text, 'binary'::citus_copy_format) intermediate_result(user_id integer)) cte ORDER BY cte.user_id DESC) foo, (SELECT DISTINCT users_table.user_id FROM subquery_and_ctes.users_table, subquery_and_ctes.events_table WHERE ((users_table.user_id OPERATOR(pg_catalog.=) events_table.user_id) AND (events_table.event_type OPERATOR(pg_catalog.=) ANY (ARRAY[1, 2, 3, 4])))) bar WHERE (foo.user_id OPERATOR(pg_catalog.=) bar.user_id) ORDER BY bar.user_id DESC
user_id
---------
1
6
5
4
3
6
2
1
(6 rows)
-- CTEs inside a deeper subquery
@ -439,7 +441,8 @@ FROM
event_type IN (1,2,3,4)
) as bar
WHERE foo.user_id = bar.user_id;
WHERE foo.user_id = bar.user_id
ORDER BY 1 DESC;
ERROR: recursive CTEs are not supported in distributed queries
-- We error-out when there's an error in execution of the query. By repeating it
-- multiple times, we increase the chance of this test failing before PR #1903.

View File

@ -292,7 +292,8 @@ SELECT
FROM
multi_outer_join_left l1
LEFT JOIN multi_outer_join_right r1 ON (l1.l_custkey = r1.r_custkey)
LEFT JOIN multi_outer_join_third_reference t1 ON (r1.r_custkey = t1.t_custkey);
LEFT JOIN multi_outer_join_third_reference t1 ON (r1.r_custkey = t1.t_custkey)
ORDER BY l_custkey, r_custkey, t_custkey;
-- Right join with single shard right most table should error out
SELECT
@ -300,7 +301,8 @@ SELECT
FROM
multi_outer_join_left l1
LEFT JOIN multi_outer_join_right r1 ON (l1.l_custkey = r1.r_custkey)
RIGHT JOIN multi_outer_join_third_reference t1 ON (r1.r_custkey = t1.t_custkey);
RIGHT JOIN multi_outer_join_third_reference t1 ON (r1.r_custkey = t1.t_custkey)
ORDER BY l_custkey, r_custkey, t_custkey;
-- Right join with single shard left most table should work
SELECT
@ -308,7 +310,8 @@ SELECT
FROM
multi_outer_join_third_reference t1
RIGHT JOIN multi_outer_join_right r1 ON (t1.t_custkey = r1.r_custkey)
LEFT JOIN multi_outer_join_left l1 ON (r1.r_custkey = l1.l_custkey);
LEFT JOIN multi_outer_join_left l1 ON (r1.r_custkey = l1.l_custkey)
ORDER BY t_custkey, r_custkey, l_custkey;
-- Make it anti-join, should display values with l_custkey is null
SELECT
@ -318,7 +321,8 @@ FROM
RIGHT JOIN multi_outer_join_right r1 ON (t1.t_custkey = r1.r_custkey)
LEFT JOIN multi_outer_join_left l1 ON (r1.r_custkey = l1.l_custkey)
WHERE
l_custkey is NULL;
l_custkey is NULL
ORDER BY t_custkey, r_custkey, l_custkey;
-- Cascading right join with single shard left most table
SELECT

View File

@ -379,7 +379,8 @@ SELECT
FROM
multi_outer_join_left l1
LEFT JOIN multi_outer_join_right r1 ON (l1.l_custkey = r1.r_custkey)
LEFT JOIN multi_outer_join_third_reference t1 ON (r1.r_custkey = t1.t_custkey);
LEFT JOIN multi_outer_join_third_reference t1 ON (r1.r_custkey = t1.t_custkey)
ORDER BY l_custkey, r_custkey, t_custkey;
l_custkey | r_custkey | t_custkey
-----------+-----------+-----------
11 | 11 | 11
@ -407,7 +408,8 @@ SELECT
FROM
multi_outer_join_left l1
LEFT JOIN multi_outer_join_right r1 ON (l1.l_custkey = r1.r_custkey)
RIGHT JOIN multi_outer_join_third_reference t1 ON (r1.r_custkey = t1.t_custkey);
RIGHT JOIN multi_outer_join_third_reference t1 ON (r1.r_custkey = t1.t_custkey)
ORDER BY l_custkey, r_custkey, t_custkey;
ERROR: cannot pushdown the subquery
DETAIL: There exist a reference table in the outer part of the outer join
-- Right join with single shard left most table should work
@ -416,7 +418,8 @@ SELECT
FROM
multi_outer_join_third_reference t1
RIGHT JOIN multi_outer_join_right r1 ON (t1.t_custkey = r1.r_custkey)
LEFT JOIN multi_outer_join_left l1 ON (r1.r_custkey = l1.l_custkey);
LEFT JOIN multi_outer_join_left l1 ON (r1.r_custkey = l1.l_custkey)
ORDER BY t_custkey, r_custkey, l_custkey;
t_custkey | r_custkey | l_custkey
-----------+-----------+-----------
11 | 11 | 11
@ -446,7 +449,8 @@ FROM
RIGHT JOIN multi_outer_join_right r1 ON (t1.t_custkey = r1.r_custkey)
LEFT JOIN multi_outer_join_left l1 ON (r1.r_custkey = l1.l_custkey)
WHERE
l_custkey is NULL;
l_custkey is NULL
ORDER BY t_custkey, r_custkey, l_custkey;
t_custkey | r_custkey | l_custkey
-----------+-----------+-----------
13 | 13 |

View File

@ -58,7 +58,9 @@ SELECT
FROM
raw_events_first, raw_events_second
WHERE
raw_events_first.user_id = raw_events_second.user_id;
raw_events_first.user_id = raw_events_second.user_id
ORDER BY
user_id DESC;
-- see that we get unique vialitons
\set VERBOSITY TERSE

View File

@ -373,7 +373,7 @@ SELECT master_create_worker_shards('nation_hash_collation_search_path', 4, 2);
5|ETHIOPIA|0|ven packages wake quickly. regu
\.
SELECT * FROM nation_hash_collation_search_path;
SELECT * FROM nation_hash_collation_search_path ORDER BY 1 DESC, 2 DESC, 3 DESC, 4 DESC;
SELECT n_comment FROM nation_hash_collation_search_path ORDER BY n_comment COLLATE english;
--test composite types with schema

View File

@ -90,7 +90,7 @@ INSERT INTO users_test_table (user_id, value_3) VALUES(16,1), (20,16), (7,1), (2
SET citus.multi_shard_modify_mode to sequential;
UPDATE users_test_table SET value_3 = 1;
END;
SELECT COUNT()SUM(value_3) FROM users_test_table;
SELECT SUM(value_3) FROM users_test_table;
SET citus.multi_shard_modify_mode to 'sequential';
-- Run multiple multi shard updates (with sequential executor)
@ -147,7 +147,7 @@ SELECT * FROM master_append_table_to_shard(1440010, 'append_stage_table', 'local
SELECT master_create_empty_shard('test_append_table') AS new_shard_id;
SELECT * FROM master_append_table_to_shard(1440011, 'append_stage_table_2', 'localhost', :master_port);
UPDATE test_append_table SET col_2 = 5;
SELECT * FROM test_append_table;
SELECT * FROM test_append_table ORDER BY 1 DESC, 2 DESC;
DROP TABLE append_stage_table;
DROP TABLE append_stage_table_2;
@ -163,7 +163,7 @@ INSERT INTO tt1 VALUES (1,11), (3,15), (5,17), (6,19), (8,17), (2,12);
SELECT create_distributed_table('tt1','id');
UPDATE tt1 SET col_2 = 13;
DELETE FROM tt1 WHERE id = 1 or id = 3 or id = 5;
SELECT * FROM tt1;
SELECT * FROM tt1 ORDER BY 1 DESC, 2 DESC;
-- Partitioned distributed table within transaction
INSERT INTO tt1 VALUES(4,6);
@ -628,9 +628,11 @@ WHERE users_test_table.user_id = events_test_table_2.user_id;
-- Should error out due to multiple row return from subquery, but we can not get this information within
-- subquery pushdown planner. This query will be sent to worker with recursive planner.
\set VERBOSITY terse
DELETE FROM users_test_table
WHERE users_test_table.user_id = (SELECT user_id
FROM events_test_table);
\set VERBOSITY default
-- Cursors are not supported
BEGIN;
@ -640,7 +642,7 @@ UPDATE users_test_table SET value_2 = 5 WHERE CURRENT OF test_cursor;
ROLLBACK;
-- Stable functions are supported
SELECT * FROM test_table_1;
SELECT * FROM test_table_1 ORDER BY 1 DESC, 2 DESC, 3 DESC;
UPDATE test_table_1 SET col_3 = 3 WHERE date_col < now();
SELECT * FROM test_table_1;
DELETE FROM test_table_1 WHERE date_col < current_timestamp;

View File

@ -1258,7 +1258,7 @@ FROM
lastseen DESC
LIMIT 10) "some_users"
ORDER BY
user_id DESC
user_id DESC, lastseen DESC
LIMIT 10;
--
@ -1366,7 +1366,7 @@ FROM
lastseen DESC
LIMIT 10) "some_users"
ORDER BY
user_id DESC
user_id DESC, lastseen DESC
LIMIT 10;
@ -1424,7 +1424,7 @@ FROM
lastseen DESC
LIMIT 10) "some_users"
ORDER BY
user_id DESC
user_id DESC, lastseen DESC
LIMIT 10;
@ -1482,7 +1482,7 @@ FROM
lastseen DESC
LIMIT 10) "some_users"
ORDER BY
user_id DESC
user_id DESC, lastseen DESC
LIMIT 10;
-- not pushdownable since lower LATERAL JOIN is not on the partition key
@ -1538,7 +1538,7 @@ FROM
lastseen DESC
LIMIT 10) "some_users"
ORDER BY
user_id DESC
user_id DESC, lastseen DESC
LIMIT 10;
-- NESTED INNER JOINs
@ -1805,7 +1805,7 @@ FROM
value_3 DESC
LIMIT 10) "some_users"
ORDER BY
value_3 DESC
value_3 DESC, user_id ASC
LIMIT 10;
-- nested lateral join at top most level

View File

@ -112,7 +112,8 @@ FROM
users_table.user_id = events_table.user_id AND
event_type IN (1,2,3,4)
) SELECT * FROM cte ORDER BY 1 DESC
) as foo;
) as foo
ORDER BY 1 DESC;
-- CTEs inside a subquery and the final query becomes a
@ -141,7 +142,8 @@ FROM
event_type IN (1,2,3,4)
) as bar
WHERE foo.user_id = bar.user_id;
WHERE foo.user_id = bar.user_id
ORDER BY 1 DESC;
-- CTEs inside a deeper subquery
-- and also the subquery that contains the CTE is replaced
@ -314,7 +316,8 @@ FROM
event_type IN (1,2,3,4)
) as bar
WHERE foo.user_id = bar.user_id;
WHERE foo.user_id = bar.user_id
ORDER BY 1 DESC;
-- We error-out when there's an error in execution of the query. By repeating it
-- multiple times, we increase the chance of this test failing before PR #1903.