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

后端 未结 4 1564
忘掉有多难
忘掉有多难 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:34

    Try not selecting both edges of the index in one query , Accessing the query in a different way like this :

    select max_date, min_date
    from (select max(sdate) max_date from mytable),
           (select min(sdate) min_date from mytable)
    

    will cause the optimizer to access the index in INDEX_FULL_SCAN(MIN/MAX) in nested loops (in our case , twice).

    enter image description here

提交回复
热议问题