Commit 5c4dcc1
committed
Use tags = NULL in middle tables if object doesn't have any tags
This doesn't make much of a difference for the ways and rels table, but
if we store all nodes in the database, it does make a huge difference,
because most nodes don't have any tags. For a current planet, disk usage
for the nodes table goes from 476 GB down to 409 GB saving 67 GB or
nearly 15%.
Additionally it makes use of that table simpler. If you want to do any
queries on tags, you need an index on the tags column on the
nodes/ways/rels tables like this:
CREATE INDEX ON planet_osm_ways USING gin (tags);
But that is wasteful, because of the empty tags. We probably want to
generate them as
CREATE INDEX ON planet_osm_ways USING gin (tags) WHERE tags != '{}'::jsonb;
But now all queries on those tables have to include that extra condition
so that the query planner will use the index.
SELECT * FROM planet_osm_ways WHERE tags ? 'highway' AND tags != '{}'::jsonb;
If we use NULLs, the index can be created as:
CREATE INDEX ON planet_osm_ways USING gin (tags) WHERE tags IS NOT NULL;
And now the query becomes simpler, because the NOT NULL is automatically
taken into account by the query planner:
SELECT * FROM planet_osm_ways WHERE tags ? 'highway';
Note that this is an incompatible change to the new format middle
tables, but they are still marked as experimental, so we can do this.1 parent 6ceb4f9 commit 5c4dcc1
1 file changed
+11
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
323 | 323 | | |
324 | 324 | | |
325 | 325 | | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
326 | 330 | | |
327 | 331 | | |
328 | 332 | | |
| |||
613 | 617 | | |
614 | 618 | | |
615 | 619 | | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
616 | 624 | | |
617 | 625 | | |
618 | 626 | | |
| |||
1464 | 1472 | | |
1465 | 1473 | | |
1466 | 1474 | | |
1467 | | - | |
| 1475 | + | |
1468 | 1476 | | |
1469 | 1477 | | |
1470 | 1478 | | |
| |||
1530 | 1538 | | |
1531 | 1539 | | |
1532 | 1540 | | |
1533 | | - | |
| 1541 | + | |
1534 | 1542 | | |
1535 | 1543 | | |
1536 | 1544 | | |
| |||
1601 | 1609 | | |
1602 | 1610 | | |
1603 | 1611 | | |
1604 | | - | |
| 1612 | + | |
1605 | 1613 | | |
1606 | 1614 | | |
1607 | 1615 | | |
| |||
0 commit comments