Making Smart Scan Work - Demo
I'll go through a simple example of the kind of thing we need to think about when trying to achieve Smart Scan. Let me just enable tracing, run a simple query, select and * from *.
Now, there's my query. The result set comes back, and how is it executed? An index full scan with the PK* index. The optimizer is intelligent enough to know that my query can be satisfied purely by reading the index and therefore it didn't have to go to the table at all.
It looks very good. Well, it wasn't. Index full scans are an operation that cannot be offloaded. So, to execute that statement, every block of that index was delivered into the buffer cache of my own database instance, and the compute node then has to do the work of extracting those values.
What can we do about it? One solution would be to hint the code. I select and demand an index fast full scan, and now we see the magic word "storage." An index fast full scan is offloadable, because an index fast full scan can do direct reads.
An alternative approach? Well, you might not want to hint many, many thousands of lines of code. An alternative approach would be to do it through DDL. For example, take that index, make it invisible. Now run my statements without any hint at all, table access storage full, and that was offloaded. Having made the index invisible, Oracle has no option but a full-table scan, and a full-table scan is offloadable.
Now, this means I have three options of this very simple example. I can let the optimizer get on with what it wants to do, and then I use an index that I'm doing block serving into the buffer cache. I can hint the code, index fast full scan. That's probably the best option for performance, but it's also the most work.
In this intervening case, I make the index invisible so that it will still be used of course for enforcing the primary key constraints, but it will not be visible to the optimizer and therefore influence the optimizer towards using plans that can be offloaded the Smart Scan.
Making the choice between this and influencing the optimizer in the correct direction is an extremely difficult job, and it is not always easy to determine what is going to be the best solution.