Is it possible to avoid the or in this sql?

Hello

I have a subquery to work which is givng me some performance issues... (I've changed the names of tables and columns).
select h.name, h.age, h.sex, h.height, h.occupation
  from human h
 where h.newest = 'Y'
   and h.death_date is null
   and (i_department_ids is null or
       (i_department_ids is not null and
       h.unique_id in
       (select m.unikt_id
            from departments d
           where d.department_id like i_department_ids)) and
       (INSTR(i_apartment_numbers, aki.apartment_id) > 0 or
       i_apartment_numbers is null))
i_department_ids and i_apartment_numbers can be null at the time, but not both at the same time, it is also checked. My problem is with two operators OR . As soon as I have the OR, a full scan is completed. A search can take as long as 13 seconds. Without the operators OR there 0,0062 dry. I use the OR operators because, if the input variable is zero, the condition must return True.

If we scan a way I can avoid using the two operators OR , so I'll avoid the fulltable?

Thank you very much

William

A shooting blind. Try this.

 select h.name, h.age, h.sex, h.height, h.occupation
   from human h
  where h.newest = 'Y'
    and h.death_date is null
    and case when i_department_ids is null then 1
             when i_department_ids is not null and
                     h.unique_id in
                     (select m.unikt_id
                          from departments d
                         where d.department_id like i_department_ids))
                           and INSTR(nvl(i_apartment_numbers,aki.apartment_id), aki.apartment_id) > 0) then 1
             else 0 end = 1
 

Published by: Karthick_Arp on November 3, 2010 05:42

Included the Toon conditino aswell.

Tags: Database

