[openstreetmap/openstreetmap-website] Preload element tags when showing changesets (PR #4569)
Anton Khorev
notifications at github.com
Sat Mar 9 15:24:01 UTC 2024
Although I'm not sure if rails' `.includes` works correctly with composite keys.
```
irb(main):020> OldNode.where("changeset_id = 81").includes(:old_tags).explain
OldNode Load (0.7ms) SELECT "nodes".* FROM "nodes" WHERE (changeset_id = 81)
OldNodeTag Load (0.6ms) SELECT "node_tags".* FROM "node_tags" WHERE "node_tags"."node_id" IN ($1, $2, $3) AND "node_tags"."version" IN ($4, $5, $6) [["node_id", 1314], ["node_id", 1312], ["node_id", 1313], ["version", 1], ["version", 3], ["version", 2]]
=>
EXPLAIN SELECT "nodes".* FROM "nodes" WHERE (changeset_id = 81)
QUERY PLAN
-------------------------------------------------------------------------------------
Index Scan using nodes_changeset_id_idx on nodes (cost=0.28..8.29 rows=1 width=53)
Index Cond: (changeset_id = 81)
(2 rows)
EXPLAIN SELECT "node_tags".* FROM "node_tags" WHERE "node_tags"."node_id" IN ($1, $2, $3) AND "node_tags"."version" IN ($4, $5, $6) [["node_id", 1314], ["node_id", 1312], ["node_id", 1313], ["version", 1], ["version", 3], ["version", 2]]
QUERY PLAN
------------------------------------------------------------------------------
Bitmap Heap Scan on node_tags (cost=12.86..19.98 rows=3 width=29)
Recheck Cond: (node_id = ANY ('{1314,1312,1313}'::bigint[]))
Filter: (version = ANY ('{1,3,2}'::bigint[]))
-> Bitmap Index Scan on node_tags_pkey (cost=0.00..12.86 rows=3 width=0)
Index Cond: (node_id = ANY ('{1314,1312,1313}'::bigint[]))
(5 rows)
```
Conditions like `WHERE "node_tags"."node_id" IN ($1, $2, $3) AND "node_tags"."version" IN ($4, $5, $6)` select unnecessary tag versions.
--
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/pull/4569#issuecomment-1986884796
You are receiving this because you are subscribed to this thread.
Message ID: <openstreetmap/openstreetmap-website/pull/4569/c1986884796 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20240309/298ef3a4/attachment.htm>
More information about the rails-dev
mailing list