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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T07:11:37+00:00 2026-06-07T07:11:37+00:00

In the nested set model we have LEFT and Right columns the first time

  • 0

In the nested set model we have LEFT and Right columns

the first time when the table is empty, what i need to insert to the RIGHT column, if i don’t know how many children will i have

LEFT 1 – forever

RIGHT ? – what value goes here??

how to make it dynamic? not static.

ps: using php

  • 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-07T07:11:39+00:00Added an answer on June 7, 2026 at 7:11 am

    I’m assuming from your tags and title that you are looking for a solution that works with MySQL.

    Yes, you are right that unless you know the number of elements in advance the value for right needs to be calculated dynamically. There are two approaches you can use:

    • You could start with the least value that works (2 in this case) and increase it later as needed.
    • You could just make a guess like 10000000 and hope that’s enough, but you need to be prepared for the possibility that it wasn’t enough and may need adjusting again later.

    In both cases you need to implement that the left and right values for multiple rows may need to be adjusted when inserting new rows, but in the second case you only actually need to perform the updates if your guesses were wrong. So the second solution is more complex, but can give better performance.

    Note that of the four common ways to store heirarchical data, the nested sets approach is the hardest to perform inserts and updates. See slide 69 of Bill Karwin’s Models for Heirarchical Data.

    nested sets update difficulty

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

Sidebar

Related Questions

I have hierarchical data in a nested set model (table:projects): My table (projects): id,
Querying a Nested Set Model table , here's the SQL... how can this be
I've got an array with data from a MySQL table in nested set model
I have an application that uses a nested set model class to organise my
I have an application that uses a nested set model class to organise my
I have been looking into Adjacency List and Nested Set Model to find the
I'm facing a problem with the nested set model, with MySQL. I can insert,
I've been using the crap out of the Nested Set Model lately. I have
I'm using a nested set in a MySQL table to describe a hierarchy of
I have your run of the mill nested set hierarchy type setup with the

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.