Similar Questions

  • Error: "it is not possible to disable the connection at this time. "This connection may be using one or more protocols that don't support Plug-and-play, or it may have been initiated by another user or the system account.

    Original title: unable to disable my lan connection

    Remember - this is a public forum so never post private information such as numbers of mail or telephone!

    Ideas:

    • I turn off my connection to the local network, it is showing message.

      It is not possible to disable the connection at this time. This connection may be using one or more protocols that don't support Plug-and-play, or it may have been initiated by another user or the system account.

      Please answer soon

      You have problems with programs

    • Error messages
    • Recent changes to your computer
    • What you have already tried to solve the problem

    Hi MVTDA,

    You can try the following methods and check to see if it helps:

    Method 1:

    a. Click Start and select run, type cmd and click OK.

    b. type net stop cryptsvc and press ENTER.

    c. type ren %systemroot%\System32\Catroot2 oldcatroot2, and then press the Enter key.

    d. restart the computer.

    e. open new command prompt and Type net start cryptsvc, and press ENTER.

    Method 2:

    If the same problem persists then you can try to uninstall the network drivers and check.

    a. click the Start button. Select run, type devmgmt.msc and press OK.

    b. Select the network card and right click on it.

    c. now, select Properties.

    d. in the Properties window, on the driver tab, click Uninstall.

    e. After you have uninstalled the drivers, restart the computer.

    Hope this information is useful.

    Jeremy K
    Microsoft Answers Support Engineer
    Visit our Microsoft answers feedback Forum and let us know what you think.

    If this post can help solve your problem, please click the 'Mark as answer' or 'Useful' at the top of this message. Marking a post as answer, or relatively useful, you help others find the answer more quickly.

  • is it far to disable the shortcut ctrl-alt-tab on windows 7 (cycle between windows) to avoid the substitution of this same shortcut (indented) in excel?

    is it far to disable the shortcut ctrl-alt-tab on windows 7 (cycle between windows) to avoid the substitution of this same shortcut (indented) in excel?

    Hello
     
    The feature you're talking about is the default value of design in Windows 7. If you have comments or suggestions, you can post your query to the Windows 7 feedback forum.

     
  • Is it possible to use the default value as sql expression in obiee 11g report?

    Hi all

    Is it possible to use the default value as sql expression in obiee 11g report?. Actually what I'm trying to make is that we send an ibot users. They want the same default values that are assigned in the command prompt in the report. So when we send the ibot it shows the report for default values assigned in the report criteria which is obsolute. As a solution, I kept the report in a dashboard page and send the dashboard like ibot page. But the problem here is that I can send only pdf format. Is it possible to do so at the level of the report (without using session variables). I want something like that

    Date between Date ' @{PV1} {Timestampadd (SQL_TSI_DAY,-90, CURRENT_DATE)} and Date ' @{PV2} {CURRENT_DATE}

    Thanks in advance

    Thank you

    AJ

    http://www.w3.org/2001/XMLSchema-instance"container ="http://www.w3.org/2001/XMLSchema"xmlVersion ="201201160' xmlns:sawx="com.siebel.analytics.web/expression/v1.1" > "

    "Question time '." Date '.

    "Question time '." Date '.

    BOX WHEN (DAYOFWEEK (cast (max (CURRENT_DATE) date)) = 1) THEN TIMESTAMPADD (SQL_TSI_DAY,-2, cast (max (CURRENT_DATE) as date)) WHEN (DAYOFWEEK (cast (max (CURRENT_DATE) date)) = 2) THEN TIMESTAMPADD (SQL_TSI_DAY,-3, cast (max (CURRENT_DATE) as date)) WHEN (DAYOFWEEK (cast (max (CURRENT_DATE) date)) = 3) THEN TIMESTAMPADD (SQL_TSI_DAY,-4, cast (max (CURRENT_DATE) as date)) WHEN (DAYOFWEEK (cast (max (CURRENT_DATE) date)) = 4) THEN TIMESTAMPADD (SQL_TSI_DAY-5 (, cast (max (CURRENT_DATE) date)) WHEN (DAYOFWEEK (cast (max (CURRENT_DATE) date)) = 5) THEN TIMESTAMPADD (SQL_TSI_DAY,-6, cast (max (CURRENT_DATE) as date)) WHEN (DAYOFWEEK (cast (max (CURRENT_DATE) date)) = 6) THEN TIMESTAMPADD (SQL_TSI_DAY, 0, cast (max (CURRENT_DATE) as date)) WHEN (DAYOFWEEK (cast (max (CURRENT_DATE) date)) = 7) THEN TIMESTAMPADD (SQL_TSI_DAY-1, cast (max (CURRENT_DATE) date)) END

  • In SQL Developer, is it possible to send the results of a sql statement?

    In SQL Developer, is it possible to send the results of a sql statement?

    Right-click on the query results pane, select "Export data" in the context menu, then select "xls".

  • How to avoid the SEPARATE in OBIEE SQL

    Hello...

    For the issue I posted previously...
    Problem with the data type LONG in responses

    I executed the query into a FROG, and I've identified the error because of what this error is coming... because of SEPARATE...
    I took care to avoid this column in ORDER BY putting order on another column...

    Now my question is how to avoid the DISTINCT clause in SQL generated by OBIEE...
    If the first column of criteria is then it avoids the SEPARATE... but if I use measure... Group of will come... and group of should not be used here...

    If it's done... my problem is solved...
    Of course... I get duplicate rows...

    However, I want the answer how avoid SEPARATE?
    Waiting for the response from your...

    Thanks and greetings
    Kishore Guggilla

    Kishore,

    In the physical layer, open the properties of physical catalog and in the features tab find DISTINCT_SUPPORTED and remove the check box value.

    who removed separate in each query generated for this database.

    -Madan

  • Is it possible to avoid the access "BY INDEX ROWID'?

    Hello

    I run a query for the primary key of a table with a text index on a column of text, something like

    Pkey SELECT FROM table WHERE CONTAINS (text, 'foobar') > 0.

    As expected, the index is scanned for the corresponding ROWID and then the rows are retrieved (BY INDEX ROWID).

    I wonder if its possible to include the primary key in the text index column, so that the table must not be access at all when querying for the primary key (this is possible with regular index).

    I tried
    1. creating a Composite field Index (i.e. including the primary key column in the FILTER clause BY index)
    2. create a SURLABASEDESDONNEESDUFABRICANTDUBALLAST section on pkey
    3. creating a MONTANA section on pkey

    In all cases, the lines were always accessible by ROWID.

    Any ideas?

    If you 11.2, you can try using the Interface of the result value. This query system (based on XML) will allow you to retrieve values SURLABASEDESDONNEESDUFABRICANTDUBALLAST directly from the text index without accessing the base table.

    In previous versions, unfortunately I don't think that there is a way to do it without going through the base table.

  • is it possible to get the result of this

    Here is the code example
    --------------------------------------------------------------------------------------------------------------------------------------------
    declare
    topic_name_out SYS_REFCURSOR;
    topic_id_out SYS_REFCURSOR;

    Start
    PG_DTLS_PKG. LOGICAL_CATEGORIES('0',topic_name_out,topic_id_out);
    dbms_output.put_line ('topic_name_out, topic_id_out');
    end;
    --------------------------------------------------------------------------------------------------------------------------------------------

    topic_name_out, topic_id_out are two ref cursor that retrieves the multi line exit of the packaging.
    I want to see the dbms_output for this... is possible to do it in writing then...
    "dbms_output.put_line ('topic_name_out, topic_id_out');" throws an error.

    Try something like this:

    var topic_name_out REFCURSOR;
    var topic_id_out REFCURSOR;
    begin
    PG_DTLS_PKG.LOGICAL_CATEGORIES('0',:topic_name_out,:topic_id_out);
    end;
    /
    print topic_name_out
    print topic_id_out 
    
  • Avoiding the clues in this query

    Hi I have the following query that produces this execution plan.
    My question is that, given that the optimizer made a complete analysis of table ((je pense que son dû de se connecter par avant dans la requête,...))
    because the full table scan happens why additonally go to the index. avoid access index here how we can save additional time to index will allow you to join.
    I can't help but full table scan because using connect by clause.

    I want to remove access from the index because the optimizer will still choose a full table scan for table prod_dim to step 3
    SELECT  prod_dim_nb, prod_type_nm, prod_fam_cd, prod_cd,
                          prod_shrt_nm, prod_full_nm,
                          LTRIM (SYS_CONNECT_BY_PATH (prod_cd, '/'),
                                 '/'
                                ) product_hierarchy
                     FROM prod_dim
                    WHERE prod_fam_cd = 'ABC'
               START WITH prod_dim_nb = prnt_prod_dim_nb
               CONNECT BY NOCYCLE prnt_prod_dim_nb = PRIOR prod_dim_nb
               
       
    PLAN_TABLE_OUTPUT
     
    -----------------------------------------------------------------------------------------------
    | Id  | Operation                      | Name         | Rows  | Bytes | Cost (%CPU)| Time     |
    -----------------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT               |              |     3 |   258 |     2   (0)| 00:00:01 |
    |*  1 |  FILTER                        |              |       |       |            |          |
    |*  2 |   CONNECT BY WITH FILTERING    |              |       |       |            |          |
    |*  3 |    TABLE ACCESS FULL           | PROD_DIM     |     1 |    86 |     3   (0)| 00:00:01 |
    |   4 |    NESTED LOOPS                |              |       |       |            |          |
    |   5 |     CONNECT BY PUMP            |              |       |       |            |          |
    |   6 |     TABLE ACCESS BY INDEX ROWID| PROD_DIM     |     3 |   258 |     2   (0)| 00:00:01 |
    |*  7 |      INDEX RANGE SCAN          | PROD_DIM_FK2 |     3 |       |     1   (0)| 00:00:01 |
    -----------------------------------------------------------------------------------------------
    
    
       
    is my understanding... do we really need to go to the index when its goes not for full access to the table in step 3 in the plan? How to avoid the 6 and 7?

    Published by: raj_fresher on September 3, 2009 15:52

    I checked all the columns in the select clause, and they are not null columns

    But the optimizer does not know that (unless you have NO constraints of NULL in all your columns).

    but he's still going for full table access

    This is not surprising. Your table is extremely low (or at least the optimizer thinks that Yes). It's probably going to be faster for analysis complete one or two blocks from the table to use multiple indexes.

  • the analysis of this sql help

    Hello

    I need help in the analysis of this query effectively

    Field1, Field2
    1, a
    2, a
    b 3,
    b 3,
    4, c.


    I want my query to return 1, a and 2 a because Field2 appeared several times with different values of field1. Please advice. It is a discrepancy report.
    WITH tab AS
      ( SELECT 1 field1,'a' field2 FROM dual
    UNION ALL
       SELECT 2 field1, 'a' field2 FROM dual
    UNION ALL
       SELECT 3 field1, 'b' field2 FROM dual
    UNION ALL
       SELECT 3 field1, 'b' field2 FROM dual
    UNION ALL
       SELECT 4 field1, 'c' field2 FROM dual
      )
     SELECT field1,
      field2
       FROM
      (SELECT field1                                ,
        field2                                      ,
        COUNT(field1) over (partition BY field2) cn1,
        COUNT(DISTINCT field1) over (partition BY field2) cn2
         FROM tab
      )
      WHERE cn1=cn2 and cn1!=1
    

    Ravi Kumar

  • Is it possible to avoid the "" Record 1: discarded - failed all the clauses WHEN. ' "

    When using when clause sqlldr. It generates too many lines as below-

    "Record 1: discarded - failed all WHEN clauses."

    "" Sheet 2: discarded - failed all WHEN clauses. ""

    "" Record 3: discarded - failed all WHEN clauses. ""

    ' Record 4: discarded - failed all WHEN clauses. »


    If she rejects millions of records. in the log file, it shows millions of lines. size of the log file is too big.

    He takes seriously the space on my hard drive.

    at the same time I need other details in the log-file

    125466 lines loaded successfully.

    0 rows not loaded due to data errors.

    65523 lines not loading because all WHEN clauses were failed.

    0 rows not populated because all fields are null.

    Run started on Fri Jan 23 12:27:16 2015

    Run finished Fri Jan 23 12:27:18 2015

    Time was: 00:00:01.70

    Time processor was: 00:00:01.16

    None of the parameters of SQLLDR to avoid these lines...?

    Oracle 11.2.0.1.0

    Windows 2008

    Although you can use SILENT = RELEASES in your SQL * Loader command line to remove the output to the screen, as much as I know there is no way to remove in your log file.  However, if you use an external table, you can use NOLOGFILE, but which eliminates the whole logfile, not only releases and requires that the data file is on the server, not the client.

  • How to avoid the duplicateConnection on a sql database?

    I have a database of newspapers that I have access to both c ++ and QML.

    While everything works correctly logs qml page complained about a double connection whenever it is open, which in turn spam log file.

    In c ++, the database is initialized once, with db being QSqlDatabase:

    QString databaseFileName = QDir::homePath() + QDir::separator() + "logs.db";
    db = QSqlDatabase::addDatabase("QSQLITE", "loggerDatabase");if (!db.open()) {        printf("Critical: Error opening logs database\n");}
    

    QML, I use a very simple way to view the contents of the db: A GroupDataModel with a data source.

    I have set up a query on the data source and fill in the datamodel with the result:

    DataSource {
       id: dataSource
       source: loggerService.dbPath
       onDataLoaded: {
          dataModel.clear();
          dataModel.insertList(data);
       }
    }
    

    I assume that the data source uses SQLDataAccess to open a connection to the db, and db already has a connection there is a complaint:

    QSqlDatabasePrivate::addDatabase: duplicate connection name ' / accounts/1000/appdata/x/data/logs.db' old deleted connection.

    How can I avoid this?

    I've given up trying through QML and just dynamically added the groupDataModel of c ++.

    I was getting the same error, without reason.

  • Is it possible to purchase the CS 6 this version without having to pay a monthly subscription

    Is there a way to pay for a full copy of DW SC 6 without having to get the version of DW CC and pay a stupid monthly fee?

    I have CS 5.5 but it works well with Windows 8

    Creative Suite 6

    Click on buy

    I want to buy: upgrade

    I'm owner: Dreamweaver CS5.5

    Make your purchase.

    Just keep in mind that no further development is done on CS6. It is 3 years old software producing 3 year old code. Basically, what you see is what you get. No other upgrade is possible.

  • It is possible to solve the problem with this update?

    I have an iPad Air bricks after setting date from 1970. Solutions-battery DFU & drain do not work for me...

    Make a Genius Bar appointment. The article you have linked, mentions the software update will prevent it from taking place, but if you already have the number, you must contact Apple technical support. -AJ

  • Is it possible to upgrade the GPU in this laptop HP DV7 - 2043cl

    I searched on the net, and I'm mixed responses.  I just got a laptop additional thanks to an agreement of craigslist and I was wondering what, if any update I could do for her. I did a little research and if I could upgrade it seems I might be able to put a 5850 in this machine without having to replace anything else.

    Hello

    I edited my response, your machine supports only the M96 cards.

    Kind regards.

Maybe you are looking for

  • Satellite U305 - CD/DVD drive not recognized

    Hello My laptop does not recognize the CD/DVD drive and when I press the Open button to put in a disk, it opens, but the light and it makes a noise as if it worked. Whenever I go to control panel, system, and then to Device Manager, the computer says

  • Qosmio x 300 - no option of dual display using analog

    Have plugged an analog monitor. I can get an image on the analog monitor or laptop LCD, but I can't it to appear on both, i.e. double - extended display either office or clone.I have a Qosmio (a regret since buying it because of all the problems it h

  • 15 - ac120tx: network driver is not install on windows 7 64 bit

    my product id = 15-ac120tx plese send mi good link of the driver lan on my mail please. [Personal information]

  • upgrade of ram 80 G50

    Hey, I have a questions upgrades support g50 - 80 dual channel 2 x 4 GB of ram? What is the frequency of the memory max this notebooks supports? and the ram type low voltage or regular? Thank you!

  • Pavilion dv6836eo: install Windows 7 on a Pavilion

    Before you buy a dvd of Windows 7, I would like to know if it kan be installed on the device. HP Pavilion dv6836eo Entertainment Notebook Thank you for any response