When I want to query a single partition I usually use something like that:
Select * from t (partition p1)
But when you have to query it in your pl/sql code it comes to using execute immediate
and hard-parse of the statement.
Okay, for RANGE-partitioned table (let it be SOME_DATE of date
type) I can workaround it like
Select * from t where some_date <= :1 and some_date > :2
Assuming :1
and :2
stand for partition bonds.
Well, as for LIST-partitioned table I can easily specify the exact value of my partition key field like
Select * from t where part_key = 'X'
And what about HASH-partitioning? For example, I have a table partitioned by hash(id)
in 16 partitions. And I have 16 jobs each handling its own partition. So I have to use it like that
Select * from t (partition p<n>)
Question is: can I do it like this for example
Select * from t where hash(id) = :1
To enforce partition pruning take the whole n-th partition?
It's okay when you have just 16 partitions but in my case I have composite partitioning (date + hash(id)), so every time job handles a partition it's always a new sql_id
and it ends up in quick shared pool growth
where part_key = 'X' and subpart_key = 'Pie'
will take you to the exact subpartition. Or you could usesubpartition for
syntax but then you are back to hard parsing. - William Robertson