I have a view my_view
I can query it like:
select * From my_view;
This takes about 4 seconds to run and returns about 100 rows of 10 columns (varchar2 and number - nothing fancy)
I want to take that results-set and insert it into a table.
I do this like:
create table my_table as select * from my_view;
and this takes about 45 minutes to complete.
I can create the table alone in no time at all:
create table my_table as select * From my_view where 1=0;
executes in a fraction of a second.
And I can insert 100 rows in no time at all:
insert into table (c1, c2, c3, c4) values ('a1', 'b1', 'c1', 'd1')
insert into table (c1, c2, c3, c4) values ('a2', 'b2', 'c2', 'd2')
insert into table (c1, c2, c3, c4) values ('a3', 'b3', 'c3', 'd3')
insert into table (c1, c2, c3, c4) values ('a4', 'b4', 'c4', 'd4')
insert into table (c1, c2, c3, c4) values ('a5', 'b5', 'c5', 'd5')
also executes in less than a second - so for a hundred rows, a few seconds would make sense. 10 even would be no problem.
It seems like, even if insert as select command required the view to be queried in it's entirety - 100 or so times - once for each row inserted, it would still run faster.
What am I missing?
My questions are:
Why is it so slow?
- If you guys don't know - how can I begin to debug it for an oracle database? How can I see what's happening under the hood?
How can I make it run faster, if my end goal is to write a robust procedure that'll take the data and archive it in a different table?
- Is there some special syntax I can use to get the DB to cache the query-result better?