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

  • Home
  • SEARCH
  • 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
  • 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-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 list that contains groups of nearly identical numeric values. i.e. (1004.523,
I have set up a Django application that uses images. I think I have
I have a problem in hand and that is to fetch a result set
I have a UIPicker with 3 components containing numeric values, this allows the user
I have a table which contains a field of type numeric(28,10) . I would
If I have a set of small string values, and I want to fetch
If I have statement DECLARE @i INT; DECLARE @d NUMERIC(9,3); SET @i = 123;
We have set up a system where notifications get sent to a user with
I have set a canvas' background to an image of a company logo. I
I have set up transactional replication between two SQL Servers on different ends of

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.