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 4334660
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T10:33:52+00:00 2026-05-21T10:33:52+00:00

So I’ve done a massive select on MySQL and got back a lot of

  • 0

So I’ve done a massive select on MySQL and got back a lot of data – which is ordered by index.
For example:

select * from nodes where config_id = 1;  

Gives (only relevancies shown)

| definition_id (PK) | position | parent | 
-------------------------------------------
   90                      1         0 << "root"
   08                      2         0
   34                      3         0
   22                      4         0
   17                      1         7  << another defn_id
   38                      2         7
   23                      3         7
   07                      1         90

If this makes no sense, imagine defining a tree, where 90, 8, 34 and 22 are children of the root.
7 is then a child of 90, and 17, 38, 23 are children of 7 (grandchildren of the root).

In order to process this, we find all the nodes with the parent 0, add them in, then look at all those nodes, see if they have any children (by grabbing their from parent, or seeing no values and treating it as a leaf). If they have children, add them on, and continue recursively until the tree is built.
This isn’t the most efficient data store, but one of the requirements is “a single line change” to move a sub-set of nodes and all children. I’d have rather defined a string 0.1.6 etc, but thats the way things are.

So this works fairly well in testing, but when we need to do this 100,000 times a day (without caching – no point, all slightly different) – we need to do this with as few hits to the database as possible (i.e. ONE). Easy, you say, just grab the whole lot and process. But, they’re not all order – as you can see above, 90 is below 7. Yes, that examples connived, but it illustrates the problem that we need some sort of order.

Basically, in a nutshell, the question is, is their an easy (and preferably cheap) way of doing a sub-select on the ResultSet – i.e. grab all results where parent == 7 into another ResultSet and work on that?

Eternal love and appreciation in exchange for thoughts/comments.

  • 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-21T10:33:53+00:00Added an answer on May 21, 2026 at 10:33 am

    I’m not aware of a way to do a sub-select on a ResultSet. If you want to keep to one query you could manage it all in memory with something like this:

    // class to represent your rows
    class Row {
        int definitionId;
        int position;
        int parent;
    }
    
    // map of parents to list of their rows
    Map<Integer, List<Row>> parentMap = new HashMap<Integer, List<Row>>();
    
    // iterate over all results, build row objects and populate the map
    while (rs.next()) {
        Row row = new Row();
        row.definitionId = rs.getInt("definition_id");
        row.position = rs.getInt("position");
        row.parent = rs.getInt("parent");
    
        // find the list of rows for the parent, create it if it doesn't exist
        List<Row> rows = parentMap.get(row.parent);
        if (rows == null) {
            rows = new ArrayList<Row>();
            parentMap.put(row.parent, rows);
        }
    
        // add row to the list for its parent
        rows.add(row);
    }
    
    // find all rows for parent == 7
    for (Row row : parentMap.get(7)) {
        // process row
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a JSP page retrieving data and when single or double quotes are
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Seemingly simple, but I cannot find anything relevant on the web. What is the
this is what i have right now Drawing an RSS feed into the php,
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

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.