MySQL in and limit cannot be a problem

Source: Internet
Author: User
Tags mysql in

Today in MySQL processing a data volume to reach Tens database table, to take out the data set to meet the conditions, and then deposit to the MONGO database, using JPA provided pageble to get the paging, and then use multithreading to fetch data, found that the first efficiency can be, certainly more than the single-line Chengqiang a lot, But this pageable has a problem, when the SQL statement is generated, will automatically add a limit *,10000, such a restriction, "*" represents the row from which to start fetching data, 10000 for this operation to take 10,000 data. This kind of operation will seriously occupy the server's cache, if you do this kind of operation, other people also in the visit, will cause everybody together to get a ratio.

The workaround is to use a concurrent queue to store the ID of the last piece of data for each page, but I have a problem:

This version of MySQL doesn ' t yet support ' LIMIT & in/all/any/some subquery

Limit cannot be directly hyphenated with in-scope keywords, bad SQL, and improved SQL.

Error sqlselect max (ID) from News_info where ID in (select ID from News_info where pub_date>?1 and id>?2 order By ID limit 10000)//correct sqlselect max (ID) from News_info where ID in (select ID from news_info where pub_da Te>?1 and id>?2 order by ID limit 10000) as news)

Since you can't do it directly, create a temporary table in the middle.

MySQL in and limit cannot be a problem

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.