Selecting both MIN and MAX From the Table is slower than expected

后端 未结 4 1622
忘掉有多难
忘掉有多难 2021-02-05 03:41

I have a table MYTABLE with a date column SDATE which is the primary key of the table and has a unique index on it.

When I run this query:

4条回答
  •  悲哀的现实
    2021-02-05 04:22

    The Index Full Scan can only visit one side of the index. When you are doing

    SELECT MIN(SDATE), MAX(SDATE) FROM MYTABLE
    

    you are requesting to visit 2 sides. Therefore, if you want both the minimum and the maximum column value, an Index Full Scan is not viable.

    A more detailed analyze you can find here.

提交回复
热议问题