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

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -