Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. select *
  2. from description
  3. where
  4. term ilike %% 'query'
  5. order by
  6. term ilike 'query' -- prefer exact match
  7. term ilike 'query' -- prefer starts with
  8. -- term %% 'query' -- fill with fuzzy trigram match
  9. limit 10
  10.  
  11. -- select * FROM (
  12.  
  13. select * -- 100 ms when run alone
  14. FROM description d
  15. where term ilike 'hyp'
  16. UNION
  17. select * from ( -- 100 ms when run alone, returns 1000 rows if no limit
  18. select *
  19. FROM snomed_ct.description d
  20. where d.term ilike 'hyp%'
  21. ) as x
  22. UNION
  23. select * -- 200ms seconds when run alone (with limit 10)
  24. FROM description d
  25. where d.term % 'hyp'
  26. -- ) as d
  27. limit 10
  28.  
  29. select *
  30. FROM description d
  31. where d.term % 'hyp'
  32.  
  33. selects = [select1_iterator, select2_iterator, select3_iterator, ]
  34. iter = chain(selects) # pick from 1st iterator, then second, then 3rd
  35. iter = duplicated(selects) # skip duplicates
  36. iter = limit(selects, 10) # pick 1st 10
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement