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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T23:23:27+00:00 2026-05-19T23:23:27+00:00

I have a query: select min(timestamp) from table This table has 60+million rows, and

  • 0

I have a query:

select min(timestamp) from table

This table has 60+million rows, and daily I delete a few off the end. To determine whether or not there is any data old enough do delete I run the query above. There is an index on timestamp ascending, containing only one column, and the query plan in oracle causes this to be a full index scan. Should this not be the definition of a seek?

edit including plan:

| Id  | Operation                  | Name       | Rows  | Bytes | Cost (%CPU)| Time     |
|   2 |   INDEX FULL SCAN (MIN/MAX)| NEVENTS_I2 |     1 |     8 |     4   (100)| 00:00:01 |
|   1 |  SORT AGGREGATE            |            |     1 |     8 |            |          |
|   0 | SELECT STATEMENT           |            |     1 |     8 |     4   (0)| 00:00:01 |
  • 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-19T23:23:28+00:00Added an answer on May 19, 2026 at 11:23 pm

    At first I thought that the index would only be used if the column is declared NOT NULL. I tested with the following setup:

    SQL> CREATE TABLE my_table (ts TIMESTAMP);
    
    Table created
    
    SQL> INSERT INTO my_table
      2  SELECT systimestamp + ROWNUM * INTERVAL '1' SECOND 
      3    FROM dual CONNECT BY LEVEL <= 100000;
    
    100000 rows inserted
    
    SQL> CREATE INDEX ix ON my_table(ts);
    
    Index created
    
    SQL> EXPLAIN PLAN FOR SELECT MIN(ts) FROM my_table;
    
    Explained
    
    SQL> SELECT * FROM TABLE(dbms_xplan.display);
    
    --------------------------------------------------------------------------------
    | Id  | Operation                  | Name | Rows  | Bytes | Cost (%CPU)| Time
    --------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT           |      |     1 |    13 |    69   (2)| 00:00:0
    |   1 |  SORT AGGREGATE            |      |     1 |    13 |            |
    |   2 |   INDEX FULL SCAN (MIN/MAX)| IX   | 90958 |  1154K|            |
    --------------------------------------------------------------------------------
    

    Here we notice that the index is used, but all rows from the index are read. If we specify that the column is not null we get a much better plan:

    SQL> ALTER TABLE my_table MODIFY ts NOT NULL;
    
    Table altered
    
    SQL> EXPLAIN PLAN FOR SELECT MIN(ts) FROM my_table;
    
    Explained
    
    SQL> SELECT * FROM TABLE(dbms_xplan.display);
    
    --------------------------------------------------------------------------------
    | Id  | Operation                  | Name | Rows  | Bytes | Cost (%CPU)| Time
    --------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT           |      |     1 |    13 |     2   (0)| 00:00:0
    |   1 |  SORT AGGREGATE            |      |     1 |    13 |            |
    |   2 |   INDEX FULL SCAN (MIN/MAX)| IX   | 90958 |  1154K|     2   (0)| 00:00:0
    --------------------------------------------------------------------------------
    

    In fact this is the same plan that is also used if we add a WHERE clause (Oracle will read a single row from the index):

    SQL> EXPLAIN PLAN FOR SELECT MIN(ts) FROM my_table WHERE ts IS NOT NULL;
    
    Explained
    
    SQL> SELECT * FROM TABLE(dbms_xplan.display);
    
    --------------------------------------------------------------------------------
    | Id  | Operation                   | Name | Rows  | Bytes | Cost (%CPU)| Time
    --------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT            |      |     1 |    13 |     2   (0)| 00:00:
    |   1 |  SORT AGGREGATE             |      |     1 |    13 |            |
    |   2 |   FIRST ROW                 |      | 90958 |  1154K|     2   (0)| 00:00:
    |   3 |    INDEX FULL SCAN (MIN/MAX)| IX   | 90958 |  1154K|     2   (0)| 00:00:
    --------------------------------------------------------------------------------
    

    This last plan shows (line 2) that Oracle is indeed performing a “seek”.

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

Sidebar

Related Questions

I have this query: SELECT page.id, revision.title, revision.number FROM page INNER JOIN revision ON
I have the following query: select column_name, count(column_name) from table group by column_name having
I have this SQL query: SELECT * FROM IMAGES WHERE IMAGENAME in ('IMG1', 'IMG2',
I have a query like this: SELECT TABLE_NAME, COLUMN_NAME, IS_NULLABLE, DATA_TYPE FROM MY_DB.INFORMATION_SCHEMA.COLUMNS WHERE
I have the following query: SELECT c.* FROM companies AS c JOIN users AS
If I have a query like: Select EmployeeId From Employee Where EmployeeTypeId IN (1,2,3)
I have the following SQL query: select expr1, operator, expr2, count(*) as c from
I have a following SQL QUERY: SELECT articles.name, articles.price, users.zipcode FROM articles INNER JOIN
I have the following (shortened query): SELECT `Statistics`.`StatisticID`, COUNT(DISTINCT `Flags`.`FlagType`) AS `FlagCount` FROM `Statistics`
I have a select query that currently produces the following results: Description Code Price

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.