Skip to content
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

Rewrite more functions #5732

Merged
merged 4 commits into from
Mar 11, 2020
Merged

Conversation

systay
Copy link
Collaborator

@systay systay commented Jan 17, 2020

This PR adds support for SCHEMA() and FOUND_ROWS(). SQL_CALC_FOUND_ROWS is being implemented in a separate PR

@systay systay requested a review from sougou as a code owner January 17, 2020 21:50
@systay systay requested a review from deepthi January 17, 2020 21:54
@systay systay force-pushed the more-functions branch 2 times, most recently from a27b6ec to bc40c03 Compare January 22, 2020 14:55
@morgo
Copy link
Contributor

morgo commented Jan 22, 2020

There is a bug in SQL_CALC_FOUND_ROWS. Here is the test case:

DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (id INT NOT NULL PRIMARY KEY auto_increment);
INSERT INTO t1 VALUES (NULL),(NULL),(NULL),(NULL),(NULL);

SELECT SQL_CALC_FOUND_ROWS * FROM t1 LIMIT 1;
SELECT FOUND_ROWS();

SELECT SQL_CALC_FOUND_ROWS * FROM t1 LIMIT 2;
SELECT FOUND_ROWS();

The first FOUND_ROWS() returns 1, second returns 2. Both would be correct if the SQL_CALC_FOUND_ROWS was not present. Because it is, both calls are expected to return 5.

@systay
Copy link
Collaborator Author

systay commented Jan 23, 2020

There is a bug in SQL_CALC_FOUND_ROWS.

Well, I've only added parsing support so far. I have yet to add the bugs to the planner. ;)

Copy link
Contributor

@sougou sougou left a comment

Choose a reason for hiding this comment

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

I don't see the tabletserver part where we have to turn around, request found_rows() and return it to vtgate.
That still needs to be implemented, right?

Everything else looks good.

go/vt/vtgate/executor.go Outdated Show resolved Hide resolved
@systay systay force-pushed the more-functions branch 2 times, most recently from acc0ac5 to d12ffce Compare February 7, 2020 10:45
@systay systay force-pushed the more-functions branch 3 times, most recently from e3ecaa8 to 2bc44b1 Compare March 2, 2020 10:23
go/vt/sqlparser/expression_rewriting.go Outdated Show resolved Hide resolved
Comment on lines +148 to +150
if err == nil {
safeSession.FoundRows = result.RowsAffected
}
Copy link
Member

Choose a reason for hiding this comment

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

do you not need locking around updating the foundRows?

Comment on lines 99 to 100

sqlparser.BindVarNeeds
Copy link
Member

Choose a reason for hiding this comment

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

nit: add comment for being in the plan like others. Also need to add json:"-" if this does not need json representation.

Signed-off-by: Harshit Gangal <[email protected]>
Copy link
Member

@harshit-gangal harshit-gangal left a comment

Choose a reason for hiding this comment

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

LGTM

@harshit-gangal harshit-gangal merged commit c7395ce into vitessio:master Mar 11, 2020
@gitmko0
Copy link

gitmko0 commented Jun 13, 2020

I'm having problem with SQL_CALC_FOUND_ROWS not being Rewrite as well. Is this resolved?
When will it be resolved?

SELECT SQL_CALC_FOUND_ROWS t_posts.ID FROM t_posts WHERE 1=1 AND t_posts.post_type = 'post' AND (t_posts.post_status = 'publish') ORDER BY t_posts.post_date DESC LIMIT 0, 10

New Edit : i found out this was not updated in the vitess.io repo.
this github one is working now. sorry for this comment.

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.

5 participants