could you pls tell me if I can get to know the exact EXECUTION plan for the query before executing the query?Think about it this way:
Can you get the
exact route you took in the car
before your journey?
If you answered yes to that, you need to start cashing in on your fortune telling powers!
And can I force the query to follow an execution plan using hints?Ye-es, buuuuut....
Typically you need waaaay more hints than you think you do. For example, this is a simple query with an "obvious" plan:
select * from t
where x = 1;
--------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | 1 (100)| |
| 1 | TABLE ACCESS BY INDEX ROWID| T | 1 | 26 | 1 (0)| 00:00:01 |
|* 2 | INDEX UNIQUE SCAN | SYS_C0014790 | 1 | | 1 (0)| 00:00:01 |
--------------------------------------------------------------------------------------------
But to ensure you keep the same plan, you need all these hints:
/*+
BEGIN_OUTLINE_DATA
IGNORE_OPTIM_EMBEDDED_HINTS
OPTIMIZER_FEATURES_ENABLE('11.2.0.4')
DB_VERSION('11.2.0.4')
OPT_PARAM('_optimizer_cost_model' 'fixed')
OPT_PARAM('_fix_control' '6670551:0')
ALL_ROWS
OUTLINE_LEAF(@"SEL$1")
INDEX_RS_ASC(@"SEL$1" "T"@"SEL$1" ("T"."X"))
END_OUTLINE_DATA
*/
Calling them hints is misleading. They're really directives. Oracle Database has to follow them if it can. If it's "ignoring" a hint, then it's invalid for some reason.
See this presentation from Maria Colgan for more details on this:
https://www.slideshare.net/MariaColgan1/harnessing-the-power-of-optimizer-hints