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

[D1] Adding PRAGMA optimize for D1 #19996

Open
wants to merge 8 commits into
base: production
Choose a base branch
from
Open

Conversation

Oxyjun
Copy link
Contributor

@Oxyjun Oxyjun commented Feb 14, 2025

Summary

Screenshots (optional)

Documentation checklist

  • The documentation style guide has been adhered to.
  • If a larger change - such as adding a new page- an issue has been opened in relation to any incorrect or out of date information that this PR fixes.
  • Files which have changed name or location have been allocated redirects.

@Oxyjun Oxyjun self-assigned this Feb 14, 2025
@Oxyjun Oxyjun requested review from elithrar, vy-ton and a team as code owners February 14, 2025 15:28
@Oxyjun Oxyjun marked this pull request as draft February 14, 2025 15:29
@github-actions github-actions bot added the product:d1 D1: https://developers.cloudflare.com/d1/ label Feb 14, 2025
@Oxyjun Oxyjun marked this pull request as ready for review February 17, 2025 16:35
@github-actions github-actions bot added size/s and removed size/xs labels Feb 17, 2025
src/content/docs/d1/best-practices/use-indexes.mdx Outdated Show resolved Hide resolved

### `PRAGMA optimize`

Attempts to optimize all schemas in a database by running various maintenance operations.
Copy link
Contributor

Choose a reason for hiding this comment

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

Need to connect optimize all schemas with query optimization

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can I check which section you're referring to here?

src/content/partials/d1/use-pragma-statements.mdx Outdated Show resolved Hide resolved

Attempts to [optimize all schemas]() in a database by running various maintenance operations. We recommend running this command after [creating an index](/d1/best-practices/use-indexes/).

Alternatively, to see all optimizations that would have been performed without actually executing them, run `PRAGMA optimize(-1)`.
Copy link
Contributor

Choose a reason for hiding this comment

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

The way D1 implements PRAGMA optimize, debug mode won't work since we constrain PRAGMA optimize to not return any rows.

As far as I can tell from reading the source code, debug mode returns a list of ANALYZE schema_name.table_name statements that PRAGMA optimize would have otherwise run.

@vy-ton I guess we should get debug mode to work, shouldn't we? Sorry for missing that detail. It's not documented at all! I had to read the source to figure it out.

src/content/docs/d1/best-practices/use-indexes.mdx Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
product:d1 D1: https://developers.cloudflare.com/d1/ size/s
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants