Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
plsql_bind_varialbes [2020/06/04 14:48] – [Hard Parse] andonovj | plsql_bind_varialbes [2020/06/04 15:43] (current) – [Hard Parse] andonovj | ||
---|---|---|---|
Line 13: | Line 13: | ||
It is obvious to notice, that we want always to have no-parse. Unfortunetely that is rarely the case | It is obvious to notice, that we want always to have no-parse. Unfortunetely that is rarely the case | ||
- | =====Parsing===== | + | =====Parsing |
Let's get through all of them: | Let's get through all of them: | ||
Line 22: | Line 22: | ||
{{ : | {{ : | ||
+ | |||
+ | That shared area check, can be seen below. If it succeed, we will have a soft parse, if not, we will have a hard parse and we will continue with the most expensive parts: | ||
+ | |||
+ | * Optimization - Generate Multiply Execution Plans | ||
+ | * Row Source Generation - Generate a query plan. | ||
+ | |||
+ | Let's example of a query which will always do a hard parse the first time, given that we change the values each time: | ||
+ | |||
+ | < | ||
+ | CREATE OR REPLACE FUNCTION get_count(p_act_id accounts.act_id%TYPE) | ||
+ | return NUMBER is | ||
+ | l_count NUMBER; | ||
+ | BEGIN | ||
+ | SELECT COUNT(*) | ||
+ | INTO l_count | ||
+ | FROM orders | ||
+ | WHERE order_act_id = p_act_id; | ||
+ | | ||
+ | END get_count; | ||
+ | |||
+ | exec get_count(100); | ||
+ | exec get_count(200); | ||
+ | exec get_count(300); | ||
+ | exec get_count(400); | ||
+ | </ | ||
+ | |||
+ | Of course, there are database settings, which we can use, to FORCE the optimized to use its magic, but in general using bind varialbes is always better. | ||
+ | |||
+ | Here is how this could' | ||
+ | |||
+ | < | ||
+ | CREATE OR REPLACE FUNCTION get_count(p_column VARCHAR2, | ||
+ | | ||
+ | return NUMBER is | ||
+ | l_count NUMBER; | ||
+ | l_query VARCHAR2(200); | ||
+ | BEGIN | ||
+ | | ||
+ | | ||
+ | ^ | ||
+ | | | ||
+ | Bind Variable | ||
+ | | ||
+ | END get_count; | ||
+ | |||
+ | exec get_count(order_act_id ,100); <- Hard Parse | ||
+ | exec get_count(order_act_id ,200); <- Soft Parse | ||
+ | exec get_count(order_act_id ,300); <- Soft Parse | ||
+ | exec get_count(order_act_id ,400); <- Soft Parse | ||
+ | </ | ||
+ | |||
+ | Of course there is a different ways, using DBMS_SQL or Native Dynamic SQL, whatever you choose, some gives you more control, some not. However USE BIND VARIABLES IN EVERY CASE. | ||
Line 78: | Line 130: | ||
dbms_sql.close_cursor(m_cursor); | dbms_sql.close_cursor(m_cursor); | ||
</ | </ | ||
+ |