-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(perf): rewrite query for performance
- Loading branch information
1 parent
7fa36b1
commit 495b74f
Showing
3 changed files
with
29 additions
and
51 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,27 @@ | ||
SELECT t1.id AS subjectId, t2.id as objectId | ||
FROM rtree AS r1, rtree AS r2 | ||
JOIN tokens AS t1 ON t1.id = r1.id | ||
JOIN tokens AS t2 ON t2.id = r2.id | ||
WHERE t1.token = $subject | ||
AND t2.token = $object | ||
AND ( | ||
t1.lang = t2.lang OR | ||
t1.lang IN ( 'eng', 'und' ) OR | ||
t2.lang IN ( 'eng', 'und' ) | ||
) | ||
-- https://silentmatt.com/rectangle-intersection/ | ||
AND ( | ||
r1.maxZ < r2.minZ AND | ||
r1.minX - $threshold < r2.maxX AND | ||
r1.maxX + $threshold > r2.minX AND | ||
r1.minY - $threshold < r2.maxY AND | ||
r1.maxY + $threshold > r2.minY | ||
) | ||
-- AND t1.tag NOT IN ( 'colloquial' ) | ||
-- AND t2.tag NOT IN ( 'colloquial' ) | ||
SELECT | ||
t1.id AS subjectId, | ||
t2.id as objectId | ||
FROM fulltext f1 | ||
JOIN tokens t1 ON f1.rowid = t1.rowid | ||
JOIN rtree AS r1 ON t1.id = r1.id | ||
JOIN rtree AS r2 ON ( | ||
r1.maxZ < r2.minZ AND | ||
(r1.minX - $threshold) < r2.maxX AND | ||
(r1.maxX + $threshold) > r2.minX AND | ||
(r1.minY - $threshold) < r2.maxY AND | ||
(r1.maxY + $threshold) > r2.minY | ||
) | ||
JOIN fulltext AS f2 ON f2.fulltext MATCH $object | ||
JOIN tokens t2 ON ( | ||
f2.rowid = t2.rowid | ||
AND r2.id = t2.id | ||
AND ( | ||
t1.lang = t2.lang OR | ||
t1.lang IN ('eng', 'und') OR | ||
t2.lang IN ('eng', 'und') | ||
) | ||
) | ||
WHERE f1.fulltext MATCH $subject | ||
GROUP BY t1.id, t2.id | ||
ORDER BY t1.id ASC, t2.id ASC | ||
LIMIT $limit | ||
LIMIT $limit |
25 changes: 0 additions & 25 deletions
25
query/match_subject_object_geom_intersects_autocomplete.sql
This file was deleted.
Oops, something went wrong.