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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:08:19+00:00 2026-05-26T03:08:19+00:00

I have a table reply of which structure is following: Id name parent_id …

  • 0

I have a table reply of which structure is following:

Id   name   parent_id ...
 1  reply1     0
 2  reply2     1
 3  reply3     2
 4  reply4     3
 5  reply5     4

This table was constructed on a hierarchical relationship(sort of parent->child), how I can get all sub replies according a id of one replies? I want use one SQL to accomplish the best performance. because really volume of replies is huge and probably one tree have more than 1000 rows.

I tried to use START WITH and CONNECT BY, but it came up with a little poor performance.

Appendix:

My rusty sql:

  SELECT * 
    from reply 
   start with (parent_Id=0 AND id=?) 
 connect by prior Id=parent_Id

Both Id and parent_id are being indexed, “connect by” statement seems be expensive, and it causes high CPU utilization on the database side if multple “connect by” SQL runs at the same time. for example: 30 threads: It takes almost 30 minuts on executing a single query

  • 1 1 Answer
  • 3 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-26T03:08:19+00:00Added an answer on May 26, 2026 at 3:08 am

    Without an actual explain plan we can only guess.

    I think your index on parent_id is not helping here since all your “trees” start with the root 0. I would make this index composite — ie: (parent_id, id). This should speed up your start with clause, afterwards the id index should be used.

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

Sidebar

Related Questions

I have a self-referencing table structure working fine with EF, which I use to
I have the following table ID | tbl | reply | time --- -----
I have table in which I am inserting rows for employee but next time
I have table and this table contain result column with some entries. I just
I have table with 300 000 records (MyISAM). I get record from this table
I have table with two columns (varchar from, varchar to). This table represents connections
I have a table with 4000 records(Which is much easier to handle through full
I have an EntiyFramework project for which i am storing settings in a table.
I have a partial view which renders a table. On page load, I am
I am making a nested comment system, and I have the following table: create

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.