Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6703777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:12:41+00:00 2026-05-26T07:12:41+00:00

I have a java application and I would like to get some data from

  • 0

I have a java application and I would like to get some data from a table and display in the application.

I have millions of records, and the query gets really slow when I am going to the last records. it takes few good minutes to get the results.

select Id from Table1x where description like '%error%' and Id between 0 and 1329999 limit 0, 1000

The above query returns a fast result. That is first pages returns fast. But when I am moving the last pages, it becomes slow.

select Id from Table1x where description like '%error%' and Id between 0 and 1329999 limit 644000, 1000. 

This query is slow and taking 17 secs.

Any ideas on how to make this faster? Id is the primary key of table1x.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T07:12:42+00:00Added an answer on May 26, 2026 at 7:12 am

    The problem is in the like. To get the first 1000 records, the database only needs to filter the database until it finds 1000 records that match the search. For the other query, the database needs to match records until it has 645000 records, which makes it much slower. There is no sorting or other filtering, so the index on ID doesn’t help at all.

    An index on description would help, but not if you start the search with a wildcard, like you do now.

    I see two solutions.

    First option is to add a FULLTEXT index on the description field. It allows to to look for the word error using MATCH rather than LIKE. I think it will be a lot faster, but the index will become larger too, and I’m not sure about the optimizations on the long run.

    Second solution: Since you’re obviously looking for errors (I think you’re building a report on a log table?), you may add a column with a record type. You can give each record a type (just an integer) which indicates where that record holds an error or not. You will need to update your table once, and insert the type along with new records, but it will make your query faster.

    I must admit that this second solution is based on assumptions about the data and your goal. If I’m wrong about that, please provide additional information and I may find a solution that suits you better.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have built a Java application that has some dependencies (~10). I would like
I have a Java application and I would like to make it extensible. To
I am developing a Java desktop application and would like to have an external
I have a few JAVA application that I monitor using JMX. I would like
I have an application where I would like to have mixed Java and Scala
I would like to create extend a Java Swing application to have a look
I have made a small application in Java and I would like to make
I have an application hosted in Java on AppEngine and I would like to
I have a web-application written in java. I would like to run integration tests
I have a Java application and I would like to find out the location

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.