Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Oracle SQL, can I query a partition of a table instead of an entire table to make it run faster?

I would like to query a table with a million records for customers named 'FooBar' that have records dated on 7-24-2016. The table has 10 days of data in it.

select * 
from table
where customer = 'FooBar'
and insert_date between to_date('2016-07-24 00:00:00', 'YYYY-MM-DD HH24:MI:SS') and to_date('2016-07-24 23:59:59', 'YYYY-MM-DD HH24:MI:SS');

The problem with the query above is that it takes awhile to run. I would like it to run faster.

The table is partitioned into 24 hr days. Could I focus the query on the table partitions? Would that make the query run faster?

select *
from partition-7-24-2016
where customer = 'FooBar'; 
like image 620
Cale Sweeney Avatar asked Jul 25 '16 21:07

Cale Sweeney


People also ask

Does table partitioning improve query performance?

With table partitioning, you can either choose to re-index the table data in its entirety or selectively. Doing so selectively will drastically reduce the time to execute this daily action. For some clients, I have seen between 50 and 75% improvement in performance.

What is the main advantage of creating table partition?

Partitioning improves the performance of the delete old version shell script since all old version data is in a separate partition. By having all current version data in a separate partition, more current version data is available in database memory that results in efficient use of database buffer pools.


1 Answers

The correct syntax is select [columns] from [table] partition ([partition]). So, in this usecase, you'd have something like this:

SELECT *
FROM   mytable PARTITION (partition_7_24_2016)
WHERE  customer = 'FooBar'; 
like image 52
Mureinik Avatar answered Sep 23 '22 18:09

Mureinik