optimizing a view

optimizing a view

Post by Nicklas Hjalmarsso » Sun, 31 Dec 1899 09:00:00



Is it possible to have a query go through an index when selecting from a
view?

If someone can look at thios example
?
CREATE TABLE TEST

  TIME   DATE,
  VALUE  NUMBER ) ;

CREATE INDEX cc_test_time_ndx ON TEST(time)
  TABLESPACE index_data ;

CREATE OR REPLACE VIEW TESTVIEW (TIME,
SUM_VAL ) AS select trunc(time,'MI') time ,sum(value) sum_val from test
group by trunc(time,'MI');

When I select directy from the table it works fine.
select trunc(time,'MI') time ,sum(value) sum_val from test  where time <
SYSDATE -1 group by trunc(time,'MI');

But when I use the view it makes a full tableacan.
select * from testview where time < SYSDATE -1;

I cannot make the query directly towards the table but its ok redifine the
view or a create another index.

 
 
 

optimizing a view

Post by Connor McDonal » Sun, 31 Dec 1899 09:00:00



> Is it possible to have a query go through an index when selecting from a
> view?

> If someone can look at thios example
> ?
> CREATE TABLE TEST

>   TIME   DATE,
>   VALUE  NUMBER ) ;

> CREATE INDEX cc_test_time_ndx ON TEST(time)
>   TABLESPACE index_data ;

> CREATE OR REPLACE VIEW TESTVIEW (TIME,
> SUM_VAL ) AS select trunc(time,'MI') time ,sum(value) sum_val from test
> group by trunc(time,'MI');

> When I select directy from the table it works fine.
> select trunc(time,'MI') time ,sum(value) sum_val from test  where time <
> SYSDATE -1 group by trunc(time,'MI');

> But when I use the view it makes a full tableacan.
> select * from testview where time < SYSDATE -1;

> I cannot make the query directly towards the table but its ok redifine the
> view or a create another index.

Until 8i, a function on an indexed column will prohibit the use of the
index.  Thus the view (which has trunc) will not allow it...

To avoid it, you could have have both the date and the trunc'd date in
the view, or just retain the original time and trunc it as your select.

HTH
--
===========================================
Connor McDonald
"These views mine, no-one elses etc etc"

"Some days you're the pigeon, and some days you're the statue."

 
 
 

1. optimizing a view-driven query

if i've got a view that joins three or four tables, is there a
way to SELECT on that view to bypass any of the joins if they're
not needed in the result?

        create view course as
                select
                        _course.name as course,
                        _topic.name  as topic,
                        _school.name as school,
                        _state.name  as state,
                        _school.zip  as zip
                where
                        _course.topic = _topic.id
                        and
                        _topic.school = _school.id
                        and
                        _state.abbr   = _school.state
                ;

        select * from course ;
        -- shows all fields via all tables

        select topic from course where course like '%comput%' ;
        -- not asking for state, we don't need to join the state table

here the optimizer might know we don't need to join the static
lookup '_state' table. can this be made to happen?

or is it just best to have "one view, one purpose"?

--
It is always hazardous to ask "Why?" in science, but it is often
interesting to do so just the same.
                -- Isaac Asimov, 'The Genetic Code'


http://newbieDoc.sourceforge.net/ -- we need your brain!
http://www.dontUthink.com/ -- your brain needs us!

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command

2. _SLOW_ QueryDef.Parameters call

3. Optimizing Queries, Views vs Tables - Info Needed

4. [Excel2Ingres v2.1 - Data Conversion Tool Update]

5. To VFP Gugus: Really OPTIMIZING local views

6. How to make a Table Column to a default UpperCase Or LowerCase

7. optimize: view of views

8. Fox 2.6 Design question

9. ASA6: Optimize view of a view?????

10. Partitioned view optimized incorrectly

11. Which is more optimized for a select query view or stored procedure

12. view optimize???

13. Are views optimized by caching?