views:

561

answers:

6

Oracle decided to dismiss the rule-based optimizer from version 10g, leaving the cost-based one as the only choice.

I think that a rule-based optimizer has the unvaluable positive side of being always predictable. I've seen instead Oracle 10g changing execution plans from night to day, leading to turtle-like performances.

Which could be the rationale behind this change?

+6  A: 

Because everything you can do with RBO, can be done with CBO.

The CBO can be rule based too — more than that, you may decide the "rules" yourself.

To create your own "rules", you hint your query or do a CREATE OUTLINE which will hint it for you. As a result, you execution plan is stable.

The outlines are stored in a system schema called OUTLN, they are editable.

As for me, I always supply hints to my queries running in a production database.

Quassnoi
You can't always add hints to your queries: think of products like Siebel CRM or Hibernate.
friol
Thanks God I don't have to think of these products :) Even if I did, I would gather their queries and created outlines for them.
Quassnoi
I've never heard of outlines. Is that a new feature? Do you have any reference for it?
friol
@friol: Updated my post with a link to the manual
Quassnoi
Ugh... Every query you hint? Why?
The optimizer is free to take the hint or not. That is not a deterministic solution.
EvilTeach
Oracle cannot ignore a hint assuming the hint is properly formed syntactically and that there exists a plan that can use the hinted path.
Justin Cave
@Mark Brady: for a query to use the best plan, of course.
Quassnoi
The point of the optimizer is that it makes best possible decisions based on changing data. If your data qualities are not changing, but the plan is, fix how you are collecting your stats.
SquareCog
@SquareCog: you really think that an algorhitm can make a better decision than a qualified programmer?
Quassnoi
Yes if you are working in an environment that is changing. Also, "qualified" is not as common as "programmer" ;)
SquareCog
@SquareCog: Maybe there is a kind of environment that changes so fast and in such an impredictable way that none can even imagine what will happen the next second and has to rely on artificial intelligence to cope with this sutuation. Maybe. But I've never met that in practice, really.
Quassnoi
Simplest case: dba creates an index. Your hard-coded query forces the optimizer not to use the new index even though it should. More serious: data streams, event databases, federated dbs across WANs (rate of tuple delivery varies with available bandwidth), etc.
SquareCog
A real-life example from personal experience -- a database for genomic alignments and annotations, that went from a design for a few species and big genomes, to supporting microbial dna -- thousands of species with tiny genomes.
SquareCog
@SquareCog: What do you mean: DBA creates an index? In my databases, programmer who writes queries create everything that his queries need to run fast: indexes, tablespaces, partitions, whatever. DBA makes backups and rebuilds RAIDS when the disks are out.
Quassnoi
Sorry for multiple comments, SO limits reply size. Final point -- how many programmers know every kind of join Oracle is capable of? Of those, how many want to select one every time they write a query? This is what declarativity is all about, separation of WHAT from HOW.
SquareCog
@SquareCog: As for now, this such called "separation of WHAT from HOW" is a myth, there is no AI smart enough to do it in practice, including Oracle's CBO. I don't care how many programmers know that, I just hire those who do.
Quassnoi
ok, a programmer creates an index. Are you the only programmer touching the codebase? Do you require data analysts to be programmers with detailed knowledge of your data layout and relative sizes? The optimizer is your friend.
SquareCog
@SquareCog: By the way, this "SQL separation" always reminds me of Joel Spolksy's article about Charles Simonyi, who tried to separate code prototyping from coding itself in Microsoft: http://www.joelonsoftware.com/articles/fog0000000034.html It didn't work in coding, it doesn't work in SQL.
Quassnoi
@SquareCog: A programmer should know what kind of data he is dealing with, point. Be it C++ programmer, Java programmer or Oracle programmer. I thought it's obvious.
Quassnoi
Quassnoi, v dannom sluchae "tochka" perevoditsya "period." Look, I wrote a whole conference paper on how optimizers black boxes and programmers want fine-grained control. I hear you. I am just saying the kind of fine control you want is only required in very specific cases, not as a general rule.
SquareCog
@SquareCog: I can't say to a customer: "you see, there is a CBO, and it decided that you need to SELECT faster and INSERT slower". He's the customer, he decides what he needs, and our task is to translate his decisions to SQL hints.
Quassnoi
Oh and one of your 6 upvotes is from me, so you don't need to get snarky..
SquareCog
Not at all, just a friendly talk :)
Quassnoi
+3  A: 

The RBO is often predicatably bad as well as predictably good. It also doesn't support partitioning and some other database features. The CBO is much better, and as Quassnoi says plan stability is a feature of the CBO also.

David Aldridge
+2  A: 

(I am not a DBA.)

My understanding is that Oracle has been moving away from the RBO for a long time in favor of CBO. It seems useful to me to stop supporting a feature that is no longer in active development (given a long enough depreciation period) so that everyone is using the most effective features.

It's interesting that you called predictability an "unvaluable" effect of using the rule-based optimizer. It seems like when the data changes to make an execution plan sub-optimal it would be best to switch to a new one. Only in the case you alluded to where the optimizer flip-flops between two execution plan would there be a problem with picking the best plan for the the data you are actually querying. I'm not sure what advantage predictability is in more normal situation.

Ending support of the out-dated optimizer ought to free up support for the newer optimizer.

Jon Ericson
+2  A: 

The reason they moved to cost-based optimization is that it can perform better since its based on analyzing statistical information that the rule-based optimizer does not have.

To make the CBO work better, its important to understand the role that statistics gathering plays in execution plan changes which directly affect performance. For one thing, running statistics more or less frequently could help you. Here is a good article about the CBO and statistics:

Optimizing Oracle Optimizer Statistics

+2  A: 

I think you should do rule based programming. Don't think about the situation, follow a list of inviolate rules, no matter what the situation, no matter what you think is the better way, if the rules say use a FOR LOOP in case X then you have to use a loop, even if you know if there will only be 1, loop from 1 to 1.

Stipulate:

Every query has a best plan.

Every query optimizer will determine that plan x% of the time.

The RBO had nowhere else to go, it's percent accuracy is lower than the CBO to be sure, but it was never going to get any better. It was limited like any rule based system.

+3  A: 

The RBO has been deprecated for a long time; it was really just retained for backwards compatibility with legacy applications. Oracle have been announcing the demise of the RBO since (IIRC) version 8, which came out about 10 years ago.

The RBO was deterministic, but not all that clever. Oracle was originally designed before cost-based optimisers were even available, let alone a mature technology. The RBO has been frozen for a long time and does not support a lot of features of modern Oracle engines.

Cost-based optimisation is much smarter. However, if you had queries optimised for the RBO, they might not play nicely with the CBO. You will probably have to re-write or hint your queries appropriately to tune them for the CBO. There is also a facility to specify a query plan and override the CBO with that plan. This will give you deterministic query execution with stable plans.

ConcernedOfTunbridgeWells
This answer touches on what I think is the key point. The RBO cannot support new features (e.g. new access methods). I suspect that trying to invent rules to guide choices between all the access paths and joins now available would become prohibitively difficult.
Dave Costa