Skip to Main Content

Write Great SQL Office Hours

Free tips and training every month! Subscribe for reminders and more from Office Hours. FAQ

Header container

November 26

14:00 UTC   Start Times Around the World


Tuning SQL Date Range Queries
Tuning SQL queries with date ranges, such as:

and start_date between to_date ( :st_dt, 'YYYY-MM-DD' )
and to_date ( :en_dt, 'YYYY-MM-DD' )

Is tricky.

In this session we discussed why this is a hard problem. And looked into strategies you can use to get better plans for these queries.

Highlights include:

02:40 - High-level strategies for identifying the number of rows a query will return
10:00 - Demo of query performance for queries with date ranges showing how the database uses adaptive cursor sharing
30:00 - Demo of a query combining equality and range predicates
37:00 - Discussion of indexes you can create to make the previous query faster
44:00 - Tuning queries that include a join like:
<col> between <start_date_col> and <end_date_col>
51:10 - Using dynamic statistics to improve the optimizer's row estimates
57:00 - How adaptive plans enable the optimizer to choose the best join method

Subscribe to be notified of changes to sessions and give us feedback!

Having trouble watching the video on this page? Open the video in your browser.

Your Experts

Chris Saxon
Chris Saxon, Oracle Developer Advocate for SQL    
Chris Saxon is an Oracle Developer Advocate and quizmaster on Dev Gym. His job is to help you get the best out of the Oracle Database and have fun with SQL! He's also part of the answer team on Ask TOM and creates YouTube videos at The Magic of SQL channel.
Keith Laker
Keith Laker, Senior Principal Product Manager    
I have been working with Oracle data warehouse technology for over 20 years working on a wide variety of data warehouse projects both as a consultant and an onsite support engineer. I am now part of the Data Warehouse Product Management Team where I am responsible for analytical SQL. I am based in the UK at our Manchester office. A key part of my role is to work with our sales teams to brief our customers on data warehousing and analytical SQL: explaining the wide variety of new and exciting opportunities that our DW and analytical solutions can support. I regularly deliver sales training for data warehousing and analytical SQL across all our sales regions and provide competitive intelligence support across all the major data warehouse vendors.