Which line in where clause gets executed first

Hi everyone!
I have some sqls which look like this
select ...
from table A, table B
where a.name = b.name
and a.name in (....)Now, which one of this is executed first? the where clause or the and clause?
Joining the tables is preferably done in where clause?
I am using Oracle 10g.
Please give me some guidance.
Thank You.
Nith

user645399 wrote:
When I deal with very large tables I notice that it takes too long, so was wondering if I move the table join to the and clause, it can join and then apply the filter which could be faster instead of filtering and joining the table.Define "+too long+" - what metric and baseline are used?
You need to have some kind of baseline of what acceptable performance is and then some metric to measure against the baseline to determine whether the process has acceptable performance or not.
What I mean by this is that "+too long+" is an arbitrary statement that cannot be evaluated. It the workload is huge, that workload will take some time too process. If a workload is tiny, that will take less time to process.
But "+too long+" gives no indication what the workload is. And "+large table+" is meaningless as a SQL against a billion row table can be minimal workload (e.g. unique index read), whereas a SQL against a small table can be a huge workload (e.g. cartesian join and full table scan).
You first need to determine WHAT the workload is, before judging it as "+too slow+".
I have no idea on how is the execution plan.And one of the first steps is looking at the execution plan. SQL code is source code (like C/C++ or Visual Basic source code). This cannot be executed - it needs to be parsed and compiled into an executable program.
For C/C++ and Visual Basic, that is typically an +.exe+ or +.ddl+ executable. SQL source code is compiled into an executable program called a cursor. The execution plan of that cursor shows the structure of this program and what this program will (technically) do step-by-step.
From the execution plan you can make calls such as, are the available indexes used optimally, did the CBO (the creator of the execution) made sane decisions based on the available data and stats it has for the tables and database?
The execution plan can also highlight errors in the source code - for example, table foo is scanned twice using a full table scan. This does not make sense to hit the same data set twice in a single SQL - so why is the SQL source code written that way?
The bottom line is that you need to know WHAT it is doing to determine if the performance is acceptable or not. If not, then you need to determine WHY it is doing what it is doing and whether there are better alternatives.

