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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T05:18:50+00:00 2026-05-21T05:18:50+00:00

I have an set numeric ranges that I would like to optimize. Here’s a

  • 0

I have an set numeric ranges that I would like to optimize.

Here’s a simple example of initial values:

Start    End
9        12
1        2
60       88
10       11
79       80

What I’d expect as output after optimization:

Start    End
1        2
9        12
60       88

These are the left and right values from Modified Preorder Tree Traversal (Nested Set) data stored in a MySQL database. I use them to exclude inactive branches from the result, and am not currently optimizing the ranges at all. I thought I might get a performance gain from optimizing the ranges before use.


MORE INFO

The values are passed into a query for exclusion of the inactive branches in the tree using a NOT BETWEEN clause. I thought that I could optimize the performance of that query by using a minimal set of ranges.

  • 1 1 Answer
  • 1 View
  • 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-21T05:18:51+00:00Added an answer on May 21, 2026 at 5:18 am

    Here is an SQL that will return what you want

    mysql> CREATE TABLE sample (Start INT, End INT);
    
    mysql> INSERT sample VALUES (9,12),(1,2),(60,88),(10,11),(79,80);
    
    mysql> SELECT * 
        -> FROM sample s 
        -> WHERE NOT EXISTS (SELECT 1 
        ->                   FROM sample 
        ->                   WHERE s.Start > Start AND s.Start < End);
    +-------+------+
    | Start | End  |
    +-------+------+
    |     9 |   12 |
    |     1 |    2 |
    |    60 |   88 |
    +-------+------+
    

    You can, of course, create VIEW, move the data to another table or delete rows using the above SQL.

    NOTE: I am not really sure why are you doing this ‘optimization’.

    EDIT:
    The query can be rewritten as

    SELECT s.* 
    FROM sample s LEFT JOIN 
         sample s2 ON s.Start > s2.Start AND s.Start < s2.End 
    WHERE s2.start IS NULL;
    

    Which will create different execution plan (2xsimple select vs primary/dependent subquery for EXISTS), so performance might be different. Both queries will use an index on (Start, End) if it exists.

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

Sidebar

Related Questions

I have a, say, daily income data set of numeric Temporal Properties , like:
I have a list that contains groups of nearly identical numeric values. i.e. (1004.523,
Imagine you have a set of five elements (A-E) with some numeric values of
I have a cookie set as yab_uploadmode and it has numeric value ranging from
I have 4 numeric up down controls on a form. They are set to
I have set up a Django application that uses images. I think I have
Problem: I have a set of items which have 3 elements: Image Description Numeric
I am modifying QuartzDemo example app and want to do set and read values
I would like to know if it's possible to order by a comma-delimited set
I have a set of divs table-like (with rows and cols), to display a

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.