-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Description
https://github.com/iandees/xapi-servlet/blob/master/src/main/java/com/yellowbkpk/geo/xapi/db/Selector.java#L37 builds a query string using exist(tags, key)
but this does not use the GIN index set up in the documentation so ends up doing a sequential scan. A query with tags ? key
will use the index.
In this example the cost is 21 times greater for the exist()
query.
xapi=# EXPLAIN (FORMAT YAML) SELECT * FROM ways WHERE tags ? 'source_1';
QUERY PLAN
-------------------------------------------------
- Plan: +
Node Type: "Bitmap Heap Scan" +
Relation Name: "ways" +
Alias: "ways" +
Startup Cost: 4541.63 +
Total Cost: 551334.20 +
Plan Rows: 151436 +
Plan Width: 1167 +
Recheck Cond: "(tags ? 'source_1'::text)" +
Plans: +
- Node Type: "Bitmap Index Scan" +
Parent Relationship: "Outer" +
Index Name: "idx_ways_tags" +
Startup Cost: 0.00 +
Total Cost: 4503.77 +
Plan Rows: 151436 +
Plan Width: 0 +
Index Cond: "(tags ? 'source_1'::text)"
(1 row)
xapi=# EXPLAIN (FORMAT YAML) SELECT * FROM ways WHERE exist(tags,'source_1');
QUERY PLAN
---------------------------------------------
- Plan: +
Node Type: "Seq Scan" +
Relation Name: "ways" +
Alias: "ways" +
Startup Cost: 0.00 +
Total Cost: 11578309.22 +
Plan Rows: 50478774 +
Plan Width: 1167 +
Filter: "exist(tags, 'source_1'::text)"
(1 row)
Metadata
Metadata
Assignees
Labels
No labels