Resolves an issue in which SQL queries are slow because the list is too long

Source: Internet
Author: User

/**
* Solve the problem that SQL query is slow because the chain list is too long
* Using the divide-and-conquer algorithm, first slice the linked list, then query the results, and finally merge the results
*
* @author Lingpy
* @since 1.0
*/
public class Divideandconquerutil {
/**
*
* @param dataList Meta data
* @param exceuter Execution class
* @return
* @throws Exception
*/
public static <r extends Map, e> R query (list<e> datalist,executer<r,e> exceuter) throws exception{
return query (DATALIST,EXCEUTER,100);

}

/**
*
* @param dataList
* @param exceuter
* @param grain size of subarraylength
* @return
* @throws Exception
*/
@SuppressWarnings ("Unchecked")
public static <r extends Map, e> R query (list<e> datalist,executer<r,e> exceuter,int subarraylength) Throws exception{
if (dataList = = NULL | | datalist.size () <= subarraylength) {
Return Exceuter.execute (dataList);
}
R result = null;
int start = 0, end = start;
while (Start < Datalist.size ()) {
End = start + subarraylength;
if (End > Datalist.size ()) {
End = Datalist.size ();
}
R r = Exceuter.execute (Datalist.sublist (Start, end));
if (result = = null) {
result = R;
}else{
Result.putall (R);
}
start = end;
}
return result;
}

public interface executer<r,e>{
R Execute (list<e> dataList) throws Exception;
}
}

Resolves an issue in which SQL queries are slow because the list is too long

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.