Similar Messages

  • Function in where clause is executed and returns null instead a valid value

    Hi all
    i have a strange problem.
    There is a access-application where i have a pass-through-sql.
    This sql is fetching a foreign exchange rate from a history table which holds this rates for every day and i'm going to fetch the rate for the last day of the last month.
    Example of the fraction which does not work and which i executed directly on the DB, Oracle 11.2.0.3.0:
    select val
    ,last_day(add_months((trunc(sysdate)+3),-1)) tag
    from k.obj_ts_hist th
    where obj_id = 2660
    and eff_date = last_day(add_months((trunc(sysdate)+3),-1))
    --and      eff_date = '01-mar-2013'
    eff_date on table k.obj_ts_hist is defined as date.
    The function last_day in the where clause leads to null for both values in the select (val and tag).
    If i use eff_date = '01-mar-2013' it's all ok, i get the rigth values.
    I tested some combinations of the clause, e.g.
    eff_date = to_date(to_char(last_day(add_months((trunc(sysdate)+3),-1)),'YYYYMMDD'),'YYYYMMDD')
    or
    to_char(eff_date,'YYYYMMDD') = to_char(last_day(add_months((trunc(sysdate)+3),-1)),'YYYYMMDD') , etc., but all of them do not work.
    Also i tested the clause with select ... from dual, e.g.
    select eff_date from
    select last_day(add_months((trunc(sysdate)+3),-1)) eff_date from dual
    where eff_date = last_day(add_months((trunc(sysdate)+3),-1))
    This work's !
    A cross check on Oracle 9.2.0.8.0: it works as expected !
    Thanks in advance for your effort.
    Regards, Konrad

    a little simulation of your formula
    select the_date,last_day(add_months((trunc(the_date) + 3),-1)) eff_date
      from (select to_date('20130224','yyyymmdd') + level - 1 the_date
              from dual
            connect by level <= 7
           )reveals you might have been querrying future rates
    THE_DATE   EFF_DATE 
    24.02.2013 31.01.2013
    25.02.2013 31.01.2013
    26.02.2013 28.02.2013  /* future date */
    27.02.2013 28.02.2013  /* future date */
    28.02.2013 28.02.2013  /* current date */
    01.03.2013 28.02.2013
    02.03.2013 28.02.2013Regards
    Etbin

  • Function in where clause being executed in subquery

    Oracle version 9.2.0.8
    I have a query of the form
    select cola
          ,colb
          ,expensive_function(colb) as colc
      from t
    where cola between 1 and 100This query returns 100 rows very fast.
    When I try to specify a where clause that uses the result of the expensive function the query takes 60 times longer (60 secs). Table t has a million rows.
    Long Query:
    select *
      from (
        select cola
              ,colb
              ,expensive_function(colb) as colc
          from t
         where cola between 1 and 100) t
    where colc = 'XXX'Could it be that Oracle is executing the function for each row in table t? I only want the function executed on the resultset but I can't seem to get it to work.
    Have tried many different hints and forms of the query without success, e.g.
    select *
      from (
        select cola
              ,colb
          from t
         where cola between 1 and 100) t
    where expensive_function(colb) = 'XXX'
    select /*+ NO_PUSH_PRED(t) */ *
      from (
        select cola
              ,colb
          from t
         where cola between 1 and 100) t
    where expensive_function(colb) = 'XXX'Message was edited by:
    SamB

    <s></s>Compare planing of two SQL, and post what is difference?
    @?/rdbms/admin/utlxplan
    explain plan for
    select cola
          ,colb
          ,expensive_function(colb) as colc
      from t
    where cola between 1 and 100
    @?/rdbms/admin/utlxpls
    explain plan for
    select *
       from (
        select cola
              ,colb
              ,expensive_function(colb) as colc
          from t
         where cola between 1 and 100) t
    where colc = 'XXX'
    @?/rdbms/admin/utlxpls
    explain plan for
    select cola
          ,colb
      from t
    where cola between 1 and 100
        and expensive_function(colb)='XXX'
    @?/rdbms/admin/utlxpls                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Dead line block is not getting executed

    Hi,
    I configured BPM scenario to collect messages from one interface and create IDOCs in ECC.i configured with following steps
    Start
    Block(start of Block)
    Loop(While 1=1)
    receive
    container step(to create multiline container)
    endloop
    Exception branch
    Deadline branch(time 1 minute with control step)
    End block
    Transformation
    send.
    But deadline branch is not getting executed.its going to endless loop.
    anybody got idea about the problem?

    Make sure that:
    1. your deadline branch has a control step raising the exception (and this exception branch could be empty, since it will only end the block; you can create another exception handler for specific application exceptions);
    2. all the exception handlers are defined in Block step;
    3. your correlation container is properly started and used by receive step (with the right fields being used for each correlation string).
    And as best practices, make sure that:
    1. your correlation is defined as local correlation in the Block step;
    2. your loop step contains only the receive step (which starts process) and a container operation of type append, which appends the received message into a multiline container (do all mappings after the loop is complete).
    Finally, save and activate your changes, go into SXI_CACHE transaction and check the returncode your BPM; it should be zero. Otherwise, there is something wrong with it.
    Regards,
    Henrique.

  • In web.xml which tag executes first.

    Hi All,
    Could any one please tell in web.xml whether Filter tag gets execute first or Security-Constraint tag?
    Thanks,
    Swapna Soni.

    In web.xml <web-app> is the root tag the container loads the web.xml when ever the application is deployed or when ever the server is started or restarted or redeployed the application In the same sequence as defined in the sun xmlschema

  • JSP, Data Web Bean, BC4J: Setting the where clause of a View Object at run time

    Hi,
    I am trying to develop a data web bean in which the where clause of a View Object will be set at run time and the results of the query then displayed.
    My BC4J components are located in one project while the coding for the data web bean is in another project. I used the following code bu t it does not work. Could you please let me know what I am doing wrong?
    public void populateOSTable(int P_EmpId)
    String m_whereString = "EmpView.EMP_ID = " + P_EmpId;
    String m_OrderBy = "EmpView.EMP_NAME";
    oracle.jbo.ApplicationModule appModule = null;
    ViewObject vo = appModule.findApplicationModule("EMPBC.EMPAppModule").findViewObject("EMPBC.EMPView");
    vo.setWhereClause(m_whereString);
    vo.setOrderByClause(m_OrderBy);
    vo.executeQuery();
    vo.next();
    String empName numAttrs = vo.getAttribute(EmpName);
    System.out.println(empName);
    Thanks.

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by JDev Team (Laura):
    Here is how I have usually done mine:
    1. In the JSP, use a RowsetNavigator bean to set the where clause and execute the query.
    2. Use a custom web bean to process the results of the query (print to HTML).
    for example:
    <jsp:useBean class="oracle.jbo.html.databeans.RowsetNavigator" id="rsn" scope="request" >
    <%
    // get the parameter from the find form
    String p = request.getParameter("p");
    String s = request.getParameter("s");
    // store the information for reference later
    session.putValue("p", p);
    session.putValue("s", s);
    // initialize the app module and view object
    rsn.initialize(application,session, request,response,out,"wt_bc_WT_bcModule.wtjoinView");
    // set the where clause string
    String theclause = "presname = '" + p + "' AND slideno=" + s;
    // set the where clause for the VO
    rsn.getRowSet().getViewObject().setWhereClause(theclause);
    rsn.getRowSet().getViewObject().executeQuery();
    rsn.getRowSet().first();
    %>
    </jsp:useBean>
    <jsp:useBean class="wt_bc.walkthruBean" id="wtb" scope="request" >
    <%
    // initialize the app module and VO
    wtb.initialize(application,session, request,response,out,"wt_bc_WT_bcModule.wtjoinView");
    wtb.render();
    %>
    In this case, the render method of my custom web bean mostly gets some session variables, and prints various content depending on the session variable values.
    Hope this helps.
    </jsp:useBean><HR></BLOCKQUOTE>
    Laura can you give the code of your walkthru bean? i wna't to initialize a viewobject, set the where clause and give that viewobject back to initialize my navigatorbar.
    Nathalie
    null

  • Where clause as a Paramter?

    So i am using a view for my report and my question is can i have a where clause parameter
    select * from vw_rpt_inv_report
    where=@where?
    The reason i want to use that is when my report is executed my view has 28 columns right so a user should be able to use any column from my report as a parameter.
    Does that make any sense ?
    I did some research and i found this as a solution :
    declare @whereclause nvarchar(1000)
    set @whereclause= 'select * from vw_rpt_inv_standard_format'
    select i.*, L.COMPANYNAME, L.LOCATIONNAME, L.ADDRESSLINE2, L.CITY, L.STATE, L.COUNTRY, L.ZIPCODE
    FROM VW_RPT_INV_STANDARD_FORMAT I
    JOIN LOCATION L ON L.LOCATIONID=I.LOCATIONID
    WHERE ' + @whereclause '
    When i try to run the report i get an error
    ORA-06550: line 1, column 9:
    PLS-00103: Encountered the symbol "@" when expecting one of the following:
    begin function package pragma procedure subtype type use
    <an identifier> <a double-quoted delimited-identifier> form
    current cursor
    The symbol "@" was ignored.
    ORA-06550: line 1, column 36:
    PLS-00103: Encountered the symbol "" when expecting one of the following:
    := ; not null default character
    I am using ORACLE AS my Database for creating reports on MS SSRS 2008.
    Can anyone help me ?

    Okay i am brand new to this so i am totally lost.
    What i am trying to do is i have a view which is my dataset right
    select * from vw_inv_report.
    once my report is done its deployed on a webservice.
    I have a report built on a query and I want to be able to send a parameter (@theWhere) that is a string which is a where clause (WORKORDERNUMBER LIKE '1563514%') and locationid in(63) these strings can vary depending on what columns the user selects and what operators they want to use. Generation of proper SQL for the where clause has been verified, I just need to be able to pass these, is there any way to do this...see example query below and how I was planning on using the @theWhere variable...
    So can i use
    declare @where nvarchar(1000)
    declare @clause nvarchar(5000)
    set @where= '(WORKORDERNUMBER LIKE '1563514%') and locationid in(63) '
    set @clause =
    'select i.*, L.COMPANYNAME, L.LOCATIONNAME, L.ADDRESSLINE2, L.CITY, L.STATE, L.COUNTRY, L.ZIPCODE
    FROM VW_RPT_INV_STANDARD_FORMAT I
    JOIN LOCATION L ON L.LOCATIONID=I.LOCATIONID
    WHERE ' + @whereclause
    EXEC
    @clause
    becuase when i run it i get this error now
    ORA-06550: line 1, column 9:
    PLS-00103: Encountered the symbol "@" when expecting one of the following:
    begin function package pragma procedure subtype type use
    <an identifier> <a double-quoted delimited-identifier> form
    current cursor

  • How to use multiple search conditions in the where clause

    Hi,
    Below is my query
    /****** Script for SelectTopNRows command from SSMS  ******/
    SELECT distinct 
    ctacct,sum(GLMN02)
      FROM [ODS].[Staging].[tODS_INF_GLPCT]
      inner join 
      [ODS].[Staging].[tODS_INF_GLPGL] ON tODS_INF_GLPCT.CTPAGE = tODS_INF_GLPGL.GLPAGE
      where 
      CTACCT like '[0-9][0-9][0-9]-[0-9][0-9][0-9]-63020-4110%'
    This one gives me the exact result i want, now if i add one more to my where clause like this
    /****** Script for SelectTopNRows command from SSMS  ******/
    SELECT distinct 
    ctacct,sum(GLMN02)
    --,ctdesc,CTPAGE
    --SUM(GLMN02)
      FROM [ODS].[Staging].[tODS_INF_GLPCT]
      inner join 
      [ODS].[Staging].[tODS_INF_GLPGL] ON tODS_INF_GLPCT.CTPAGE = tODS_INF_GLPGL.GLPAGE
      where 
      CTACCT like'[0-9][0-9][0-9]-[0-9][0-9][0-9]-63020-4110%' or
      CTACCT like '[0-9][0-9][0-9]-[0-9][0-9][0-9]-63020-4115%'
    This query doesnt give me the exact values instead it gives me all the weird values.Can someone please help me with how to work on this where clause?
    Thanks

    Hi Patrick,
    This is what i ve tried earlier and it isnt working .If i use the first query
    /****** Script for SelectTopNRows command from SSMS  ******/
    SELECT distinct 
    ctdesc,SUM(GLMN02)
    --,ctdesc,CTPAGE
    --SUM(GLMN02)
      FROM [ODS].[Staging].[tODS_INF_GLPCT]
      inner join 
      [ODS].[Staging].[tODS_INF_GLPGL] ON tODS_INF_GLPCT.CTPAGE = tODS_INF_GLPGL.GLPAGE
      where 
     CTAcct LIKE '[0-9][0-9][0-9]-[0-9][0-9][0-9]-63020-4110%'
       --OR
       --CTAcct LIKE '[0-9][0-9][0-9]-[0-9][0-9][0-9]-63020-4115%'
      and GLYEAR = 2014
      and CTDESC = 'Sales'
      group by ctdesc
    The result set is 
    Sales                        
    -182273.96
    And if i use the second query
    SELECT distinct 
    ctdesc,SUM(GLMN02)
    --,ctdesc,CTPAGE
    --SUM(GLMN02)
      FROM [ODS].[Staging].[tODS_INF_GLPCT]
      inner join 
      [ODS].[Staging].[tODS_INF_GLPGL] ON tODS_INF_GLPCT.CTPAGE = tODS_INF_GLPGL.GLPAGE
      where 
     CTAcct LIKE '[0-9][0-9][0-9]-[0-9][0-9][0-9]-63020-4110%'
     OR
       CTAcct LIKE '[0-9][0-9][0-9]-[0-9][0-9][0-9]-63020-4115%'
      and GLYEAR = 2014
      and CTDESC = 'Sales'
      group by ctdesc
    The result set i get is 
    Sales                        
    -1455441.08
    And i verified that  CTAcct LIKE '[0-9][0-9][0-9]-[0-9][0-9][0-9]-63020-4115%'
    this second line of where clause has not desc as Sales.
    I am not sure whats causing the difference in the values.
    Can you please help me with this?
    Thanks

  • Where clause on right side table of a left join

    I was told by someone that a where clause on the right side table of a left join is bad SQL.  I have looked around and found a great article for DB2.  I am not sure if this is 100% correct for SQL Server so would like to find a good detailed
    article on the topic.  
    Thank  you

    I was told by someone that a where clause on the right side table of a left join is bad SQL.  I have looked around and found a great article for DB2.  I am not sure if this is 100% correct for SQL Server so would like to find a good detailed
    article on the topic.  
    Thank  you
    I'm going to be blunt here so if you get offended easily please stop reading now.
    That has got to be some of the dumbest advice I've seen in a while.  Such a query serves a specific purpose, there's no good or bad to it.  Following is a classic example:
    select distinct
    CustomerID
    from Customer as c
    left join Orders as o
    on c.CustomerID = o.CustomerID
    and o.OrderDate > dateadd(day, -90, getdate())
    where o.CustomerID is null
    The above hypothetical query, which includes a where clause which targets the right table in a left join, returns all customers which have not placed an order in the past 90 days.  It's a perfectly valid query which serves a key business purpose and
    I challenge anyone to justify why they claim it is "bad SQL".
    Such a query will execute efficiently given appropriate indices.  There's simply no justification for such a blanket statement about where clauses and outer joins.

  • Problem in Dynamic Where clause..

    Hello All,
    I have a requirement in which i have to do a select statement where (Field1 = 'X') and (Field2 = 'A' or Field2 = 'B').
    But if i write it directly,
    select * from Ztable into table itab where Field1 = 'X' and Field2 = 'A' or Field2 = 'B'.
    Then I am not getting the expected result.
    instead i need something which tells the where clause to do OR operation first and then AND operation..
    Any ideas ??
    Thanks in advance.
    Tatvagna Shah.

    Hi,
    Please try this.
    select *
    from Ztable
    into table itab
    where Field1 = 'X' and ( Field2 = 'A' or Field2 = 'B' ).
    Regards,
    Ferry Lianto

  • Date functions in WHERE clause? HELP

    The following two queries are identical except for how I supply the date values in the where clause, yet the first query using the a custom my_date function runs 30x slower than the one using the TO_DATE() function. Both return DATE types...any reason for the difference?
    SELECT * from outcomes
    WHERE start_time >=fn_my_date('START_MONTH')
    AND start_time < fn_my_date('END_MONTH')+1
    -- This runs 30x faster--
    SELECT * from outcomes
    WHERE start_time >=TO_DATE('08/01/2001','MM/DD/YYYY')
    AND start_time < TO_DATE('08/31/2001','MM/DD/YYYY')+1
    On the flip side, I've also experienced queries running slower using the TO_DATE() function vs the LAST_DAY(sysdate) for equivalenet dates.
    null

    I haven't seen the message coming up when using LENGTH or SUBSTR, but every time I connect to a database or attempt to change my preferences (including the "NLS Parameters: Comp" preference), this appears.
    You are attempting to set the preference you should be to switch this from ANSI to something else, but SQL Developer is ignoring the preference setting (which I think is a bug).
    A way to set the NLS_COMP to something else is to use something like "alter session set nls_comp = BINARY;". Note that changing any preference after that appears to overwrite this and you need to do this for each new connection you start.

  • Tree Layout  and a Where Clause

    I have built a uix application using Jdev (10.1.2) + Jheadstart (10.1.2). I followed Jheadstart for ADF developer’s guide (10.1.2) for creating a page with a recursive tree, tree layout style and it works well. Now I need to apply a where clause, programmatically, on the view I am using for generating the tree and the problem is that the where clause 'gets lost' on the child view before the page is displayed. How do I fix this?

    rbackmann wrote:
    And the page_id_1 is a field in the table (SORRY EXAMPLE BAD NAMING CONVENTIONS) that IS VARCHAR
    and houses a comma seperated list of page numbers ie 28,29, 30Okay, I was wrong about the field name :(
    Carefully examine the query, expecially the INSTR line. Get the values in both the column and the bind variable and make sure they are what you think they are.
    The example on the other post might have failed because you were equality comparing the column value to '28' when it might have been a csv with commas unless you changed it (something worth trying).
    On 4th look I may (or may not) have something. PAGE_ID_1 is a VARCHAR2, while the 28 you compared it to was a number. Its a long shot, but maybe SQL is trying to convert the csv field to a number, failing to raise an error message where you can find it, and failing for that reason. Try using '28' on the equality test.
    Edited by: riedelme on May 8, 2009 6:03 AM

  • Changing the where clause

    Hi all,
    Can anyone suggest an appropriate answer for this
    I want to change the where condition in Reports (Developer 2000) dynamically (in runtime)
    Thank you

    Hi,
    Try this in you pre-query trigger.
    -- if you want to add to the where clause do this
    -- first store the current where clause
    C_WHERE := get_block_property('your_block', default_where);
    IF <condition> THEN
         c_where := 'desired_condition'||' AND '||C_where;
    -- append your condition to the existing one.
    END IF;
    set_block_property('your_block', default_where,c_where);
    or if you want to totally replace it just use the set_block_property in the trigger.
    Hope this helps.
    Bob

  • HT4528 Howdy.  I keep getting a message stating that my apple ID has been disabled.  I recently contacted my CC company, AMEX, for several fradulent iTune charges, which is probably where the problem first originated.  How can I resolve this issue?

    Howdy.  I keep getting a message stating that my apple ID has been disabled.  I recently contacted my CC company, AMEX, for several fradulent iTune charges, which is probably where the problem first originated.  How can I resolve this issue?

    I had to dispute several unauthorized charges to itunes. My apple id was disabled after that. I followed jarnoldus's (older post) advice and it worked. Im duplicating his entry here with a few modifications. I hope this works for you.
    1. Go to https://getsupport.apple.com
    2. Choose your product (mine was ipad)
    3. Click the "iTunes, App Store or iBooks" icon
    4. Click "Apple ID account security"
    5. Type in "apple id has been disabled"
    6. Choose your country (mine was US)
    7. Choose the "talk to apple support now" option
    8. Provide the info they request (name, email, phone number)
    9. They will call you right away.
    Explain your apple id has been disabled. The rep will connect you to an iTunes rep. He/she will look up your account. You will be required to answer your 3 security questions. You MUST get a minimum of 2 correct. If you succeed they will enable your id. Good luck!

  • Beginner: Getting syntax error on WHERE clause in SELECT

    I'm very new to php and mySQL.  Am using DW master/detail to generate to basic code I need.  One thing I need to do is modify a select statement in the master to include a WHERE clause to limit the selection to a particular value in one field.
    I'm getting a syntax error with the WHERE clause I'm adding to the map select statement.
    This is the portion of the error message showing the error location:
    'WHERE Group='Community' LIMIT 0, 10'
    The php that generated the select is:
    $query_maps = "SELECT * FROM tblmaps ORDER BY tblmaps.DispSeq";
    $query_limit_maps = sprintf("%s WHERE Group='%s' LIMIT %d, %d", $query_maps, $selectGroup, $startRow_maps, $maxRows_maps);
    This approach to creating the select statement is from the code generated for the master page.  It adds the LIMIT clause.  All I did was add the "WHERE Group='%s' and the $selectGroup variable which comes from earlier code.  You can see that the $selectGroup variable is equal to the "Community: group.
    I've scanned the web to see what syntax error I might be making but haven't found anything that explains it.
    The full resolved select statement is:
    SELECT * FROM tblmaps ORDER BY tblmaps.DispSeq WHERE Group='Community' LIMIT 0,10
    What am I not seeing?
    Tom

    Thanks.  Make sense but changing that didn't help.
    Here's the error message I'm getting:
    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Group='Community' ORDER BY tblmaps.DispSeq LIMIT 0, 10' at line 1
    The full select (from a debugging ECHO I inserted) is:
    SELECT * FROM tblmaps WHERE Group='Community' ORDER BY tblmaps.DispSeq LIMIT 0, 10
    Note that when I take the WHERE clause out, there is no syntax error.

Maybe you are looking for