Skip to content

Support sql_calc_found_rows with limit in sharded keyspace#6680

Merged
harshit-gangal merged 17 commits intovitessio:masterfrom
planetscale:sql-cal-found-rows
Sep 14, 2020
Merged

Support sql_calc_found_rows with limit in sharded keyspace#6680
harshit-gangal merged 17 commits intovitessio:masterfrom
planetscale:sql-cal-found-rows

Conversation

@harshit-gangal
Copy link
Copy Markdown
Member

@harshit-gangal harshit-gangal commented Sep 9, 2020

Support queries using SQL_CALC_FOUND_ROWS. This is done by rewriting the queries according to https://dev.mysql.com/worklog/task/?id=12615:

Frequently, it would be cheaper to run the query with LIMIT and then a separate SELECT COUNT() for the same query, since COUNT() can make use of optimizations that can't be done when searching for the entire result set (e.g. filesort can be skipped for COUNT(*), whereas with CALC_FOUND_ROWS, we must disable some filesort optimizations to guarantee the right result). If you search online, you'll frequently find the advice to run two separate queries instead of using SQL_CALC_FOUND_ROWS, precisely for performance reasons.

So, vtgate will plan these queries by first solving the original query, without the SQL_CALC_FOUND_ROWS option, and then following up with a COUNT(*) query.

SELECT SQL_CALC_FOUND_ROWS col1, col2 FROM user WHERE col3 > "foo" LIMIT 10

will get be rewritten into two queries:

SELECT col1, col2 FROM user WHERE col3 > "foo" LIMIT 10
SELECT count(*) FROM user WHERE col3 > "foo" 

The first query will be used to return the results to the user, and the second will be used to save the found_rows state on the session in vtgate.

systay and others added 5 commits September 8, 2020 16:55
Signed-off-by: Andres Taylor <andres@planetscale.com>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Signed-off-by: Andres Taylor <andres@planetscale.com>
@systay systay force-pushed the sql-cal-found-rows branch from f210296 to e26f979 Compare September 9, 2020 14:38
harshit-gangal and others added 6 commits September 9, 2020 20:46
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>

Signed-off-by: Andres Taylor <andres@planetscale.com>
Signed-off-by: Andres Taylor <andres@planetscale.com>
Signed-off-by: Andres Taylor <andres@planetscale.com>
Signed-off-by: Andres Taylor <andres@planetscale.com>
@systay systay marked this pull request as ready for review September 10, 2020 09:08
@systay systay requested a review from sougou as a code owner September 10, 2020 09:08
@systay systay requested a review from deepthi September 10, 2020 09:09
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
]
}
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reset this file change.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... Weird. On my machine, with 723fef02e checked out, that file has an extra line at the end, and git does not see any changes. Not sure what's going on...

Signed-off-by: Andres Taylor <andres@planetscale.com>
Signed-off-by: Andres Taylor <andres@planetscale.com>
Signed-off-by: Andres Taylor <andres@planetscale.com>
Signed-off-by: Andres Taylor <andres@planetscale.com>
@harshit-gangal harshit-gangal merged commit e6579aa into vitessio:master Sep 14, 2020
@systay systay deleted the sql-cal-found-rows branch September 14, 2020 12:32
@askdba askdba added this to the v8.0 milestone Oct 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants