Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Omnisharded tables
We now treat all tables as omnisharded unless they are configured in
pgdog.toml. This makes configuration a lot easier. To make this work we load the Postgres schema from system catalogs on boot and inspect it for tables that match the config for each query. This is quick, since the tables (and their columns) are organized in a HashMap.Schema inference
We now load schema from Postgres on boot and inspect it for sharding keys. To make this work, Postgres needs to be available when PgDog is started.
Migrations
When adding/changing sharded tables, make sure to run
RELOAD(orRECONNECT) to reload the schema, otherwise aSELECTagainst the new table will default to omni, not sharded, for queries that don't provide the sharding key.Unique ID generation
Added
pgdog.unique_id()to Postgres itself (viasetupCLI command), so it's now possible to add it as a default to a table, e.g.:How this works:
pgdog.tomlpgdog setupto create the function and its dependencies. This will create a schema calledpgdogon all shards and the pl/PgSQL functions will be added to it.Warning
Don't use the Postgres unique ID function to generate sharding keys! They won't match the shard they are generated on. Make sure to call it explicitly in the query so PgDog executes it instead.