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

  • SEARCH
  • Home
  • 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 8964677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:38:34+00:00 2026-06-15T16:38:34+00:00

I have a MySQL database which is indexed by Solr. I carry out searches

  • 0

I have a MySQL database which is indexed by Solr. I carry out searches using Solr (fast), and I retrieve every result in the Solr search from the database using JPA. JPA runs a WHERE IN query on the database which is VERY slow.

Is there a way to make this process faster, or to refactor the design to improve performance?

I have just refactored the whole application from using MySQL’s fulltext search to use Solr, and now the performance is worse.

Note: I need all results immediately to carry out calculations on, and thus, I cannot use pagination.

Java code:

    SolrDocumentList documentList = response.getResults();
    Collection<String> listingIds = new ArrayList<>();
    for(SolrDocument doc : documentList) {
        String listingId = (String) doc.getFirstValue("ListingId");
        listingIds.add(listingId);
    }

    Query query = em.createNamedQuery("getAllListingsWithId");
    query.setParameter("listingIds", listingIds);
    List<ListedItemDetail> listings = query.getResultList();

Named Query:

<query>Select listing from ListingSet listing where listing.listingId in :listingIds</query>

Additional Information:

SHOW CREATE TABLE ListingSet produces [shortened]:

CREATE TABLE `listingset` (
  `LISTINGID` int(11) NOT NULL,
  `STARTDATE` datetime DEFAULT NULL,
  `STARTPRICE` decimal(10,2) DEFAULT NULL,
  `TITLE` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`LISTINGID`),
  KEY `FK_LISTINGSET_MEMBER_MEMBERID` (`MEMBER_MEMBERID`),
  CONSTRAINT `FK_LISTINGSET_MEMBER_MEMBERID` FOREIGN KEY (`MEMBER_MEMBERID`) REFERENCES `member` (`MEMBERID`),
) ENGINE=InnoDB DEFAULT CHARSET=latin1

Investigating the generated SQL

Looking at the generated SQL, JPA runs a lot of SQL queries for a single JPA query. The ListingSet table has 7 tables it is linked to, and runs a separate SELECT query for each table for EACH listingid (of which there are 1,000 – 10,000). So my one JPA query gets blown into what looks like ~7,000 queries!

  • 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-06-15T16:38:35+00:00Added an answer on June 15, 2026 at 4:38 pm

    The problem was caused by my use of JPA. Due to the many relationship my entity had, a single query exploded into 1,000-10,000 queries.

    The solution is to use Batch Processing in JPA to prevent the ORM n + 1 query problem. Batch processing causes JPA to request all relevant rows from related tables at once, rather than once for each entity. This solution is appropriate when a query returns many results, and the entity being queried has many relationships.

    The easiest way to determine potential issues with JPA is to enable finer logging. For EclipseLink, add a property to persistence.xml:

      <property name="eclipselink.logging.level" value="FINEST"/>
    

    Be wary that the logging produced under the default settings for EclipseLink only displays the JPQL form of the queries.

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

Sidebar

Related Questions

I have a mysql database in which i am using auto_increment(integer), can you tell
I have a MySQL database which contains data i would like to populate into
I currently have a MySQL database which I was hoping to use to store
I have a mysql database in which there is about hundreds of category for
i have a mysql database from which i require an rss feed of its
I have mysql database and I want a software which can draw the database
i have come across a mysql database which has dates entered in a varchar
i have a large mysql database table in which one column contains values ranging
So I have a mySQL database with a 'users' table which includes a username,
I have a MySQL database with multiple tables, each of which have the same

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.