Skip to content

Commit

Permalink
feat(query): rewrite queries for performance (#219)
Browse files Browse the repository at this point in the history
  • Loading branch information
missinglink committed Dec 13, 2021
1 parent 92c175d commit 82db3cd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 5 additions & 3 deletions query/match_subject_object_geom_intersects.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ SELECT
t1.id AS subjectId,
t2.id as objectId
FROM fulltext f1
JOIN tokens t1 ON f1.rowid = t1.rowid
JOIN tokens t1 ON (
f1.rowid = t1.rowid
AND f1.fulltext MATCH $subject_quoted
AND LIKELY(t1.token = $subject)
)
JOIN rtree AS r1 ON t1.id = r1.id
JOIN rtree AS r2 ON (
r1.maxZ < r2.minZ AND
Expand All @@ -22,8 +26,6 @@ FROM fulltext f1
t2.lang IN ('eng', 'und')
)
)
WHERE f1.fulltext MATCH $subject_quoted
AND LIKELY(t1.token = $subject)
GROUP BY t1.id, t2.id
ORDER BY t1.id ASC, t2.id ASC
LIMIT $limit
8 changes: 5 additions & 3 deletions query/match_subject_object_geom_intersects_autocomplete.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ SELECT
t1.id AS subjectId,
t2.id as objectId
FROM fulltext f1
JOIN tokens t1 ON f1.rowid = t1.rowid
JOIN tokens t1 ON (
f1.rowid = t1.rowid
AND f1.fulltext MATCH $subject_quoted
AND LIKELY(t1.token = $subject)
)
JOIN rtree AS r1 ON t1.id = r1.id
JOIN rtree AS r2 ON (
r1.maxZ < r2.minZ AND
Expand All @@ -22,8 +26,6 @@ FROM fulltext f1
t2.lang IN ('eng', 'und')
)
)
WHERE f1.fulltext MATCH $subject_quoted
AND LIKELY(t1.token = $subject)
GROUP BY t1.id, t2.id
ORDER BY t1.id ASC, t2.id ASC
LIMIT $limit

0 comments on commit 82db3cd

Please sign in to comment.