Index (or not) for excluding NULL values in a query

Hello,
I have table that can become very large. The table has a varchar2 column (let's call it TEXT) that can contain NULL values. I want to process only the records that have a value (NOT NULL). Also, the table is continuously expanded with newly inserted records. The inserts should suffer as little performance loss as possible.
My question: should I use an index on the column and if so, what kind of index?
I have done a little test with a function based index (inspired by this Tom Kyte article: http://tkyte.blogspot.com/2006/01/something-about-nothing.html):
create index text_isnull_idx on my_table(text,0);
I notice that if I use the clause WHERE TEXT IS NULL, the index is used. But if I use a clause WHERE TEXT IS NOT NULL (which is the clause I want to use), a full table scan is performed. Is this bad? Can I somehow improve the speed of this selection?
Thanks in advance,
Frans

I build a test case with very simple table with 2 columns and it shows that FTS is better than index access even when above ratio is <= 0.01 (1%):
DROP TABLE T1;
CREATE TABLE T1
           C1 VARCHAR2(100)
          ,C2 NUMBER
INSERT INTO T1 (SELECT TO_CHAR(OBJECT_ID), ROWNUM FROM USER_OBJECTS);
BEGIN
     FOR I IN 1..100 LOOP
          INSERT INTO T1 (SELECT NULL, ROWNUM FROM USER_OBJECTS);
     END LOOP;
END;
CREATE INDEX T1_IDX ON T1(C1);
ANALYZE TABLE T1 COMPUTE STATISTICS
     FOR TABLE
     FOR ALL INDEXES
     FOR ALL INDEXED COLUMNS
SET AUTOTRACE TRACEONLY
SELECT
          C1, C2
     FROM T1 WHERE C1 IS NOT NULL;
3864 rows selected.
real: 1344
Execution Plan
   0      SELECT STATEMENT Optimizer=CHOOSE (Cost=59 Card=3864 Bytes=30912)
   1    0   TABLE ACCESS (FULL) OF 'T1' (Cost=59 Card=3864 Bytes=30912)
Statistics
          0  recursive calls
          0  db block gets
       2527 consistent gets
       3864 rows processed
BUT
SELECT
     --+ FIRST_ROWS
          C1, C2
     FROM T1 WHERE C1 IS NOT NULL;
3864 rows selected.
real: 1296
Execution Plan
   0      SELECT STATEMENT Optimizer=HINT: FIRST_ROWS (Cost=35 Card=3864 Bytes=30912)
   1    0   TABLE ACCESS (BY INDEX ROWID) OF 'T1' (Cost=35 Card=3864 Bytes=30912)
   2    1     INDEX (FULL SCAN) OF 'T1_IDX' (NON-UNIQUE) (Cost=11 Card=3864)
Statistics
          0  recursive calls
          0  db block gets
       5052 consistent gets
       3864 rows processed
and just for comparison:
SELECT * FROM T1 WHERE C1 IS NULL;
386501 rows selected.
real: 117878
Execution Plan
   0      SELECT STATEMENT Optimizer=CHOOSE (Cost=59 Card=386501 Bytes=3092008)
   1    0   TABLE ACCESS (FULL) OF 'T1' (Cost=59 Card=386501 Bytes=3092008)
Statistics
          0  recursive calls
          0  db block gets
     193850 consistent gets
     386501 rows processedHence you have to benchmark you queries with and w/o index[es]

Similar Messages

  • How to query for a NULL value?

    Hi all,
    how can I query for a NULL value in a ViewObject. I tried to set null as where-clause param [setWhereClauseParam(0, null)]. But the created statement looks like this:
    SELECT ...
    FROM ...
    WHERE param = null
    I would expect it to create something like WHERE param IS NULL. I hope anybody has a solution for this.
    Thanks,
    Axel

    I think you should use setWhereClause("COL_NAME IS NULL")
    You could use setWhereClauseParam(0, "NULL"), but only if you have a predefined query similar to: "SELECT X, Y, Z FROM A WHERE X IS :0" (which is a pretty useless query, as you can ONLY set "NULL" as the value for ":0").

  • Condition for excluding Sales value less than or equal to 0

    Hello Experts,
    I have to create condition in the query designer to exclude Sales Value <=0, and that should be applied to all the column values and result values when we put active.
    Can anyone help ?
    Thanks in advance,
    Venky
    Duplicate Post
    Condition for excluding Sales value less than or equal to 0
    Edited by: Arun Varadarajan on Apr 13, 2010 8:57 PM

    Hello Naveen,
    Thanks for quick reply. I have created condition greater than zero and executed report, i can able to eliminate rows with sales value <=0, but we have other columns in the report say Quantity, Backlog... when we run the report without condition the values which showed are same when we put it in active aslo.
    After eliminating few rows which having some quantity value, that value should be deducted from the result of the quantity. I tried with applying apply to results opton, then also there is no change in the result value of the quantity.
    Our requirement is to apply condition to eliminate rows which are sales value <=0 and same the result values of the columns should effect.
    Is it possible in anyway, if yes please specify solution.
    Thanks,
    Venky

  • Exclude NULL values from SUM and AVG calculation

    Hi,
    I have column in report that contains some NULL values. When i perform SUM,MAX,MIN or AVG calculation on this column the NULL values are treated as '0' and included in calculation. Is there any way to exclude them while calculating aggregate functions? 
    As a result MIN calculation on values (NULL,0.7,0.5,0.9) gives me output as 0 when it should have been 0.5 
    Can someone please help ?
    Thanks and Regards,
    Oliver D'mello

    Hi Oliver,
    According to your description, you want to ignore the NULL values when you perform aggregation functions.
    In this scenario, aggregate functions always ignore the NULL values, because their operation objects are non-null values. So I would like to know if you have assigned “0” for NULL values. I would appreciate it if you could provide some screenshots about
    your expressions or reports.
    Besides, we have tested in our environment using  Min() function. The expression returns the minimum value among the non-null numeric values. Please refer to the screenshots below:
    Reference:
    Min Function (Report Builder and SSRS)
    Aggregate Functions Reference (Report Builder and SSRS)
    If you have any question, please feel free to ask.
    Best regards,
    Qiuyun Yu

  • ViewRowImpl.writeXML: not to omit null values

    Hi.
    I want to use writeXML method in ViewRowImpl to get current row's data in XML format. Here is a snippet of my code
            Node rootNode = myViewRowImpl.writeXML(1, XMLInterface.XML_OPT_ALL_ROWS);
            StringWriter sw = new StringWriter();
            try {
                Transformer t = TransformerFactory.newInstance().newTransformer();
                t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
                t.setOutputProperty(OutputKeys.INDENT, "yes");
                t.transform(new DOMSource(rootNode), new StreamResult(sw));
            } catch (TransformerException te) {
                System.out.println("Transformer Exception");
            System.out.println(sw.toString());
    ...The problem is that there are missing tags of attributes which has null value (does not have a value). How to "force" writeXML method or even transformer to output empty tags for attributes that does not have values definied?
    Thx
    Regards

    As per the doc.
    38.7.3.2 Controlling Element Suppression for Null-Valued Attributes
    By default, if a view row attribute is null, then its corresponding element is omitted from the generated XML. Select the attribute on the Attributes page of the overview editor and in the Property Inspector, select the Custom Properties navigation tab and set the custom attribute-level property named Xml Explicit Null to any value (e.g. "true" or "yes") to cause an element to be included for the attribute if its value is null. For example, if an attribute named AssignedDate has this property set, then a row containing a null assigned date will contain a corresponding AssignedDate null="true"/ element. If you want this behavior for all attributes of a view object, you can define the Xml Explicit Null custom property at the view object level as a shortcut for defining it on each attribute.

  • SQL query to not to exclude NULLS

    Hi,
    I have a column in table
    Type
    ABC
    XYZ
         -- NULL
         -- NULLWhen I write sql statement to exclude Type = 'ABC', the query also excluding NULLs. How to avoid (include nulls) that?

    ...or (this is not the best one):
    select * from yourtable
    WHERE nvl2(type,type,'?') != 'ABC'
    select * from yourtable
    WHERE decode(type,null,'?',type) != 'ABC'..it's only for 'educational' purpose (an excuse to show the nvl2 and decode functions)
    or
        select * from yourtable
        where coalesce(type,'?')!= 'ABC'sorry i stop here now.
    select * from yourtable
        where nullif(type,'ABC')= type or type is nullEdited by: user11268895 on Aug 31, 2010 5:10 PM

  • Will substr + not function ignore null values ?

    hi guys
    i have a table test with 1 column named (value) of varchar2 type.
    inside this table, i have 3 rows.
    1) 2255
    2) null
    3) 5522
    when i do select * from test where substr(value,1,1) not in ('3'), it only returns me
    row 1) 2255
    row 3) 5522
    but why doesnt it return me row 2 with null value as well ?
    since substr(null) will generate null. and null is also NOT IN ('3'), why doesnt it shows?
    any ideas guys ?

    Because NULL is unknown.
    By definition you cannot say if unknown is IN or NOT IN anything.
    So you have to account for the unknown however you think appropriate, in your case that would mean saying:
    select * from test where substr(value,1,1) not in ('3') OR value IS NULL;
    [pre]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Replace NULL values from PIVOT query

    Hi,
    I'm querying a table for sales, for some values, when now columns, the finish with a null value. How can I handle these values as 0 (zeros).
    WITH PIVOT_DATA AS (
    SELECT S.ZONE_CODE,Z.ZONE_NAME,S.YEAR,S.PERIOD,S.SALES
    FROM STAT_TABLE_SALES VTA
    JOIN ZONES Z ON S.COMP=Z.COMP AND S.ZONE_CODE=Z.ZONE_CODE
    WHERE S.COMP = '001'
    AND S.BRAND_CODE = '001'
    SELECT *
    FROM PIVOT_DATA
    PIVOT(
    SUM(SALES) FOR (YEAR,PERIOD) IN ((2009,1),
    (2009,2),
    (2009,3),
    (2009,4),
    (2009,5),
    (2009,6),
    (2009,7),
    (2009,8),
    (2009,9),
    (2009,10),
    (2009,11),
    (2009,12),
    (2010,1),
    (2010,2),
    (2010,3),
    (2010,4),
    (2010,5),
    (2010,6),
    (2010,7))
    ORDER BY 14 DESC NULLS LAST;
    This query returns the following:
    COD_ZONA NOM_ZONA 2009_1 2009_2 2009_3
    01 YEDUSIJH. 1382367.75 1559943.27 1441279.64
    02 DO,ASKAK 711897.82 865854.05 1583232.3
    03 ASDFG 130443.03 205409.84 178633.69
    04 OSOIDSD 320118.32 439008.83 409251.18
    05 ODFSDF 300908.21 276301.59 260188.53
    06 CH 242749.65 325196.71 464938.9
    07 SOA 610312.31 606312.93 754569.82
    08 SAN 89426.8 81360.04 61649.27
    09 YP 284487.79 328281.31 267210.85
    10 TC 87043.28 158594.43 85195.8
    11 BAGNN 76778.78 68180.76 118530.04
    12 CRTS 122023.7 143442.21 134744.85
    13 OCC 209992.79 196477.03 185222.14
    14 IDLB
    15 YA 23870.41 4137.33 16660.53
    **These are not all the columns and rows, but this is a piece of what it returns.
    How can I replace these NULLS with 0(zeros).

    Still not sure why nvl shouldn't suit your needs:
    SQL> select ename, nvl (clerk_20, 0) clerk_20, nvl (sal_30, 0) sal_30
      from emp pivot (sum (sal)
               for (job, deptno)
               in ( ('CLERK', 20) clerk_20, ('SALESMAN', 30) sal_30))
    ENAME             CLERK_20          SAL_30
    WARD                     0            1250
    JONES                    0               0
    TURNER                   0            1500
    ADAMS                 1100               0
    ALLEN                    0            1600
    SMITH                  800               0
    CLARK                    0               0
    KING                     0               0
    BLAKE                    0               0
    JAMES                    0               0
    FORD                     0               0
    SCOTT                    0               0
    MARTIN                   0            1250
    MILLER                   0               0
    14 rows selected.

  • An index can not being used and still afect a query performance?

    Hi i have a query with a high cost so i created two indexes, A and B, to improve its performance.
    After the creation of the indexes when i reviewed the execution plan of the query the cost had been reduced, but i noticed that the index B is not being used,
    and if i try to force the query to use index B with a HINT the cost increases, so i decided to drop the index B.
    Once i droped the index B i checked the execution plan again and then i noticed that the cost of the query increased, if i recreate the index B the explain plan
    shows a lower cost even though its not being used by the execution plan.
    Does anyone know why is this happening?
    An index can, not being used by the execution plan and still affect a query performance?

    user11173393 wrote:
    Hi i have a query with a high cost so i created two indexes, A and B, to improve its performance.
    After the creation of the indexes when i reviewed the execution plan of the query the cost had been reduced, but i noticed that the index B is not being used,
    and if i try to force the query to use index B with a HINT the cost increases, so i decided to drop the index B.
    Once i droped the index B i checked the execution plan again and then i noticed that the cost of the query increased, if i recreate the index B the explain plan
    shows a lower cost even though its not being used by the execution plan.
    Does anyone know why is this happening?
    An index can, not being used by the execution plan and still affect a query performance?You said that is what is happening, & I believe you.

  • Any diffrent access for the null value between oracle 9i and 11g?

    I'v got a tmp result set by a SQL that with a group by rollup (code) clause, and the last row is the totle number and column 'code' is null.
    when i left out join (use (+)) the result set with the code table , in 9i,i can not get the last totle number row,but in 11g,can get the last totle number row.
    why? any one can help me?

    Can you post an example of what you mean?
    Please read {message:id=9360002} with the necessary details so we can understand your issue more clearly.

  • Trigger not changing a null value to -1 on insert, but works on update?

    Here is the trigger I am working on.
    If i update a row it will update the org_type_id to -1. However, nightly a job runs to append new data to the table. I can't change the fact that every day a few "deleted org"'s have a org_type_id as null.
    So, this trigger was supposed to solve it, but it ONLY works if a row is updated, it doesn't work on inserted new rows.
    Thoughts?
    CREATE OR REPLACE TRIGGER MDMR.MDM_ORG_TYPE_ID
    BEFORE INSERT OR UPDATE
    ON MDMR.MDM_ORG
    FOR EACH ROW
    declare
    begin
    if (UPDATING) then
    if ((:old.org_name = 'Deleted Org') and (nvl(:old.org_type_id,0) = 0)) then
    :new.org_type_id := -1;
    end if;
    end if;
    if (INSERTING) then
    DBMS_OUTPUT.put_line ('INSERTING1');
    if ((:new.org_name = 'Deleted Org') and (nvl(:new.org_type_id,0) = 0)) then
    DBMS_OUTPUT.put_line ('INSERTING2');
    :new.org_type_id := -1;
    end if;
    end if;
    end;
    /

    Hi,
    It looks fine to me (or, rather, it would look fine if it were formatted), but I can't test it without your table.
    Whenever you have a problem, post a little sample data (CREATE TABLE and INSERT statements), and the results you want from that data. In the case of DML problems (like this), the results are the contents of the changed table after each DML operation.
    Are you sure that 'Deleted Org' is spelled exactly the same in the trigger and in your INSERT statements? That includes capital letters and trailing spaces, including those automatically supplied for CHAR columns.
    Does it work when you test it, but fail during the nightly job?

  • How to use OFFSET for CHAR type value in Bex query

    infoobject A value = 1102007
    Type = CHAR
    I want to have an offset for this infoobject created in query say 1 to 12 months
    in month of 10/2007 value = 1102007
    remember above 1 is always CONSTANT
    then
    in month of 11/2007 value = 1112007
    in month of 12/2007 value = 1122007
    how to do this since the infoobject is of TYPE- CHAR ,its gives we cannot do the OFFFSET in the query ,for doing OFFSET the infoobject must be of type numeric or NUMC.
    is it possible achieve this in to update rules?? since i cannot change the type of this infoobject now in the middle of production support
    please help
    thanks

    Hi,
    You will have to add a characteristic to your cube.
    The format should be NUMC
    In the update-routine you will have to convert the char value to numc
    Success
    udo

  • Not to display the null values from data base

    Hiiii.
    In a jsp file i have ten check boxes.The jsp file is mapped to a servlet file for parameter requesting and to
    store it in DB.
    The unchecked box values has null values.All the values are store in a Mysql DB table.
    Again i have to display it in a jsp page from table.
    The problem am facing was,how can i display only the values in a row.it must not display the null values and the crresponding column name.
    Or any other way is their like below
    How i can retrieve only the selected check boxes from tht jsp file.and store in backend.
    Thanks in Advance
    regards,
    satheesh kannan

    Here is a rough example that may give you some ideas:
    On the JSP page:
    <%if(myData.getFirstName()!=null){%>
    Your First Name'
    <input type="text" name="firstName" value="<%=myData.getFirstName()%>">
    <%}%>
    In the servlet:
    String firstName= request.getParameter("firstName");
    if(firstName!=null){
    //write it to the database
    }

  • Query not executing for one particular value

    Hi
    I have query on multi provider. and this multi provider is combination of Info objects only but not any ODS or cubes. I have one key figure in this multi provider.while executing the query i need to give input for variabl which has 7 different values. Query is executing fine for 6 values but not for one particular value.
    query executed in listcube transaction and it is executed fine here for the same selection. then what might be the reason?
    Please advise as soon as possible.
    Thanks

    Hi Kiran,
    are you maintaining any filters in the query? or is there any logic in the exit for this variable.
    regards.

  • How to pass NULL value in SSRS

    Hi All,
    I have a parameter called Division,Region and State.While loading these parameter I am replacing NULL value as "NO Division","NO Region" and "NO State".Note all parameters are multi valued.
    Now In my dataset query If I put the condition like (division=@Division or Division is null) and (region=@region or Region is null) and (state=@State
    or State is null).
    In this scenario if I want to exclude null values need only specific Division which is not allowing me to do that with above condition.If  I need all it works fine but not with specifice division,region and  sate.
    Any thought on this.
    thanks
    Chandan
    Thanks Chandan

    Thats because of or conditions
    As per your explanation since you replace NULL value as No division etc what you need to do is just this
    (division=@Division or @Division = 'All') and (region=@region or @Region = 'All') and (state=@State or @State = 'All').
    this will make sure it will bring all values including NULLs when you pass All and will only give you specific division/region etc records when you pass a specific value.
    To get NULL valued records alone you need to pass value as No Division,No region etc
    Also you should change dataset query for parameter combo to make prompt as No Division etc for NULL values so that it can be selected as an option inside multi valued combo box to see NULL valued records
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

Maybe you are looking for

  • Ora-12704: character set mismatch

    I'm trying to insert string data into a nvarchar2 column using jdbc and I keep getting the error, ora-12704: character set mismatch. How do I avoid this without using the translate function? I believe my nls variables are all set correctly. Our softw

  • Error Message When Opening Interactive Demand Planning

    Hello Experts, I have one user who is receiving the following error message when trying to open Interactive Demand Planning Workbook.  Only one user is experiencing this issue.  Has anyone run into this before?  GP: Graphics product not available in

  • Unable to access the Firewall through ASDM

                       Hi All, Thanks in advance , in my organisatin we are facing one issue with launching of ASDM in ASA 5520 , when wer are trying to access the Firewall through ASDM we are unable to access that , see the java error loggs below , yes

  • Invalid Email Password - but its not.

    Hi - I hope you can help. I had a BB curve 8520 for past 2 years and loved it.  Over Christmas, my son had my old BB and I bought a new one - exactly the same - the Curve 8520. Both operate on orange networks.  My old BB was v4 new BB is v5.  I have

  • Java.lang.NoSuchMethodError: oracle.forms.handler.IHandler.getApplet()Ljava

    Hello to all I hope it is right forum for my question I have found for error I get in Directprint this following: When you migrate to the latest Forms version (10.1.2.3 or 11) and try using a JavaBean created with an older Forms version, you can get