Skip to content

Add extended stats and force of custom query plans - #1543

Open
nmaytan wants to merge 4 commits into
bluesky:mainfrom
nmaytan:mig_adjustment
Open

nmaytan wants to merge 4 commits into
bluesky:mainfrom
nmaytan:mig_adjustment

Conversation

@nmaytan

@nmaytan nmaytan commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

This adjustment brings the migration in harmony to what we deployed in prod. This is currently the intended configuration for all deployments. We also in this PR make GraphQL queries use literal tag IDs, matching catalog queries. Finally, a new migration script is added which renames the grants table to something less verbose.

Note on forcing custom plans:

  • We cannot set force_custom_plan during migration because for this to be set for tiled role that role must exist, which is not defined/guaranteed by the ORM (CI doesn't use this role, for example)
    • For the same reasons, we also don't want to set this via event listener in the ORM either
  • We don't want to just set it for <current user> either, because that may have unintended effects (e.g. if someone is using postgres user for Tiled connections, it will force custom plans everywhere in the postgres instance instead of just for Tiled)
  • Current version of PR instead uses the per-connection version of this setting and hooks into database connection setup.

Other notes:

  • Migration script now adds extended stats and performs a vacuum-analyze to cleanup after the potentially large table change
  • Added event listener to add extended stats during setup in the ORM as well
  • Renamed the stats to a less terse name (long but still under the 63 byte postgres limit)

Checklist

  • Add a Changelog entry
  • Add the ticket number which this PR closes to the comment section

@nmaytan nmaytan changed the title Add extended stats and force of custom plans to migration Add extended stats and force of custom query plans Oct 1, 2026
@nmaytan
nmaytan requested a review from genematx October 1, 2026 21:40

@danielballan danielballan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks good to go save for my naming nit-pick.

Comment thread tiled/catalog/orm.py
connection.execute(
text(
"""
CREATE STATISTICS IF NOT EXISTS node_access_tags_association_parent_id_tag_id_node_id_stats

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Revisiting this after a couple days, I'm feeling strongly we should just name this grants or access_grants (pick your preference). If the meaning/content is unclear, that's what schema introspection is more; we don't need the column names in the table name.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I was going to do this in separate PR, but it can be done here. This is also a database migration to go with this, of course.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have a commit incoming for this. However, I note that calling this access_grants breaks our convention of appending "association" to all association tables.

@nmaytan nmaytan Oct 9, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Also, the stats highlighted by this thread are not on the grants table - they are on the node-tag associations table, so the name of this doesn't change. I've left it with the existing name.

This branch has not been deployed

No deployments
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.

2 participants