forked from MaterializeInc/materialize
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request MaterializeInc#3765 from benesch/topk-idiom
test: add plan + test for idiomatic top-k-in-group query
- Loading branch information
Showing
1 changed file
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# Copyright Materialize, Inc. All rights reserved. | ||
# | ||
# Use of this software is governed by the Business Source License | ||
# included in the LICENSE file at the root of this repository. | ||
# | ||
# As of the Change Date specified in that file, in accordance with | ||
# the Business Source License, use of this software will be governed | ||
# by the Apache License, Version 2.0. | ||
|
||
mode cockroach | ||
|
||
statement ok | ||
CREATE TABLE cities ( | ||
name text NOT NULL, | ||
state text NOT NULL, | ||
pop int NOT NULL | ||
) | ||
|
||
statement ok | ||
INSERT INTO cities VALUES | ||
('Los_Angeles', 'CA', 3979576), | ||
('Phoenix', 'AZ', 1680992), | ||
('Houston', 'TX', 2320268), | ||
('San_Diego', 'CA', 1423851), | ||
('San_Francisco', 'CA', 881549), | ||
('New_York', 'NY', 8336817), | ||
('Dallas', 'TX', 1343573), | ||
('San_Antonio', 'TX', 1547253), | ||
('San_Jose', 'CA', 1021795), | ||
('Chicago', 'IL', 2695598), | ||
('Austin', 'TX', 978908) | ||
|
||
query TT rowsort | ||
SELECT state, name FROM | ||
(SELECT DISTINCT state FROM cities) grp, | ||
LATERAL (SELECT name FROM cities WHERE state = grp.state ORDER BY pop DESC LIMIT 3) | ||
---- | ||
AZ Phoenix | ||
CA Los_Angeles | ||
CA San_Diego | ||
CA San_Jose | ||
IL Chicago | ||
NY New_York | ||
TX Houston | ||
TX San_Antonio | ||
TX Dallas | ||
|
||
mode standard | ||
|
||
query T multiline | ||
EXPLAIN PLAN FOR SELECT state, name FROM | ||
(SELECT DISTINCT state FROM cities) grp, | ||
LATERAL (SELECT name, pop FROM cities WHERE state = grp.state ORDER BY pop DESC LIMIT 3) | ||
---- | ||
%0 = | ||
| Get materialize.public.cities (u1) | ||
| Distinct group=(#1) | ||
|
||
%1 = | ||
| Get %0 | ||
| ArrangeBy (#0) | ||
|
||
%2 = | ||
| Get %0 | ||
| ArrangeBy (#0) | ||
|
||
%3 = | ||
| Get materialize.public.cities (u1) | ||
|
||
%4 = | ||
| Join %2 %3 (= #0 #2) | ||
| | implementation = Differential %3 %2.(#0) | ||
| | demand = (#0, #1, #3) | ||
| TopK group=(#0) order=(#3 desc) limit=3 offset=0 | ||
|
||
%5 = | ||
| Join %1 %4 (= #0 #1) | ||
| | implementation = Differential %4 %1.(#0) | ||
| | demand = (#0, #2) | ||
| Project (#0, #2) | ||
|
||
EOF |