Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> Re: rownum=1 slow + tell if a column has at least a non null value
"Le JeanMimi" <scjm_at_noos.fr> wrote in message
news:c7be5048.0211131002.37beecaa_at_posting.google.com...
> Hello,
>
> I run these queries with toad on my_table (25 millions rows) :
>
> select count(*) from my_table where rownum = 1;
> => 8s
>
> select count(*) from my_table where rownum < 3000000;
> => 30s
>
> select count(*) from my_table where rownum < 30000000;
> => 4 min
>
> 1) Why does it take 8 sec for the first to complete ?
> I thought it would be instantaneous.
> (select * from my_table where key='value' is instantaneous)
>
> 2) By the way, what is the fastest method to tell if a column has at
> least one non null value ?
>
> I was thinking about : select 'x' from any_table where any_column is
> not null and rownum = 1;
>
> But with the previous results (8 sec), it may not be.
> Do i have to make a function which opens a cursor and loop until i
> find a non null value ?
>
> Thanks a lot.
>
> Jean-Michel
2
select 'x' from dual
where exists
(select 'x'
from my_table
where column >0 (or > chr(0))
)
provided the column is indexed.
Non-indexed: full table scan
You might want to ask yourself whether you really need this type of test. In 13 years I never needed this kind of test.
Hth
-- Sybrand Bakker Senior Oracle DBA to reply remove '-verwijderdit' from my e-mail addressReceived on Wed Nov 13 2002 - 12:54:31 CST
![]() |
![]() |