This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WITH RECURSIVE search_graph(id, parent, name, depth) AS ( | |
SELECT v.id AS id, v.name AS name, e.vertex_1 AS parent, 1 AS depth | |
FROM vertices AS v | |
LEFT JOIN edges AS e ON e.vertex_0 = v.id AND e.edge_type_id = 0 | |
UNION | |
SELECT v.id AS id, v.name AS name, e.vertex_1 AS parent, sg.depth + 1 AS depth | |
FROM vertices v, search_graph sg | |
LEFT JOIN edges AS e ON e.vertex_0 = v.id AND e.edge_type_id = 0 | |
WHERE sg.parent = v.id | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
QUERY PLAN | |
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
Sort (cost=2889817.55..2895073.57 rows=2102405 width=68) (actual time=345.103..360.131 rows=78331 loops=1) | |
Sort Key: search_graph.depth | |
Sort Method: external merge Disk: 4224kB | |
CTE search_graph | |
-> Recursive Union (cost=13075.32..2162313.09 rows=2102405 width=56) (actual time=59.622..257.259 rows=78331 loops=1) | |
-> Merge Right Join (cost=13075.32..18806.76 rows=61235 width=52) (actual time=59.619..97.254 rows=61235 loops=1) | |
Merge Cond: (e.vertex_0 = v.id) | |
-> Index Scan using edges_vertex_0_type_idx on edges e (cost=0.00..3669.65 rows=17128 width=32) (actual time=0.710..10.818 rows=17096 loops=1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1> A = []. | |
[] | |
2> lists:keystore(<<"test">>, 1, A, {<<"test">>, 1}). | |
[{<<"test">>,1}] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
drake=# explain analyze select id from vertices where name_fts @@ plainto_tsquery('school'::text); | |
QUERY PLAN | |
----------------------------------------------------------------------------------------------------------------------------------------- | |
Bitmap Heap Scan on vertices (cost=37.50..4536.36 rows=2258 width=16) (actual time=1.630..4.424 rows=2307 loops=1) | |
Recheck Cond: (name_fts @@ plainto_tsquery('school'::text)) | |
-> Bitmap Index Scan on vertices_name_fts_gin_idx (cost=0.00..36.94 rows=2258 width=0) (actual time=1.255..1.255 rows=2307 loops=1) | |
Index Cond: (name_fts @@ plainto_tsquery('school'::text)) | |
Total runtime: 4.803 ms | |
(5 rows) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
QUERY PLAN | |
----------------------------------------------------------------------------------------------------------------------------------------------------- | |
Limit (cost=4633.95..4634.20 rows=100 width=51) (actual time=13.523..13.535 rows=100 loops=1) | |
-> Sort (cost=4633.95..4639.60 rows=2258 width=51) (actual time=13.518..13.522 rows=100 loops=1) | |
Sort Key: (ts_rank(name_fts, plainto_tsquery('school'::text))) | |
Sort Method: top-N heapsort Memory: 32kB | |
-> Bitmap Heap Scan on vertices (cost=37.50..4547.65 rows=2258 width=51) (actual time=2.052..12.442 rows=2307 loops=1) | |
Recheck Cond: (name_fts @@ plainto_tsquery('school'::text)) | |
-> Bitmap Index Scan on vertices_name_fts_gin_idx (cost=0.00..36.94 rows=2258 width=0) (actual time=1.621..1.621 rows=2307 loops=1) | |
Index Cond: (name_fts @@ pla |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
QUERY PLAN | |
------------------------------------------------------------------------------------------------------------------------------------------------------------------ | |
Limit (cost=6391.54..6391.79 rows=100 width=109) (actual time=29.755..29.768 rows=100 loops=1) | |
-> Sort (cost=6391.54..6402.75 rows=4484 width=109) (actual time=29.754..29.759 rows=100 loops=1) | |
Sort Key: ((ts_rank(name_fts, plainto_tsquery('school'::text)) + ts_rank(description_fts, plainto_tsquery('school'::text)))) | |
Sort Method: top-N heapsort Memory: 32kB | |
-> Bitmap Heap Scan on vertices (cost=76.15..6220.17 rows=4484 width=109) (actual time=3.497..28.446 rows=3824 loops=1) | |
Recheck Cond: ((name_fts @@ plainto_tsquery('school'::text)) OR (description_fts @@ plainto_tsquery('school'::text))) | |
-> BitmapOr (cost=76.15..76.15 r |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
drake=# explain analyze select id from vertices where name_fts @@ plainto_tsquery('school') or description_fts @@ plainto_tsquery('school'); QUERY PLAN | |
------------------------------------------------------------------------------------------------------------------------------------------------------ | |
Bitmap Heap Scan on vertices (cost=76.15..6164.12 rows=4484 width=16) (actual time=3.357..7.751 rows=3824 loops=1) | |
Recheck Cond: ((name_fts @@ plainto_tsquery('school'::text)) OR (description_fts @@ plainto_tsquery('school'::text))) | |
-> BitmapOr (cost=76.15..76.15 rows=4521 width=0) (actual time=2.750..2.750 rows=0 loops=1) | |
-> Bitmap Index Scan on vertices_name_fts_gin_idx (cost=0.00..36.94 rows=2258 width=0) (actual time=1.430..1.430 rows=2307 loops=1) | |
Index Cond: (name_fts @@ plainto_tsquery('school'::text)) | |
-> Bitmap Index Scan |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
drake=# explain analyze select id from vertices where name_fts @@ plainto_tsquery('school') or description_fts @@ plainto_tsquery('school') limit 100; | |
QUERY PLAN | |
------------------------------------------------------------------------------------------------------------------------- | |
Limit (cost=0.00..201.42 rows=100 width=16) (actual time=53.723..356.704 rows=100 loops=1) | |
-> Seq Scan on vertices (cost=0.00..9031.60 rows=4484 width=16) (actual time=53.721..356.685 rows=100 loops=1) | |
Filter: ((name_fts @@ plainto_tsquery('school'::text)) OR (description_fts @@ plainto_tsquery('school'::text))) | |
Rows Removed by Filter: 93311 | |
Total runtime: 356.751 ms | |
(5 rows) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
QUERY PLAN | |
------------------------------------------------------------------------------------------------------------------------------------------------------------ | |
Limit (cost=76.15..211.92 rows=100 width=16) (actual time=3.487..3.673 rows=100 loops=1) | |
-> Bitmap Heap Scan on vertices (cost=76.15..6164.12 rows=4484 width=16) (actual time=3.485..3.641 rows=100 loops=1) | |
Recheck Cond: ((name_fts @@ plainto_tsquery('school'::text)) OR (description_fts @@ plainto_tsquery('school'::text))) | |
-> BitmapOr (cost=76.15..76.15 rows=4521 width=0) (actual time=2.886..2.886 rows=0 loops=1) | |
-> Bitmap Index Scan on vertices_name_fts_gin_idx (cost=0.00..36.94 rows=2258 width=0) (actual time=1.461..1.461 rows=2307 loops=1) | |
Index Cond: (name_fts @@ plainto_tsquery('school'::text)) | |
-> Bitmap Index Scan on |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
log_attrs(Type, ActionAttrs) -> | |
case ActionAttrs of | |
[] -> | |
lager:debug("empty"); | |
[_] -> | |
lager:debug("one"); | |
[_, _] -> | |
lager:debug("two") | |
end. |