-
-
Notifications
You must be signed in to change notification settings - Fork 118
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
Improve DB Indexes and Fix Deferred Index Logging in Compact DB Mode #245
Conversation
Use "primary key without rowid" instead of "unique" on tiles_shallow (compact mode). This behind the scenes switches from a non-clustered to a clustered index. And this further reduces the DB and also improves read and write performance. Log the correct statement to manually create the index in compact DB mode. Move the automatic index creation into Mbtiles#createTables.
https://github.com/onthegomap/planetiler/actions/runs/2423265831 ℹ️ Base Logs f93e522
ℹ️ This Branch Logs 26aa9ca
|
It seems like the code evolved over time from deferring i.e adding the index after the inserts to skipping adding the index entirely and just logging the DDL statement to create the index.
if (!config.deferIndexCreation()) { | ||
mbtiles.addTileIndex(); | ||
} | ||
mbtiles.createTables(config.skipIndexCreation()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One other thing I noticed in the mbtiles write benchmark is that it iterates through tile coordinates like this:
for (int z = 0; z <= 14; z++) {
int maxCoord = 1 << z;
for (int x = 0; x < maxCoord; x++) {
for (int y = 0; y < maxCoord; y++) {
but the tile index order actually inverts Y - could you change the inner one to be:
for (int y = maxCoord - 1; y > 0; y--) {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch!
(assuming you meant for (int y = maxCoord - 1; y >= 0; y--) {
)
* manually | ||
* @return {@code this} | ||
*/ | ||
public Mbtiles createTables(boolean skipIndexCreation) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's a little hard to follow what the callers want with the true/false flag... could we make add a createTablesWithoutIndex
so it's a bit more clear?
TILES_COL_Y + ", " + TILES_COL_DATA + " blob);"); | ||
// here "unique" is much more compact than a "primary key without rowid" because the tile data is part of the table | ||
String tilesUniqueAddition = skipIndexCreation ? "" : """ | ||
, unique(%s,%s,%s) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a difference between unique
and primary key
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
afaik no - other than the usual stuff that you can have only one PK and cannot insert NULL
=> let me change this to primary key since it expresses its purpose better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good! A few minor comments...
Kudos, SonarCloud Quality Gate passed! |
Looks good, thanks for implementing this! I'll get some performance and DB size tests on the planet along with the other performance improvements before putting out the next release. |
--defer-mbtiles-index-creation
does not apply to--compact-db
#243Here are some results on experimenting with PK with and without rowid, and unique on tiles and tiles_shallow