Re: "WHERE 1 = 2" does strange things



paulfil wrote:
> "WHERE 1 = 2" is a known trick to clone table structure. It should
> create an empty table. It should work very fast.
> IT DOES NOT. At least when cloning a structure of a view.
>
> Try it and look at explain plan. For some reason, even if it should be
> absolutely clear to ORACLE optimizer that no rows ought to be return,
> it still scans indexes of the tables forming the view. On complex
> views with large tables this turns out to be a costly process.
>
> Does anybody know more effective method to clone structure of a view
> into a new table?

I think you forgot to include the explain plan & view definition in
your request. I'm guessing that the view in question may do some
aggregation (group by logic), so it may be processing all the tables in
order to resolve the view.

However, you could try some other options:

CREATE TABLE NewTable as SELECT * FROM MyView WHERE Rownum < 1;

Otherwise, if that's also slow, you could write a PL/SQL procedure that
takes a table name & new table name and generates some the Create Table
sql by querying the user_tab_columns table and execute it with the
dbms_sql package. In order to do so, you'll have to make sure you've
explicitly granted CREATE TABLE privileges directly to the user running
the dbms_sql command (granting them a role that contains CREATE TABLE
privileges will not work). That will always be fast, it's just a bit
of a hassle to write.

-Steve

.



Relevant Pages

  • Re: Minnesota plan: Clone embryos and kill them!
    ... Minnesota plan to clone human embryos for "research," force taxpayers ... representatives rejected an amendment would be a true ban on cloning, ...
    (alt.politics.bush)
  • Re: Yet, More Campaign Rage...
    ... empty suit...a very expensive suit...but empty nonetheless. ... "BARACK OBAMA AND JOE BIDEN’S EMERGENCY ECONOMIC PLAN ... Barack Obama and Joe Biden have advocated for an Emergency Economic Plan to jumpstart the economy, ... State Growth Fund: $25 billion in a State Growth Fund to prevent state and local cuts in health, education and housing assistance or counterproductive increases in property taxes, tolls or fees. ...
    (rec.sport.football.college)
  • Minnesota plan: Clone embryos and kill them!
    ... Minnesota plan: Clone embryos and kill them! ... representatives rejected an amendment would be a true ban on cloning, ...
    (alt.politics.bush)
  • Re: New at dcroads.net: Jones Falls Expressway (I-83)
    ... mostly empty. ... I-95 interchange, with a narrow Boston St. and O'Donnell St. being the ... 1971 D.C. Interstate plan, as described on your website, appears to ...
    (misc.transport.road)
  • Re: Rover 200 coolant loss
    ... >month and the coolant level drops quite rapidly (full to empty in one ... I plan to take this back to the dealer under warranty but want ...
    (uk.rec.cars.maintenance)