To make the query more efficient (create table wiht select command)

Hi,
I have written this query to create another table, but it takes approx two hours while both tables are indexed with 891353, 769023, i have used the following query.
create table source1 as select a.idx, a.source from tt a where a.idx not in (select b.idx from ttt b)
thanks

Try this one if you're on oracle 8i or older
create table source1 as
  select a.idx, a.source
    from tt a
   where not exists (select null from ttt b where a.idx = b.idx)

Similar Messages

  • How to make this query more efficient

    Hi, i have query to find out the count of records based on certain conditions like below.
    SELECT count(*)
    FROM new_orders WHERE card_number IS NOT NULL
    AND exp_date IS NOT NULL
    AND card_id in ( select card_id from old_orders );
    There are millions of records in both the tables. , so it is taking long time to run. Is there any solution to optimize this query.....thanks for help. Bcj

    you might want to give this a try.
    SELECT count(*)
      FROM new_orders no
    WHERE no.card_number IS NOT NULL
       AND no.exp_date IS NOT NULL
       AND exists (select 'x'
                     from old_orders oo
                    where oo.card_id = no.card_id);it would also help if you can post the information needed as suggested by rob.

  • How can we optimize the LIKE '%...%' to make it work more efficiently

    how can we optimize the LIKE '%...%' to make it work more efficiently

    SQL> create table test as select * from V$SQL
    Table created.
    SQL> create index test_txt_idx on test(sql_fulltext) indextype is ctxsys.context
    Index created.
    SQL> select substr(sql_fulltext,1,30) sql_fulltext from test where contains(sql_fulltext, 'dataobj#') > 0
    SQL_FULLTEXT                                               
    select obj#, dataobj#, part#,                              
    select /*+ index_ss(obj$ i_obj                             
    select /*+ index_ss(obj$ i_obj                             
    select /*+ index_ss(obj$ i_obj                             
    select /*+ index_ss(obj$ i_obj                             
    select /*+ index_ss(obj$ i_obj                             
    delete from sys.cache_stats_1$                             
    select substr(sql_fulltext,1,3                             
    insert into wrh$_seg_stat   (s                             
    insert into obj$(owner#,name,n                             
    update /*+ index_ss(obj$ i_obj                             
    update /*+ index_ss(obj$ i_obj                             
    select i.obj#,i.ts#,i.file#,i.                             
    select i.obj#,i.ts#,i.file#,i.                             
    select i.obj#,i.ts#,i.file#,i.                             
    update wrh$_seg_stat_obj sso                               
    select obj#, dataobj#, part#,                              
    select obj#, dataobj#, part#,                              
    insert into tabpart$ (obj#, da                             
    update ind$ set ts#=:2,file#=:                             
    update ind$ set ts#=:2,file#=:                             
    insert into tab$(obj#,ts#,file                             
    select i.obj#,i.ts#,i.file#,i.                             
    select i.obj#,i.ts#,i.file#,i.                             
    select i.obj#,i.ts#,i.file#,i.                             
    select i.obj#,i.ts#,i.file#,i.                             
    select i.obj#,i.ts#,i.file#,i.                             
    select i.obj#,i.ts#,i.file#,i.                             
    select i.obj#,i.ts#,i.file#,i.                             
    update tabpart$ set dataobj# =                             
    insert into ind$(bo#,obj#,ts#,                             
    update tab$ set ts#=:2,file#=:                             
    update tab$ set ts#=:2,file#=:                             
    update /*+ index_ss(obj$ i_obj                             
    insert into indpart$ (obj#, da                             
    35 rows selected.
    SQL> drop table test
    Table dropped.What are you doing differently?

  • Query to find out the sessions trying to create table.

    Hi Folks,
    I wanted to know the sessions that are trying to create tables. I'm trying to use the query... but not getting the correct results...
    These are the three versions of queries i wrote..
    SELECT A.SID,A.USERNAME,A.SQL_ID,B.SQL_TEXT FROM V$SESSION A,V$SQLTEXT B
    WHERE A.STATUS='ACTIVE'
    AND A.SQL_ID=B.SQL_ID
    AND B.SQL_TEXT LIKE '%INSERT%' OR B.SQL_TEXT LIKE '%insert%'
    SELECT A.SID,A.USERNAME,A.SQL_ID,B.SQL_TEXT FROM V$SESSION A,V$SQLTEXT B
    WHERE A.SID IN (SELECT SID FROM V$SESSION WHERE STATUS='ACTIVE')
    AND A.SQL_ID=B.SQL_ID
    AND B.SQL_TEXT LIKE '%INSERT%' OR B.SQL_TEXT LIKE '%insert%'
    select sid, serial#, status, username, osuser,machine,sql_id from v$session
    where sql_id in (select sql_id from v$sqltext where SQL_TEXT like '%INSERT%'
    union
    select sql_id from v$sqltext where SQL_TEXT like '%insert%')
    But its not giving me the correct results. Can any one help me with a query to determine a way to catch the sessions trying to create tables.
    Thanks
    Karthik

    I'm not sure why this needs further explanation. A database is a conceptual and logical whole, it is not a dumpground. Databases are designed prior to their creation, after their creation only the content of the database change, not the database itself.
    Having end-users creating tables on the fly means you have no control over the database and also no control over it's integrity and consistency.
    Basically this means your database has been converted into a garbage dump.
    End-users creating tables on the fly is a big nono in my book, and whoever develops an application creating tables on the fly should be shown to the door of unemployment.
    You would either set up audit and issue audit table as explained before, or revoke the create table privilege from all end-users. Personally I prefer the last approach, and I wouldn't even consider the former.
    Sybrand Bakker
    Senior Oracle DBA

  • Is there a way to make the query key reference date equal to a date of IC

    Hi gurus
    Is there a way to make the query key reference date equal to a date in the InfoCube. For example, I want to see the attributes for characteristic material based on the sales date of the transaction?
    Thanks
    Siva

    Sivakumar,
    Key date applicable to entire query for time dependent attributes and heirarchies.
    You can create a user entry variable and use it for query key date. So can choose at input screen. and also you can populate default value using user exit(eg: current date).
    Hope it Helps
    Srini

  • How can i display all the query items to a table?

    how can i display all the query items to a table in a jsp file?
    i always have an out of memory error..

    any body??any idea?
    is it possible thru configuration or i have to write a program by the abaper??
    Biswa

  • Is there a Way to Make the HUD More Transparent

    I have been doing a number of Full screen adjustments with the HUD, but I find I am always moving the HUD so that I can see the image section I need to tweek. It would be EXTREMELY nice if I could make the HUD more transparent so that I can see the underlying image better. As the HUD is already partly transparent, I know there must be a preference somewhere to increase the transparency. Since I can not seem to find any mention of this in the manual, and no menu option (that I can find), I assume the only way to make the HUD more transparent, would be edit a plist.
    Would anyone know what I need to do to make the HUD more transparent?
    Any help or suggestions would be greatly appreciated.
    Thanks
    Gary
    Dual G5 2.5 GHz Dual Core, 2.5 GB RAM, 500 GB HDD   Mac OS X (10.4.9)   iLife 06, Final Cut Studio

    Hi, Ian.
    I would hope that application developers would learn from game developers, where HUDs are used ubiquitously.. Very usable and can be even 90% transparent or more.... it is all about contrast. There is a LOT of opaque DARK gray space in the Aperture HUDs, which could easily be much more transparent (even 50% would help). All you would have to do is keep the adjustment controls contrast up. i.e. Apples DVD Player Navigator.
    Anyway.... it would be nice.
    Thanks again for keeping me company at this early hour.
    Gary

  • How do you make the inside lines in a table darker?

    Hi There,
    I want to make the inside lines darker. I can't figure out how to do it with this newer version. Thanks!

    It is not a menu, but an annotated screen grab of the box item you need to click for each selected row.
    Click Format in the Toolbar. Click your table. Select the first row. In Pages v5.2.2, select the Cell tab, and then click Border to get it to expand, which shows the screen grab box that I put the red mark into so you would click there. In Pages v5.5, Apple has re-engineered the border layout in the Cell tab as shown below:

  • Create table as select (CTAS)statement is taking very long time.

    Hi All,
    One of my procedure run a create table as select statement every month.
    Usually it finishes in 20 mins. for 6172063 records and 1 hour in 13699067.
    But this time it is taking forever even for 38076 records.
    When I checked all it is doing is CPU usage. No I/O.
    I did a count(*) using the query it brought results fine.
    BUT CTAS keeps going on.
    I'm using Oracle 10.2.0.4 .
    main table temp_ip has 38076
    table nhs_opcs_hier has 26769 records.
    and table nhs_icd10_hier has 49551 records.
    Query is as follows:
    create table analytic_hes.temp_ip_hier as
    select b.*, (select nvl(max(hierarchy), 0)
    from ref_hd.nhs_opcs_hier a
    where fiscal_year = b.hd_spell_fiscal_year
    and a.code in
    (primary_PROCEDURE, secondary_procedure_1, secondary_procedure_2,
    secondary_procedure_3, secondary_procedure_4, secondary_procedure_5,
    secondary_procedure_6, secondary_procedure_7, secondary_procedure_8,
    secondary_procedure_9, secondary_procedure_10,
    secondary_procedure_11, secondary_procedure_12)) as hd_procedure_hierarchy,
    (select nvl(max(hierarchy), 0) from ref_hd.nhs_icd10_hier a
    where fiscal_year = b.hd_spell_fiscal_year
    and a.code in
    (primary_diagnosis, secondary_diagnosis_1,
    secondary_diagnosis_2, secondary_diagnosis_3,
    secondary_diagnosis_4, secondary_diagnosis_5,
    secondary_diagnosis_6, secondary_diagnosis_7,
    secondary_diagnosis_8, secondary_diagnosis_9,
    secondary_diagnosis_10, secondary_diagnosis_11,
    secondary_diagnosis_12, secondary_diagnosis_13,
    secondary_diagnosis_14)) as hd_diagnosis_hierarchy
    from analytic_hes.temp_ip b
    Any help would be greatly appreciated

    Hello
    This is a bit of a wild card I think because it's going to require 14 fill scans of the temp_ip table to unpivot the diagnosis and procedure codes, so it's lilkely this will run slower than the original. However, as this is a temporary table, I'm guessing you might have some control over its structure, or at least have the ability to sack it and try something else. If you are able to alter this table structure, you could make the query much simpler and most likely much quicker. I think you need to have a list of procedure codes for the fiscal year and a list of diagnosis codes for the fiscal year. I'm doing that through the big list of UNION ALL statements, but you may have a more efficient way to do it based on the core tables you're populating temp_ip from. Anyway, here it is (as far as I can tell this will do the same job)
    WITH codes AS
    (   SELECT
            bd.primary_key_column_s,
            hd_spell_fiscal_year,
            primary_PROCEDURE       procedure_code,
            primary_diagnosis       diagnosis_code,
        FROM
            temp_ip
        UNION ALL
        SELECT
            bd.primary_key_column_s,
            hd_spell_fiscal_year,
            secondary_procedure_1    procedure_code,
            secondary_diagnosis_1    diagnosis_code
        FROM
            temp_ip
        UNION ALL
        SELECT
            bd.primary_key_column_s,
            hd_spell_fiscal_year,
            secondary_procedure_2    procedure_code ,
            secondary_diagnosis_2    diagnosis_code     
        FROM
            temp_ip
        UNION ALL
        SELECT
            bd.primary_key_column_s,
            hd_spell_fiscal_year,
            secondary_procedure_3    procedure_code,
            secondary_diagnosis_3    diagnosis_code
        FROM
            temp_ip
        UNION ALL
        SELECT
            bd.primary_key_column_s,
            hd_spell_fiscal_year,
            secondary_procedure_4    procedure_code,
            secondary_diagnosis_4    diagnosis_code
        FROM
            temp_ip
        UNION ALL
        SELECT
            bd.primary_key_column_s,
            hd_spell_fiscal_year,
            secondary_procedure_5    procedure_code,
            secondary_diagnosis_5    diagnosis_code
        FROM
            temp_ip
        UNION ALL
        SELECT
            bd.primary_key_column_s,
            hd_spell_fiscal_year,
            secondary_procedure_6    procedure_code,
            secondary_diagnosis_6    diagnosis_code
        FROM
            temp_ip
        UNION ALL
        SELECT
            bd.primary_key_column_s,
            hd_spell_fiscal_year,
            secondary_procedure_7    procedure_code,
            secondary_diagnosis_7    diagnosis_code
        FROM
            temp_ip
        UNION ALL
        SELECT
            bd.primary_key_column_s,
            hd_spell_fiscal_year,
            secondary_procedure_8    procedure_code,
            secondary_diagnosis_8    diagnosis_code
        FROM
            temp_ip
        UNION ALL
        SELECT
            bd.primary_key_column_s,
            hd_spell_fiscal_year,
            secondary_procedure_9    procedure_code,
            secondary_diagnosis_9    diagnosis_code
        FROM
            temp_ip
        UNION ALL
        SELECT
            bd.primary_key_column_s,
            hd_spell_fiscal_year,
            secondary_procedure_10  procedure_code,
            secondary_diagnosis_10    diagnosis_code
        FROM
            temp_ip
        UNION ALL
        SELECT
            bd.primary_key_column_s,
            hd_spell_fiscal_year,
            secondary_procedure_11  procedure_code,
            secondary_diagnosis_11    diagnosis_code
        FROM
            temp_ip    
        SELECT
            bd.primary_key_column_s,
            hd_spell_fiscal_year,
            secondary_procedure_12  procedure_code,
            secondary_diagnosis_12    diagnosis_code
        FROM
            temp_ip
    ), hd_procedure_hierarchy AS
    (   SELECT
            NVL (MAX (a.hierarchy), 0) hd_procedure_hierarchy,
            a.fiscal_year
        FROM
            ref_hd.nhs_opcs_hier a,
            codes pc
        WHERE
            a.fiscal_year = pc.hd_spell_fiscal_year
        AND
            a.code = pc.procedure_code
        GROUP BY
            a.fiscal_year
    ),hd_diagnosis_hierarchy AS
    (   SELECT
            NVL (MAX (a.hierarchy), 0) hd_diagnosis_hierarchy,
            a.fiscal_year
        FROM
            ref_hd.nhs_icd10_hier a,
            codes pc
        WHERE
            a.fiscal_year = pc.hd_spell_fiscal_year
        AND
            a.code = pc.diagnosis_code
        GROUP BY
            a.fiscal_year
    SELECT b.*, a.hd_procedure_hierarchy, c.hd_diagnosis_hierarchy
      FROM analytic_hes.temp_ip b,
           LEFT OUTER JOIN hd_procedure_hierarchy a
              ON (a.fiscal_year = b.hd_spell_fiscal_year)
           LEFT OUTER JOIN hd_diagnosis_hierarchy c
              ON (c.fiscal_year = b.hd_spell_fiscal_year)HTH
    David

  • DB Link Create table as select

    I ve a query which starts with create table as select ..
    When I run the select part of the query, it runs in 2 sec.
    But the whole query runs in 10min. It is fetching data from dblink.
    I think if select can finish in 2 sec. All is left to do is create table and insert.
    Why is takin so long?
    Oracle DB version 9.2.0.8

    When I run the select part of the query, it runs in 2 sec.Does the select finish in 2 seconds or does it start returning rows in 2 seconds?
    Big difference.

  • Identify tablspace in create table as select

    I am trying to run a create table as select query that specifies which tablspace to create the table in. When I run the query below I get an error, any ideas?
    create table roi_call_record_backup as (select * from prod.roi_call_record)
    tablespace roi_data01;
    null

    Try this ...
    create table roi_call_record_backup
    tablespace roi_data01
    as
    (select * from prod.roi_call_record)
    null

  • [Solved]SIMPLE Question ON "CREATE TABLE as SELECT".

    Hi there,
    I was wondering how to work it out smartly and briefly.
    For example, I already have a "tableA" as following.
    tableA
    id name
    1 name1
    2 name2
    create table tmp as
    select id, name from tableA;
    It will create the tmp table successfully.
    If I want to add a new column 'tel' in tmp table,
    I can run as following.
    create table tmp as
    select id, name, 999 tel, 'aaaaaaaaa' ps from tableA;
    It will add 'tel NUMBER' column and 'ps char(9)' in tableA.
    If I want to add 'col varchar(50)' in tableA,
    I do not want to make a string which contains 50 characters in Select command.
    How can I make it work in a smart way?
    Thanks.
    Phil
    Message was edited by:
    user615355

    Is there a reason that you need this to be in a single statement? You would normally be better served here with a separate CREATE TABLE and INSERT (possibly as a direct path operation).
    That said, you could use the CAST operator, i.e.
    SCOTT @ jcave102 Local> create table a as select cast('a' as varchar2(50)) col1 from dual;
    Table created.
    Elapsed: 00:00:00.48
    SCOTT @ jcave102 Local> desc a;
    Name                                                  Null?    Type
    COL1                                                           VARCHAR2(50)
    SCOTT @ jcave102 Local> Justin

  • "Create Table from select Query" Vs "Insert into"

    Hi
    Schenaio:
    My Select Query returns more than 10 million records, these records needs to be inserted into another table.
    Approach 1:
    I created table called TABLE1, and inserted the records using INSERT statement as a batch (batch size is 5000).
    Approach 2:
    I create table like,
    CREATE TABLE TABLE1 AS <SELECT QUERY>
    Here Apporach-1 took almost 40 minutes to complete the insert but Approach-2 took only 6 minutes.
    If anybody knows why it is? And is there any way to improve the performance of Approach-1?.
    Thanks
    Nidhi

    Most "batch" methods execute the same query multiple times. Row filtering is done after the rows are fetched from the source. The process of fetching all the rows could be a FullTableScan.
    Therefore, a FullTableScan is executed for each batch of 5000 rows.
    However, your query and batch definitions may well be different. We haven't seen the query and the execution plan.
    Another point : How are you "filtering" the rows (i.e the second execution inserts rows 5001 to 10000 and does not attempt to reinsert rows 1 to 5000) ?
    What is the overhead imposed by the filter ? (does the third execution have to exclude rows 1 to 10000 and inserts rows 10001 to 15000 and so on)
    Hemant K Chitale

  • How to make the search faster  in a table ?

    hi ,
    i have got a table wich has one field as a primary key , and this table got 500000 records in it
    wich i try to pop up the (LOV)  it takes about one minute to be retreived
    i dodnt know how to make it faster ?
    could anyone help me how to make faster ?
    and what index should i put on this table ?

    thanks for your help
    and here is the the
    CREATE TABLE MOBWORKSHOP.MOBWSH_GUARANTY
      GRNTY_NO          VARCHAR2(10 BYTE),
      I_CODE            VARCHAR2(30 BYTE),
      SERIAL_NO         VARCHAR2(30 BYTE)           NOT NULL,
      GRNTY_START_DATE  DATE,
      GRNTY_EXPIR_DATE  DATE,
      GRNTY_VALIDTY     NUMBER(1),
      CAUSE_ID          VARCHAR2(10 BYTE),
      NOTE              VARCHAR2(60 BYTE),
      AD_U_ID           NUMBER(5)                   NOT NULL,
      AD_DATE           DATE                        NOT NULL,
      UP_U_ID           NUMBER(5),
      UP_DATE           DATE,
      BRN_NO            NUMBER(6)                   NOT NULL,
      BRN_YEAR          NUMBER(4)
    TABLESPACE MOBWRKSHPTRANS
    PCTUSED    0
    PCTFREE    10
    INITRANS   1
    MAXTRANS   255
    STORAGE    (
                INITIAL          64K
                MINEXTENTS       1
                MAXEXTENTS       UNLIMITED
                PCTINCREASE      0
                BUFFER_POOL      DEFAULT
    LOGGING
    NOCOMPRESS
    NOCACHE
    NOPARALLEL
    MONITORING;
    CREATE UNIQUE INDEX MOBWORKSHOP.MOBWSH_GUARANTY_PK ON MOBWORKSHOP.MOBWSH_GUARANTY
    (GRNTY_NO)
    LOGGING
    TABLESPACE INDX_TRANS_MOBWRKSHP
    PCTFREE    10
    INITRANS   2
    MAXTRANS   255
    STORAGE    (
                INITIAL          64K
                MINEXTENTS       1
                MAXEXTENTS       UNLIMITED
                PCTINCREASE      0
                BUFFER_POOL      DEFAULT
    NOPARALLEL;
    ALTER TABLE MOBWORKSHOP.MOBWSH_GUARANTY ADD (
      CONSTRAINT MOBWSH_GUARANTY_PK
    PRIMARY KEY
    (GRNTY_NO)
        USING INDEX
        TABLESPACE INDX_TRANS_MOBWRKSHP
        PCTFREE    10
        INITRANS   2
        MAXTRANS   255
        STORAGE    (
                    INITIAL          64K
                    MINEXTENTS       1
                    MAXEXTENTS       UNLIMITED
                    PCTINCREASE      0
    ALTER TABLE MOBWORKSHOP.MOBWSH_GUARANTY ADD (
      CONSTRAINT MOBWSH_QRNTY_I_CODE_FK
    FOREIGN KEY (I_CODE)
    REFERENCES MOBWORKSHOP.ITEM_DETAILS (I_CODE),
      CONSTRAINT MOBWSH_CANCEL_CAUS_FK
    FOREIGN KEY (CAUSE_ID)
    REFERENCES MOBWORKSHOP.GUARANTY_CANCEL_CAUSES (CAUSE_ID));
    i made  a button to show  (LOV) and when i press the putton it take about one minute to view the LOV

  • Is a WITH...SELECT query more efficient than a SELECT query ?

    Hi folks,
    Is the WITH...SELECT just a convenience or is it really efficient than a simple SELECT with UNION ALL ? e.g. is the following:
    with rset as (select dname,empno,ename,hiredate,sal from emp e,dept d where e.deptno=d.deptno)
    select dname,empno,ename,hiredate,sal,
    case
    when trunc(hiredate) < to_date('19800101','yyyymmdd') then 'Hired before 1980'
    when trunc(hiredate) between to_date('19800101','yyyymmdd') and to_date('19851231','yyyymmdd') then 'Hired between 1980 and 1985'
    else 'Hired after 1985'
    end as notes
    from rset
    union all
    select dname,empno,ename,hiredate,sal,
    case
    when sal < 500 then 'Salary less than 500'
    when sal between 501 and 1500 then 'Salary between 501 and 1500'
    else 'Salary greater than 1500'
    end as notes
    from rset;
    better than the following:
    select dname,empno,ename,hiredate,sal,
    case
    when trunc(hiredate) < to_date('19800101','yyyymmdd') then 'Hired before 1980'
    when trunc(hiredate) between to_date('19800101','yyyymmdd') and to_date('19851231','yyyymmdd') then 'Hired between 1980 and 1985'
    else 'Hired after 1985'
    end as notes
    from emp e,dept d where e.deptno=d.deptno
    union all
    select dname,empno,ename,hiredate,sal,
    case
    when sal < 500 then 'Salary less than 500'
    when sal between 501 and 1500 then 'Salary between 501 and 1500'
    else 'Salary greater than 1500'
    end as notes
    from emp e,dept d where e.deptno=d.deptno;
    I am a newbie at sql tuning. Apparently, the first query should be faster because it runs the actual query only once and then just works on the resultset obtained. Is this thinking correct ?
    Thanks a lot!!
    JP

    Also I tried a test here with a ten million row emp table queried five times, and explain plan showed the optimizer would read emp five times and not once.
    Re: Intresting question
    Apparently, the first query should be faster because it runs the actual query only once
    and then just works on the resultset obtained.But my test combined with Jonathan's article made me question whether materializing ten million rows somewhere would be faster than querying them five times. Somehow I doubt it.

Maybe you are looking for