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

sql: set max statement time on a per query basis #52240

Closed
awoods187 opened this issue Aug 3, 2020 · 7 comments
Closed

sql: set max statement time on a per query basis #52240

awoods187 opened this issue Aug 3, 2020 · 7 comments
Labels
A-sql-ui Why is my query slow? C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) no-issue-activity X-stale

Comments

@awoods187
Copy link
Contributor

awoods187 commented Aug 3, 2020

We now have a statement_timeout and a idle_in_session_timeout (introduced in 20.2). In #5924 we plan to add a idle_in_transaction_session_timeout. We should also add a per-query timeout (instead of a session variable/cluster setting). This is analogous to an INDEX or JOIN hint in that we are instructing specific behavior for an individual query.

In MariaDB, they offer this via max_statement_time

SET STATEMENT max_statement_time=100 FOR 
  SELECT field1 FROM table_name ORDER BY field1;

I couldn't find an example in Postgres (I believe it only allows for the connection or session settings).

Jira issue: CRDB-3972

@awoods187 awoods187 added the C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) label Aug 3, 2020
@awoods187 awoods187 added the A-sql-ui Why is my query slow? label Aug 3, 2020
@jordanlewis
Copy link
Member

Thumbs down for making this a priority, if only because no existing Postgres driver will have built-in support for this syntax.

@awoods187
Copy link
Contributor Author

I understand that some drivers make this an option, for example in JDBC:

Statement stmt = connection.prepareStatement("SELECT * FROM BOOKS");
stmt.setQueryTimeout(10);//Timeout of 10 seconds

But others do not (I believe the Python PG driver only offers it on a connection basis). I think this may end up a critical piece of last-resort intervention analogous to JOIN HINTS and therefore that it still merits further consideration.

@vy-ton
Copy link
Contributor

vy-ton commented Aug 4, 2020

@rafiss fyi

@rafiss
Copy link
Collaborator

rafiss commented Aug 4, 2020

The PGJDBC setQueryTimeout method actually is just a client-side timeout. It starts a timer in the client, and after the time is elapsed, it issues a pgwire Cancel message (see #41335).

@jordanlewis
Copy link
Member

Okay, so are we good to close this?

@awoods187
Copy link
Contributor Author

No, I don't think so. We don't have this option available in all drivers.

@github-actions
Copy link

We have marked this issue as stale because it has been inactive for
18 months. If this issue is still relevant, removing the stale label
or adding a comment will keep it active. Otherwise, we'll close it in
10 days to keep the issue queue tidy. Thank you for your contribution
to CockroachDB!

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Sep 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-sql-ui Why is my query slow? C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) no-issue-activity X-stale
Projects
None yet
Development

No branches or pull requests

4 participants