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

Adds session option to cache query plans #3246

Merged

Conversation

rafael
Copy link
Member

@rafael rafael commented Sep 26, 2017

Motivation

  • Recently we ran into some issues due to query plan cache in vtgate growing too fast and causing OOM errors in the machine. It turned out, that in this context we don't need to be caching query plans.

  • This commit adds a new option to ExecuteOptions. It allows clients to set a
    session variable to not cache query plans.

  • If you are using mysql server plugin, you can set this variable with:

    set skip_query_plan_cache=1 
    
  • By default, all query plans are cached (existent behavior)

Open Questions

  • Is it possible to pass this variable at connection time? If we could do something similar toCLIENT_FOUND_ROWS, it would be way more convenient. However, I didn't find a clear path to support this :(
  • Should we also use this setting to not cache query plans in tablets?

Tests

  • Locally and unit tests

@@ -280,6 +284,22 @@ func (e *Executor) handleSet(ctx context.Context, session *vtgatepb.Session, sql
default:
return nil, vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT, "unexpected value for client_found_rows: %d", val)
}
case "no_cache_query_plan":
Copy link
Member

Choose a reason for hiding this comment

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

Although this was the option we discussed IRL, as a general rule I try to avoid having the "negative" case encoded in options, even when it is the default.

In other words, I think we should change this so the exposed option is set cache_query_plan with a default value of 1.

return plan, nil
}

// getNoCacheQueryPlanFromSession extracts NoCacheQueryPlan from session
Copy link
Member

Choose a reason for hiding this comment

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

This is a mouthful and the "FromSession" is implicit in the function signature.

Also in light of the above comment, I'd change this to be func shouldCacheQueryPlan(session *vtgatepb.Session) bool

@@ -287,6 +287,10 @@ message ExecuteOptions {
}

TransactionIsolation transaction_isolation = 9;

// no_cache_query_plan specifies if the query plan shoud be cached by vitess.
Copy link
Member

Choose a reason for hiding this comment

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

Note that even if we switch the exposed set option, this needs to stay as-is so that the default value in the ExecuteOptions protobuf stays 0.

@demmer
Copy link
Member

demmer commented Sep 26, 2017

Is it possible to pass this variable at connection time? If we could do something similar toCLIENT_FOUND_ROWS, it would be way more convenient. However, I didn't find a clear path to support this :(

Not that I know of

Should we also use this setting to not cache query plans in tablets?

Yes!

@rafael rafael force-pushed the add-session-option-for-query-plan-cache branch from 71b50e5 to da58bc5 Compare September 26, 2017 18:07
@rafael
Copy link
Member Author

rafael commented Sep 26, 2017

@demmer addressed most of the comments. I have one comment about:

set cache_query_plan

I agree with the idea and I also try to avoid negative options. However, in this case I would argue we should keep it like this to be consistent. If no_cache_query_plan in the proto definition were private, it would be different. Given that someone using the grpc protocol will still have to set no_cache_query_plan, I think it's better to keep it consistent between the two. What do yo think?

@rafael rafael force-pushed the add-session-option-for-query-plan-cache branch from da58bc5 to 77afafc Compare September 26, 2017 23:43
@rafael rafael changed the title WIP: Adds session option to cache query plans Adds session option to cache query plans Sep 26, 2017
@rafael
Copy link
Member Author

rafael commented Sep 26, 2017

Addressed negative option by renaming no_cache_query_plan to skip_query_plan_cache

@rafael rafael force-pushed the add-session-option-for-query-plan-cache branch from 77afafc to 3be2507 Compare September 26, 2017 23:51
Copy link
Member

@demmer demmer left a comment

Choose a reason for hiding this comment

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

Looks great to me!
@sougou ?

@sougou
Copy link
Contributor

sougou commented Sep 30, 2017

Change looks good. Can you rebase against the latest master first and make sure all the tests pass? I worry that the latest dedup improvements may affect some tests.

@rafael rafael force-pushed the add-session-option-for-query-plan-cache branch from 1ae1d62 to 7d5e2a7 Compare September 30, 2017 23:44
@rafael rafael force-pushed the add-session-option-for-query-plan-cache branch from 7d5e2a7 to fdf7ec3 Compare September 30, 2017 23:45
@rafael rafael force-pushed the add-session-option-for-query-plan-cache branch from fdf7ec3 to d37ad9b Compare September 30, 2017 23:46
@vitessio vitessio deleted a comment from googlebot Sep 30, 2017
@rafael
Copy link
Member Author

rafael commented Sep 30, 2017

I had a bad rebase and I think @googlebot got confused. It should be good now :)

@sougou sougou merged commit bb636e8 into vitessio:master Oct 1, 2017
@ajm188 ajm188 deleted the add-session-option-for-query-plan-cache branch January 14, 2021 16:57
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.

4 participants