mysql - jQuery AutoComplete - Query Database with JOIN -
i'm implementing jquery autocomplete library on textbox. sql query have in end uses join:
select distinct wcc.itemcode, gwbo.itemname tbl1 gwbo inner join tbl2 wcc on gwbo.itemcode = wcc.itemcode wcc.itemcode '$term%' or gwbo.itemname '%$term%' , wcc.countstatus != 2 order wcc.itemcode limit 0, 10
this takes 25 seconds autocomplete box populate , display.. however, when remove join , query 1 table, autocomplete displays (of course data isn't accurate). why join slowing down drastically? need join.. there way speed missing, or need entirely new implementation?
run explain
in mysql see why join
taking long, , indexes can set make faster.
explain select distinct wcc.itemcode, gwbo.itemname tbl1 gwbo inner join tbl2 wcc on gwbo.itemcode = wcc.itemcode wcc.itemcode '$term%' or gwbo.itemname '%$term%' , wcc.countstatus != 2 order wcc.itemcode limit 0, 10
it seems setting index on itemcode
speed query. recommend adding it, , running explain
again see if db using newly created index.
also, like
conditions tend slow since no matter index set on column, db has full-table scan. see if can change somehow. can ==
instead of like
?
Comments
Post a Comment