sql - Search in huge table -
i got table on 1 millions rows. table represents user information, e.g username, email, gender, marrial status etc.
i'm going write search on rows in table, when conditions applied.
in simples case, when search perfomed on username, takes on 4-7 seconds find result.
select u u.name ilike " ... "
yes, got indexes on fileds. checked applied using explain analyse command.
how search can boost ?
i heart lucene, can ?
i'm wondering how facebook search working, got billions users , search works faster.
there great difference between these 3 queries:
a) select * u u.name "george%" b) select * u u.name "%george" c) select * u u.name "%george%"
a) first use index on u.name (if there one) , fast.
b) second not able use index on u.name there ways circumvent rather easily.
for example, add field namereversed
in table reverse(name)
stored. index on field, query rewritten (and fast first one):
b2) select * u u.namereversed reverse("%george")
c) third query poses greatest difficulty neither of 2 previous indexes of , query scan whole table. alternatives are:
using dedicated such problems solution (search "full text search"), sphinx. see question on more details: which-is-best-search-technique-to-search-records
if field has names (or limited set of words, few hundred different words), create auxilary table names (words) , store foreign key in table u
.
if off course not case , have tens of thousands or millions different words or field contains whole phrases, solve problem many auxilary tables, it's creating full text search tool yourself. it's nice exercise , won't have use sphinx (or other) besides rdbms it's not trivial.
Comments
Post a Comment