sql - How to replace IN clause when using huge list of included items/ids? -


i have sql looks this:

select some_column some_table some_column in (v1, v2, v3, v4, ..., v100, v101, ... v1000, v1001, ... ); 

in clause contains lot of items/ids 1000 or more. i'm not sql expert, there way solve problem because performance low query? replacement in clause?

to more precisely, values came method:

public void slowquery() {     list<integer> ids = getids();     string querystring = "select some_column some_table some_column in :ids";     query query = getsession().createquery(querystring);     query.setparameter(ids, "ids");     .... }  public list<integer> getids() {     list<integer> ids = new arraylist<integer>();     // run 4 queries data , put them ids array      return ids; } 

there 2 ways deal this, depending on ids come in first place.

if ids come external system or convoluted process, insert them temporary table. modify query include:

where id in (select id temp) 

if ids come select out of same database, avoid bringing them on network client software have them sent again:-

where id in ( select ...however find them now... ) 

in both of above causes may prefer use inner join in list. easier me explain in clause because more closely matches have now.


Comments

Popular posts from this blog

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -

java - How to specify maven bin in eclipse maven plugin? -