Constant declaration and the optimizer

Assume there is a Plsql package A with a defined constant 'constA'
Assume we have an sql query in PLSQL package B that references A.constA.
Will the optimizer always give the same plan for the query whether I used the literal constant or the reference A.constA?
I assume that replacement of references to A.constA would have to be don't before the optimizer begins it's evaluation. I assume that does not happen; therefore, using A.constA has prevented the optimizer from using the statistics on the table.
Ie. It is true that use of literals may provide better performance than references to declared constants.

Hi,
Will the optimizer always give the same plan for the query whether I used the literal constant or the reference A.constA?Assuming bind peeking is not turned off and all other parameters influencing CBO are the same - yes.
"The same plan" in this context means not "the same piece of memory in library cache", but "the same execution path", because query with literal and a constant will result in different SQL queries, hence different shareable parent cursors.
It is true that use of literals may provide better performance than references to declared constants.Yes. If you have a constant to use in SQL, then it's better to use it as a literal rather than bind (using a PL/SQL constant in a query results in using bind variable - but maybe that behavior will be changed sometime).
The main issue with using binds for constant is a case you use several constants for exactly the same query and there's data skew. CBO is not doing well with that until 11g (which introduced adaptive cursor sharing).

Similar Messages

  • Exception Declaration and the Public Interface

    What is the connection between a method , exception declaration ( throw ) and public interface. Does every method has an implicit public interface ?? Is list of thrown exceptions, part of a method’s public interface ?

    sagararya wrote:
    So, how do we know that some method throws an exception that we have to catch?Via the throws clause.
    [http://java.sun.com/docs/books/tutorial/essential/exceptions/index.html]
    Just as a method must specify what type and how many arguments it accepts and
    what is returned, the exceptions that a method can throw must be declared (unless the
    exceptions are subclasses of RuntimeException). Also those that are subclasses of Error need not be declared.
    The list of thrown exceptions
    is part of a method’s public interface.Ah, now I see what you mean. Where did you read that? I don't recall having ever heard the phrase "public interface" used like that.
    The above paragraph is from the book, Osborne_Java, written by James Kussow.. Ok.
    Can anybody explain me the 4th line in the above paragraph, starting from "The list of thrown exceptions ... "
    The list of thrown exceptions is part of a method’s public interface.
    The throws keyword is used as follows to list the exceptions that a method can throw:What part do you not understand? Read the tutorial I linked, and if something is still not clear, ask your specific question.
    Personally I think the phrase "public interface" is misleading here. If that's what you're hung up on, don't be. It doesn't mean "public" in the sense of Java's "public" access modifier. It just means the list of exceptions is part of what callers of the method know about it.
    EDIT: Oops. Too late.
    Edited by: jverd on Jun 25, 2008 8:31 AM

  • Problem declaring and using a REF CURSOR

    I'm having a real problem using a REF CURSOR type
    Here's the DECLARE and the start of the BEGIN I've so far developed.
    DECLARE
    TYPE r1 IS RECORD (
    szvcapc_pidm szvcapc.szvcapc_pidm%TYPE,
    szvcapc_term_code szvcapc.szvcapc_term_code%TYPE,
    szvcapc_request_no szvcapc.szvcapc_request_no%TYPE);
    szvcapc_rec r1;
    TYPE cursor_1 IS REF CURSOR RETURN r1;
    szvcapc_cv cursor_1;
    TYPE r2 IS RECORD (
    stvests_code stvests.stvests_code%TYPE
    stvests_rec r2;
    TYPE cursor_2 IS REF CURSOR RETURN stvests_rec;
    stvests_cv cursor_2;
    BEGIN
    OPEN szvcapc_cv FOR
    SELECT szvcapc_pidm, szvcapc_term_code, szvcapc_request_no
    FROM szvcapc
    WHERE szvcapc_passed_ind = 'Y'
    AND szvcapc_award_credits = 'N';
    LOOP
    FETCH szvcapc_cv INTO szvcapc_rec;
    EXIT WHEN szvcapc_cv%NOTFOUND;
    END LOOP;
    OPEN stvests_cv FOR
    SELECT stvests_code
    FROM stvests
    WHERE stvests_eff_headcount = 'Y';
    LOOP
    FETCH stvests_cv INTO stvests_rec;
    EXIT WHEN stvests_cv%NOTFOUND;
    END LOOP;
    SELECT *
    FROM (
    <snip>
    INNER JOIN stvests_rec
    ON SFBETRM.SFBETRM_ESTS_CODE = stvests_rec.STVESTS_CODE
    <snip>
    I later try to use the stvests_rec and szvcapc_rec in the main SELECT statement it doesn't recognise stvests_rec and szvcapc_rec as a "Table or View".
    I have to use a REF CURSOR as this code is ultimately for use in Oracle Reports.
    What am I doing wrong?

    > The reason I'm trying to use a REF CURSOR is that I was told that you
    couldn't use CURSORs in Oracle Reports.
    That does not change anything ito what happens on the Oracle server side. A cursor is a cursor is a cursor.
    Every single SQL winds up as a cursor. Each cursor has a reference handle to access and use. HOW this handle is used in the language differs. But that is a language issue and not an Oracle RDBMS issue.
    For example. An EXECUTE IMMEDIATE in PL/SQL creates a cursor handle and destroys it after use - automatically. An implicit cursor works the same. An explicit cursor you have the handle fetch from it and close from it when done.
    A ref cursor is simply a handle that can be returned to an external client - allowing that application to use the handle to fetch the rows.
    Do not think that a ref cursor is any different from the RDBMS side than any other cursor. The RDBMS does not know the difference. Does not care and nor should it.
    > I'm trying to reduce the hits on the database from nested selects by
    removing the dataset from the main SELECT statement and performing it only
    once outside and then referencing this previously collected dataset inside the
    main SELECT statement.
    Good stuff that you are considering SQL performance. But you need to make sure that you
    a) identify the performance inhibitor issue correctly
    b) address this issue correctly
    And you need to do that within SQL. Not PL/SQL. PL/SQL will always be slower at crunching data than SQL. For example, wanting to cache the data somehow to reduce the read overhead - that is exactly what the DB buffer cache does. It caches data. That is also exactly what the CBO will attempt - reduce the amount of data that needs to be read and processed.
    Not saying that the RDBMS can do it all. It needs help from you - in the form of a SQL that instructs it to process only the minimum amount of data required to get the required results. In the form of a sound physical design that provides optimal usage of data storage and access (like indexing, partitioning, clustering, etc).
    Bottom line - you cannot use a REF CURSOR to make a SQL go faster. A REF CURSOR is simply a cursor in the SQL Engine. A cursor is nothing but the "compiled-and-executable" code of a SQL "source program".

  • Pl/sql boolean expression short circuit behavior and the 10g optimizer

    Oracle documents that a PL/SQL IF condition such as
    IF p OR q
    will always short circuit if p is TRUE. The documents confirm that this is also true for CASE and for COALESCE and DECODE (although DECODE is not available in PL/SQL).
    Charles Wetherell, in his paper "Freedom, Order and PL/SQL Optimization," (available on OTN) says that "For most operators, operands may be evaluated in any order. There are some operators (OR, AND, IN, CASE, and so on) which enforce some order of evaluation on their operands."
    My questions:
    (1) In his list of "operators that enforce some order of evaluation," what does "and so on" include?
    (2) Is short circuit evaluation ALWAYS used with Boolean expressions in PL/SQL, even when they the expression is outside one of these statements? For example:
    boolvariable := p OR q;
    Or:
    CALL foo(p or q);

    This is a very interesting paper. To attempt to answer your questions:-
    1) I suppose BETWEEN would be included in the "and so on" list.
    2) I've tried to come up with a reasonably simple means of investigating this below. What I'm attempting to do it to run a series of evaluations and record everything that is evaluated. To do this, I have a simple package (PKG) that has two functions (F1 and F2), both returning a constant (0 and 1, respectively). These functions are "naughty" in that they write the fact they have been called to a table (T). First the simple code.
    SQL> CREATE TABLE t( c1 VARCHAR2(30), c2 VARCHAR2(30) );
    Table created.
    SQL>
    SQL> CREATE OR REPLACE PACKAGE pkg AS
      2     FUNCTION f1( p IN VARCHAR2 ) RETURN NUMBER;
      3     FUNCTION f2( p IN VARCHAR2 ) RETURN NUMBER;
      4  END pkg;
      5  /
    Package created.
    SQL>
    SQL> CREATE OR REPLACE PACKAGE BODY pkg AS
      2 
      3     PROCEDURE ins( p1 IN VARCHAR2, p2 IN VARCHAR2 ) IS
      4        PRAGMA autonomous_transaction;
      5     BEGIN
      6        INSERT INTO t( c1, c2 ) VALUES( p1, p2 );
      7        COMMIT;
      8     END ins;
      9 
    10     FUNCTION f1( p IN VARCHAR2 ) RETURN NUMBER IS
    11     BEGIN
    12        ins( p, 'F1' );
    13        RETURN 0;
    14     END f1;
    15 
    16     FUNCTION f2( p IN VARCHAR2 ) RETURN NUMBER IS
    17     BEGIN
    18        ins( p, 'F2' );
    19        RETURN 1;
    20     END f2;
    21 
    22  END pkg;
    23  /
    Package body created.Now to demonstrate how CASE and COALESCE short-circuits further evaluations whereas NVL doesn't, we can run a simple SQL statement and look at what we recorded in T after.
    SQL> SELECT SUM(
      2           CASE
      3              WHEN pkg.f1('CASE') = 0
      4              OR   pkg.f2('CASE') = 1
      5              THEN 0
      6              ELSE 1
      7           END
      8           ) AS just_a_number_1
      9  ,      SUM(
    10           NVL( pkg.f1('NVL'), pkg.f2('NVL') )
    11           ) AS just_a_number_2
    12  ,      SUM(
    13           COALESCE(
    14             pkg.f1('COALESCE'),
    15             pkg.f2('COALESCE'))
    16           ) AS just_a_number_3
    17  FROM    user_objects;
    JUST_A_NUMBER_1 JUST_A_NUMBER_2 JUST_A_NUMBER_3
                  0               0               0
    SQL>
    SQL> SELECT c1, c2, count(*)
      2  FROM   t
      3  GROUP  BY
      4         c1, c2;
    C1                             C2                               COUNT(*)
    NVL                            F1                                     41
    NVL                            F2                                     41
    CASE                           F1                                     41
    COALESCE                       F1                                     41We can see that NVL executes both functions even though the first parameter (F1) is never NULL. To see what happens in PL/SQL, I set up the following procedure. In 100 iterations of a loop, this will test both of your queries ( 1) IF ..OR.. and 2) bool := (... OR ...) ).
    SQL> CREATE OR REPLACE PROCEDURE bool_order ( rc OUT SYS_REFCURSOR ) AS
      2 
      3     PROCEDURE take_a_bool( b IN BOOLEAN ) IS
      4     BEGIN
      5        NULL;
      6     END take_a_bool;
      7 
      8  BEGIN
      9 
    10     FOR i IN 1 .. 100 LOOP
    11 
    12        IF pkg.f1('ANON_LOOP') = 0
    13        OR pkg.f2('ANON_LOOP') = 1
    14        THEN
    15           take_a_bool(
    16              pkg.f1('TAKE_A_BOOL') = 0 OR pkg.f2('TAKE_A_BOOL') = 1
    17              );
    18        END IF;
    19 
    20     END LOOP;
    21 
    22     OPEN rc FOR SELECT c1, c2, COUNT(*) AS c3
    23                 FROM   t
    24                 GROUP  BY
    25                        c1, c2;
    26 
    27  END bool_order;
    28  /
    Procedure created.Now to test it...
    SQL> TRUNCATE TABLE t;
    Table truncated.
    SQL>
    SQL> var rc refcursor;
    SQL> set autoprint on
    SQL>
    SQL> exec bool_order(:rc);
    PL/SQL procedure successfully completed.
    C1                             C2                                     C3
    ANON_LOOP                      F1                                    100
    TAKE_A_BOOL                    F1                                    100
    SQL> ALTER SESSION SET PLSQL_OPTIMIZE_LEVEL=0;
    Session altered.
    SQL> exec bool_order(:rc);
    PL/SQL procedure successfully completed.
    C1                             C2                                     C3
    ANON_LOOP                      F1                                    200
    TAKE_A_BOOL                    F1                                    200The above shows that the short-circuiting occurs as documented, under the maximum and minimum optimisation levels ( 10g-specific ). The F2 function is never called. What we have NOT seen, however, is PL/SQL exploiting the freedom to re-order these expressions, presumably because on such a simple example, there is no clear benefit to doing so. And I can verify that switching the order of the calls to F1 and F2 around yields the results in favour of F2 as expected.
    Regards
    Adrian

  • Using 'save as...' and the options panel to optimize

    When I take a JPG and use "save as..." then select 'options' I can't seem to change the file size manually.  When the options window opens after I do save as, I go through the regular process of using the slider to change the percentage of quality.  I can see in the upper right-hand corner the file size changes.  I click 'OK' and then save in the next window and I wind up with the file in the same original size, as if I hadn't changed the percentage.  Am I forgetting something...I know 'save as...' in Lion/Mountain Lion is not a default setting, but Export doesn't give me the options I want.  Also renaming the file, moving it to another place, none of those things enable to me to save a file with the reduced file size. 
    Thanks in advance!

    I think you're running into a known Fireworks bug, where options specified by a user within the Save As options dialog are overridden by settings already specified within the Optimize panel or Image Preview dialog. This is typically only a problem when the files being saved/exported are of the same type—e.g., using Save As to create a JPEG from an existing JPEG, or a PNG with transparency from an existing PNG.
    Have a look at this forum post and thread for more info:
    http://forums.adobe.com/message/4701484#4701484
    You should have better luck if you Export the file using File > Image Preview. This brings up the same dialog as the Save As options, but your settings, in this case, will be honored.
    You can submit your own bug report on this issue here: https://www.adobe.com/cfusion/mmform/index.cfm?name=wishform

  • Bridge CC and the constant thumbnail regeneration problem.

    I'm one of many who suffers from Bridge CC constantly regenerating thumbnails. There are multiple threads about the problem, with different descriptions and different theories of the cause.
    I recently tried an experiment. I replaced Camera Raw.8bi (version 8) file in the CC folder with the Camera Raw.8bi file from my old CS6 folder (version 7.1.0.354). That worked OK. Bridge CC and Photoshop CC work with the older version of Camera Raw, and the constant regeneration of thumbnails ceased.
    Unfortunately, installing the old version of Camera Raw causes Bridge CC to regenerate thumbnails for all folders on the first visit, even though the files are cached and unchanged. But after that first visit, no regeneration occurs.
    I have no idea why that is, but I think the experiment gives good evidence that the problem lies in the Camera Raw code and not in the Bridge CC code itself.
    None of the various threads I've seen give me any confidence that Adobe has acknowledged this problem, or is even aware of it. And I'm not sure of the best way to get their attention. I've seen references that say Adobe bug reporting should be done on the photoshop.com website. I've tried that in the far past for different issues, but with no success. However, with no known alternative, I've made the following post:
    http://feedback.photoshop.com/photoshop_family/topics/bridge_cc_re_caching_thumbnails?rfm= 1
    I encourage others to "reply" to that post. Maybe if enough people respond, Adobe will notice and acknowledge.
    If anybody knows a better way to report bugs (and get acknowledgement), please share.

    Been there, done that:
    http://feedback.photoshop.com/photoshop_family/topics/unneccesary_bridge_thumbnail_and_pre view_extraction
    They know about it, they just don't know how to recreate it.
    Best thing we can do is reliably recreate the fault. My workaround is to only enable Lens Profile Corrections when necessary, as it is a combination of that and some other factor(s) which seems to trigger it.
    If you read all the discussions, you'll see that there are two bugs which produce the same symptoms. One introduced in probably ACR 6.1, whichg was fixed in 8.2; and the other was introduced in 7.3 and is ongoing.

  • My macbook wont boot up, black screen and the cd drive keeps making a constant sound. What to do?

    My macbook wont boot up. When I turn it on, the screen turns black right away and the cd/dvd drive keeps making a constant "ejecting" sound.
    The strange thing though is that once in a while starts up propperly, but suddely goes black again (after a min. or two), and the ejecting sound comes back. What to do, and yh, I've never done a back up so would it be possible to take out the HD and regain whats in there?
    Any help would be appriciated!

    Hello. Try resetting the PRAM and SMC first.
    http://support.apple.com/kb/ht3964
    http://support.apple.com/kb/ht1379

  • How to create a matrix with constant values and multiply it with the output of adc

    How to create a matrix with constant values and multiply it with the output of adc 

    nitinkajay wrote:
    How to create a matrix with constant values and multiply it with the output of adc 
    Place array constant on diagram, drag a double to it, r-click "add dimension". There, a constant 2D double array, a matrix.
    /Y
    LabVIEW 8.2 - 2014
    "Only dead fish swim downstream" - "My life for Kudos!" - "Dumb people repeat old mistakes - smart ones create new ones."
    G# - Free award winning reference based OOP for LV

  • What is the difference between the function declared in the package and pac

    What is the difference between defining a function in the package and package body ?
    Edited by: user10641405 on Nov 19, 2009 1:29 PM

    If you describe a package, you will only see the functions declared in the spec.
    If you only declare them in the body then they are not available to other packages (they are private to the package, not public)

  • What is varray and how to declare in the pl/sql program

    what is varray and how to declare in the pl/sql program

    1b5595eb-fcfc-48cc-90d2-43ba913ea79f wrote:
    what is varray and how to declare in the pl/sql program
    when all else fails Read The Fine Manual
    Oracle Database Search Results: varray

  • Since moving to Maverick and the new updated of Keynote, I have a constant problem when typing in a text box, the program crashes. Is there a bug fix for this. Drives me nuts.

    Since moving to Maverick and the new updated of Keynote, I have a constant problem when typing in a text box, the program crashes. Is there a bug fix for this. Drives me nuts. Like many who can type quite quickly but at secretarial level, the text box freezes, nothing works and you know what's coming...crash!
    This is most annoying. Is there bug fixes for this. Apparently I have the current updates and this problem still exists. Is it a Maverick bug or Keynote.
    Barry

    How did you install Mavericks, as an update ontop of the previous OS or did you wipe the drive and install clean?

  • I get constant buffering very slow downloads and the pinwheel.  is there a keystroke remedy for this??

    i get constant buffering very slow downloads and the pinwheel.  is there a keystroke remedy for this??

    No magical keystroke remedy. The causes for this can be complicated.
    http://www.thexlab.com/faqs/sbbod.html
    Also check the health of the drive with the free demo of SMART Utiltiy.
    http://www.volitans-software.com/smart_utility.php
    Only happening while on the Internet or all over the place? What's your Internet speed?
    http://www.speedtest.net/

  • I am having constant crashing and significant slow down on my iPad with the new update operating system, is anyone else out there?

    I am having constant crashing and significant slowdown on my iPad with the new operating system...is anyone else out there ?

    You are in the Mavericks forum.  You need to ask in the IOS 8 forum.

  • Please, advice how to optimize optimizer_index_cost and the other optimizer

    I need to tune my performance. I have too many db_file_sequential read due to index lookups. The tables are Large and indexes are also large. I would like to only cache the indexes that are actually used.
    Please, advice how to tune optimizer_index_cost and the other optimizer_index parameters.
    Thanks a lot,
    MJ

    Oracle will only cache blocks from objects that are used. I'm not sure, therefore, what it is you are trying to cache (or not cache) here.
    What version of Oracle are you using? Assuming you're using 9i or later, gathering system statistics is generally preferrable to adjusting optimizer initialization parameters.
    You are also in the somewhat unique position of, apparently, complaining that the CBO is using too many indexes rather than doing full table scans. While it is certainly true that full table scans may be more efficient than index lookups, it is pretty rare for the CBO to erroneously use indexes when it shouldn't-- it tends to be much less index hungry than the RBO was, for example. It sounds like you likely have inefficient SQL that needs to be tuned, not that you have initialization parameters to tune.
    Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • How can i do with labview program,when i have 20 different values,and 1 want to add it with constant value.and how to get the results?

    how can i do with labview program,when i have   20 different values,and 1 want to add it with constant value.and how to get the results?

    Why do the 20 values have to be different? The same code should work even if some are equal.
    What do you mean by "get the result"? The result is available at the output terminal and all you need is a wire to get it where you need it. That could be an indicator, another operation, or even a hardware device.
    What is the data type of the 20 values? An array? A cluster? A bunch of scalars? A waveform? Dynamic data?
    LabVIEW Champion . Do more with less code and in less time .

Maybe you are looking for