-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Explain plan for YCQL #861
Comments
ExamplesSetup Table and indexescqlsh> CREATE KEYSPACE IF NOT EXISTS imdb;
cqlsh> CREATE TABLE IF NOT EXISTS imdb.movie_stats (
... movie_name text,
... movie_genre text,
... user_name text,
... user_rank int,
... last_watched timestamp,
... PRIMARY KEY (movie_genre, movie_name, user_name)
... ) WITH transactions = { 'enabled' : true };
cqlsh> CREATE INDEX IF NOT EXISTS most_watched_by_year
... ON imdb.movie_stats((movie_genre, last_watched), movie_name, user_name)
... INCLUDE(user_rank);
cqlsh> CREATE INDEX IF NOT EXISTS best_rated
... ON imdb.movie_stats((user_rank, movie_genre), movie_name, user_name)
... INCLUDE(last_watched);
cqlsh> USE imdb;
cqlsh:imdb> INSERT INTO movie_stats(movie_name, movie_genre, user_name, user_rank, last_watched)
... VALUES ('m1', 'g1', 'u1', 5, '2019-01-18');
cqlsh:imdb> INSERT INTO movie_stats(movie_name, movie_genre, user_name, user_rank, last_watched)
... VALUES ('m2', 'g2', 'u1', 4, '2019-01-17');
cqlsh:imdb> INSERT INTO movie_stats(movie_name, movie_genre, user_name, user_rank, last_watched)
... VALUES ('m3', 'g1', 'u2', 5, '2019-01-18');
cqlsh:imdb> INSERT INTO movie_stats(movie_name, movie_genre, user_name, user_rank, last_watched)
... VALUES ('m4', 'g1', 'u1', 2, '2019-02-27'); // If movie_genre, cqlsh:imdb> EXPLAIN SELECT *
... FROM movie_stats
... WHERE movie_genre = 'g1';
QUERY PLAN
----------------------------------------
Range Scan on imdb.movie_stats
Key Conditions: (movie_genre = 'g1') // If movie_genre & last_watched are specified cqlsh:imdb> EXPLAIN SELECT *
... FROM movie_stats
... WHERE movie_genre = 'g1' and last_watched='2019-02-27';
QUERY PLAN
--------------------------------------------------------------------------
Index Only Scan using imdb.most_watched_by_year on imdb.movie_stats
Key Conditions: (movie_genre = 'g1') AND (last_watched = '2019-02-27')
// If user_rank and movie_genre are specified cqlsh:imdb> EXPLAIN SELECT *
... FROM movie_stats
... WHERE movie_genre = 'g2' and user_rank=5;
QUERY PLAN
--------------------------------------------------------------
Index Only Scan using imdb.best_rated on imdb.movie_stats
Key Conditions: (user_rank = '5') AND (movie_genre = 'g2')
Create non-covering index cqlsh:imdb> DROP INDEX best_rated;
cqlsh:imdb> CREATE INDEX IF NOT EXISTS best_rated
... ON imdb.movie_stats((user_rank, movie_genre), movie_name, user_name); 2-Step Select - Index Scan as opposed to Index Only Scan cqlsh:imdb> EXPLAIN SELECT *
... FROM movie_stats
... WHERE movie_genre = 'g2' and user_rank=5;
QUERY PLAN
--------------------------------------------------------------
Index Scan using imdb.best_rated on imdb.movie_stats
Key Conditions: (user_rank = '5') AND (movie_genre = 'g2') Other explain select typesWe don’t support QLName() for these expressions yet cqlsh:imdb> EXPLAIN SELECT * FROM movie_stats where movie_genre in ('g1', 'g2');
QUERY PLAN
-------------------------------------------
Range Scan on imdb.movie_stats
Key Conditions: (movie_genre IN 'expr') cqlsh:imdb> EXPLAIN SELECT COUNT(*) FROM movie_stats WHERE movie_genre = 'g2' and user_rank=5;
QUERY PLAN
--------------------------------------------------------------------
Aggregate
-> Index Only Scan using imdb.best_rated on imdb.movie_stats
Key Conditions: (user_rank = '5') AND (movie_genre = 'g2') cqlsh:imdb> EXPLAIN SELECT * FROM movie_stats WHERE movie_genre = 'g2' and user_rank = 5 LIMIT 5;
QUERY PLAN
--------------------------------------------------------------------
Limit
-> Index Only Scan using imdb.best_rated on imdb.movie_stats
Key Conditions: (user_rank = '5') AND (movie_genre = 'g2') Insert Examplecqlsh:imdb> EXPLAIN INSERT INTO movie_stats(movie_name, movie_genre, user_name, user_rank, last_watched)
... VALUES ('m4', 'g1', 'u1', 2, '2019-02-27');
QUERY PLAN
----------------------------
Insert on imdb.movie_stats Delete Examplescqlsh:imdb> explain delete from movie_stats where movie_genre = 'g1' and movie_name = 'm1';
QUERY PLAN
----------------------------------------------
Delete on imdb.movie_stats
-> Range Scan on imdb.movie_stats
Key Conditions: (movie_genre = 'g1')
Filter: (movie_name = 'm1') cqlsh:imdb> explain delete from movie_stats where movie_genre = 'g1';
QUERY PLAN
----------------------------------------------
Delete on imdb.movie_stats
-> Range Scan on imdb.movie_stats
Key Conditions: (movie_genre = 'g1') Update Examplecqlsh:imdb> EXPLAIN UPDATE movie_stats SET user_rank = 1 WHERE movie_name = 'm1' and movie_genre = 'g1' and user_name = 'u1';
QUERY PLAN
---------------------------------------------------------------------------------------------
Update on imdb.movie_stats
-> Primary Key Lookup on imdb.movie_stats
Key Conditions: (movie_genre = 'g1') AND (movie_name = 'm1') AND (user_name = 'u1') |
…#861 Summary: finished adding explain command and functionality to YCQL to show query plan for the SELECT, INSERT, UPDATE, DELETE statements similar to Postgres Explain Plan. output: #861 (comment) Test Plan: ./yb_build.sh --cxx-test ql-parser-test --gtest_filter QLTestParser.TextExplain Reviewers: mihnea, oleg, neil, robert Reviewed By: robert Subscribers: kannan, yql Differential Revision: https://phabricator.dev.yugabyte.com/D6245
Added in 43f44de |
Explain plan seems for YSQL only.
We may use this ticket to track it.
The text was updated successfully, but these errors were encountered: