Query performace with "partition by" clause.

Below is my query
>
select event_type, time, count(event_id) as no_of_events from (
select e.event_type, t.time , e.id as event_id from time t
left outer join events e partition by (event_type)
on t.time < e.end_time and (t.time + 1) > e.start_time
where t.time >= '2008-01-01' and t.time < '2008-02-01'
) events_by_event_type
group by event_type, time
order by event_type, time
The idea is to get a count of active "events" of each "event_type", for each day between 2 dates. The "time" table has one row each for each day. An event is said to be active for a day , when it's end_time - start_time overlaps the day's beginning and end.
The query works but always does a full table scan of the events table.
I tried creating following indexes on the events table , but none of them is ever used.
(event_type,start_time)
(event_type,end_time)
(event_type,start_time,end_time)
(start_time)
(end_time)
(start_time,end_time)
How can I avoid the full table scan of the "events" table in the above query ?
fyi the events table looks like
>
id number not null primary key,
event_type number not null,
start_date date not null,
end_date date not null

What I want is to avoid the full table scan on the
"events" table. I don't think adding an index on the
'time' table will help there.The conditions you have on events are
t.time < e.end_time and (t.time + 1) > e.start_timeSo you should have an index on the columns end_time and start_time to avoid a full table scan.
But anyway is that query slow?
Bye Alessandro
Message was edited by:
Alessandro Rossi
Plus I would add two more predicates to the query to enforce a range scan. If I did well they should always be true for the rows you want. They are there just to tell the CBO that the scan on end_time has to begin from '2008-02-01' and the scan on start_time has to finish on ('2008-01-01' - 1). Sometime this kind of additional conditions helped me.
select event_type, time, count(event_id) as no_of_events
from (
          select e.event_type, t.time , e.id as event_id from time t
          left outer join events e partition by (event_type) on (
               t.time between e.start_time - 1 and e.end_time
          where t.time >= '2008-01-01' and t.time < '2008-02-01'
               and e.end_time >= '2008-02-01' and e.start_time <= '2008-01-01' - 1
) events_by_event_type
group by event_type, time
order by event_type, time

Similar Messages

  • Query Optimization with partitioned/subpartitioned tables

    I have a 1 billion row table with 72 partitions by range and thousands of subpartitions by list. There is a bitmap index on the subpartition by list field.
    If I execute the following query which requests data from a single partition and a single subpartition:
    SQL> select * from cen00_demog_sf1_hp where
    ckey like '33011%' and demogname = 'P002006';
    the optimizer selects a single partition ('33...') and a single subpartition ('P002006'). The query takes only 6 seconds including displaying the 7,386 row result.
    However, if I then execute the following query which selects data from two partitions and a single subpartition within each partition:
    SQL> select * from cen00_demog_sf1_hp where
    (ckey like '33011%' or ckey like '35001%')
    and demogname = 'P002006';
    the optimizer scans all partitions rather than just scanning partitions 33 and 35. The query takes over 10 minutes to display the 17,972 row result. If this query is split into two separate queries, the same result set can be realized in a total 26 seconds including display the results to the screen.
    Any suggestions on how the multiple partition query can be modified to avoid an all rows scan?
    Thank you.

    I had previously tried reversing the WHERE clause statements in the query but it had no affect. The execution plan for the two partition query follows. Note the "ALL" on the partition range. I purposely did not index the ckey field believing that partitioning would be sufficent (ckey contains 8,262,363 unique keys out of 1,041,057,738 rows). As a test a query requesting a demogval based on a single ckey for a particular demogname returns a result in less than a second. Another test requesting data for a particular ckey without a demogname qualifier resulted in a full scan of a single partition (but not all the partitions) taking 4 minutes of elapsed time. Note that the only reason that there is a bitmap index on the demogname in table cen00_demog_sf1_hp is that normally the query is a join with another table containing an indexed demogname field. In sum, it appears that the optimizer defaults to an all partition scan when more than one partition is included in the query.
    Elapsed: 00:11:38.41
    Execution Plan
    0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=53824 Card=4 Bytes=148)
    1 0 PARTITION RANGE (ALL) (Cost=53824 Card=4 Bytes=148)
    2 1 PARTITION LIST (SINGLE) (Cost=53824 Card=4 Bytes=148)
    3 2 TABLE ACCESS (BY LOCAL INDEX ROWID) OF 'CEN00_DEMOG_SF1_HP' (TABLE) (Cost=53824 Card=4 Bytes=148)
    4 3 BITMAP CONVERSION (TO ROWIDS)
    5 4 BITMAP INDEX (SINGLE VALUE) OF 'CEN00_DEMOG_SF1_HP_IDX' (INDEX (BITMAP))
    The single partition query trace shows selectivity on the partition range.
    Elapsed: 00:00:09.69
    Execution Plan
    0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=42 Card=133 Bytes=4655)
    1 0 PARTITION RANGE (SINGLE) (Cost=42 Card=133 Bytes=4655)
    2 1 PARTITION LIST (SINGLE) (Cost=42 Card=133 Bytes=4655)
    3 2 TABLE ACCESS (BY LOCAL INDEX ROWID) OF 'CEN00_DEMOG_SF1_HP' (TABLE) (Cost=42 Card=133 Bytes=4655)
    4 3 BITMAP CONVERSION (TO ROWIDS)
    5 4 BITMAP INDEX (SINGLE VALUE) OF 'CEN00_DEMOG_SF1_HP_IDX' (INDEX (BITMAP))

  • Query tuning with partition

    Hi to all,
    I am an issue with a tuning of a query where I have a join among a lot of table with the same structure as described below:
    Table A
    VARCHAR2(20) : id_customer
    VARCHAR2(20): external_id
    date : start_custromer
    date : end_customer.
    The end customer is settled when the record is closed. Therefore this field may assume two possible value: null or with the closing date.
    The table is partiotioned with the end date.
    Into the query I have a filter because I search the record open at for exemple the last year. Then also when I create an index in the end_customer I'm not able to use the corresponding index because the optimezer choises to select all partitions.
    How can I resolve this problem?
    TIA !

    Correct. In fact I suppose that the problem is when I search the null values. The filter of my query is:
    table.start_customer <= sysdate and nvl(table.end_customer), sysdate+1) > sysdate
    I read the threads suggested by you, and I try to create a bitmap index. But Oracle does not accept it because it force me to create a bitmap index only in a local partition of the table....
    I try also to set an hint but the database does not choise this path, probably because there is a setting or something like that.
    TIA!

  • Cross-listing Query (Partition By Clause? Self-Join?)

    Hello,
    I need a query that will cross-list courses a professor is teaching this semester. Essentially, two fields need to be the same (i.e.: Section & CourseTitle), while the third field is different (i.e.: Subject).
    For example, Max Power is a professor teaching 3 courses, one is cross-listed (ENG 123 and JRL 123):
    LastName     FirstName     Subject     Section     CourseTitle
    Power          Max          ENG     123     English Composition
    Power          Max          ENG     452     Robert Frost Poetry     
    Power          Max          JRL     123     English Composition
    Power           Max          ENG      300     Faulkner & TwainThe desired query output is this:
    LastName     FirstName     Subject     Section     CourseTitle
    Power          Max          ENG     123     English Composition
    Power          Max          JRL     123     English CompositionBasically, I need only the cross-listed courses in the output.Is this an instance where I use a "Partition By Clause" or should I create a self-join?
    Much thanks for any help and comments.

    Unfortunately, I can't create new tables. I don't have permission. I can't alter, add or delete any of the data.
    So I tried Frank's code with my data:
    WITH got_cnt AS
    SELECT  sivasgn_term_code, spriden_id, spriden_last_name, spriden_first_name,
                    ssbsect_ptrm_code, ssbsect_camp_code,
                    sivasgn_crn, ssbsect_subj_code, ssbsect_crse_numb, scbcrse_title,
           count(*) over (partition by ssbsect_crse_numb, scbcrse_title) cnt
    FROM spriden INNER JOIN sivasgn ON spriden_pidm = sivasgn_pidm JOIN
         ssvsect ON ssbsect_crn = sivasgn_crn JOIN
         sfrstcr ON sfrstcr_crn = sivasgn_crn
    WHERE  ssbsect_term_code= sivasgn_term_code  
    AND sfrstcr_term_code = sivasgn_term_code
    AND ssbsect_enrl > '0' and sivasgn_credit_hr_sess > '0'
    AND sivasgn_term_code IN ('200901', '200909')
    AND spriden_change_ind IS NULL
    AND ssbsect_camp_code IN ('1', '2', 'A', 'B')
    SELECT DISTINCT sivasgn_term_code, spriden_id, spriden_last_name, spriden_first_name,
                    substr(ssbsect_ptrm_code,1,1) as ptrm_code, ssbsect_camp_code,
                    sivasgn_crn, ssbsect_subj_code, ssbsect_crse_numb, scbcrse_title
    FROM got_cnt
    WHERE cnt >1
    ORDER BY spriden_last_name, sivasgn_term_code, ssbsect_crse_numb;The output pretty much displays all courses with same subject code, course number and course title.
    Output:
    LastName     FirstName     Subject     Section     CourseTitle
    Power          Max          ENG     123     English Composition
    Power          Max          ENG     123     English Composition
    Power          Max          ENG     452     Robert Frost Poetry
    Power          Max          ENG     452     Robert Frost Poetry
    Power           Max          ENG      300     Faulkner & Twain
    Power           Max          ENG      300     Faulkner & Twain
    Power          Max          JRL     123     English Composition
    Power          Max          JRL     123     English CompositionWhat I would like is same course number, course title, BUT different subject code. Pretty much that in my first post of this thread.
    Desired Output:
    LastName     FirstName     Subject     Section     CourseTitle
    Power          Max          ENG     123     English Composition
    Power          Max          JRL     123     English CompositionMaybe I'm explaining this wrong. Any help would be greatly appreciated. Thanks.

  • Problem with SQL query region source containing OLAP clauses

    Hi team,
    I believe I found a bug when HTMLDB validates the SQL Query in a report region.
    My query includes an ORDER BY clause within a windowing function and HTMLDB refuses to accept the source owing to the presence of the ORDER BY and the column heading sort preference.
    Clearly the order-by in a window function has little to do with the column heading sort, but this error prevents me from updating the conditional display item in the page definition.
    Note also that the page was imported smoothly from the 1.5 version, so probably the region source is not checked at that time, but only when you update it "manually".
    So, in the end, if I don't change anything the page works because the sql query is assumed to be correct but unfortunately I need to change the condition and I cannot.
    The problem shows up in page 126 of app 21670, SQL query region.
    Bye,
    Flavio
    PS: may be I can work around this by using the pl/sql function returning the sql query.

    Flavio,
    We're aware of this problem. For now, your workaround is described in this thread:
    HTMLDB 1.6 and "order by" in analytic functions
    Sergio

  • [10g] Need help with order by clause in hierarchical query

    I have the following sample data:
    CREATE TABLE     bill_test1
    (     parent_part     CHAR(25)
    ,     child_part     CHAR(25)
    ,     line_nbr     NUMBER(5)
    ,     qty_per          NUMBER(9,5)
    INSERT INTO bill_test1 VALUES ('ABC-1','ABC-10',100,1);
    INSERT INTO bill_test1 VALUES ('ABC-1','ABC-20',200,2);
    INSERT INTO bill_test1 VALUES ('ABC-1','ABC-30',300,3);
    INSERT INTO bill_test1 VALUES ('ABC-1','HARDWARE-1',401,10);
    INSERT INTO bill_test1 VALUES ('ABC-1','HARDWARE-2',402,5);
    INSERT INTO bill_test1 VALUES ('ABC-10','ABC-155',100,2);
    INSERT INTO bill_test1 VALUES ('ABC-10','HARDWARE-1',200,1);
    INSERT INTO bill_test1 VALUES ('ABC-155','RAW-2',100,4.8);
    INSERT INTO bill_test1 VALUES ('ABC-155','HARDWARE-3',200,3);
    INSERT INTO bill_test1 VALUES ('ABC-20','RAW-1',100,10.2);
    INSERT INTO bill_test1 VALUES ('ABC-30','RAW-3',100,3);And the query below gives me exactly what I want, in the order I want it. However, I am wondering if there is a way to get this order without creating the SEQ column, since I don't need it in my results
    SELECT     part_nbr
    ,     parent_part
    ,     child_part
    FROM     (
         SELECT     CONNECT_BY_ROOT b.parent_part                         AS part_nbr
         ,     b.parent_part
         ,     b.child_part
         ,     SYS_CONNECT_BY_PATH(b.line_nbr,' ')                    AS seq
         FROM     bill_test1 b
         ,     dual
         CONNECT BY     parent_part     = PRIOR child_part
    WHERE          part_nbr     = 'ABC-1'
    ORDER BY     seq
    Results of above query, except with SEQ included in SELECT (just to show what I'm sorting off of):
    PART_NBR                     PARENT_PART                  CHILD_PART                   SEQ
    ABC-1                        ABC-1                        ABC-10                        100
    ABC-1                        ABC-10                       ABC-155                       100 100
    ABC-1                        ABC-155                      RAW-2                         100 100 100
    ABC-1                        ABC-155                      HARDWARE-3                    100 100 200
    ABC-1                        ABC-10                       HARDWARE-1                    100 200
    ABC-1                        ABC-1                        ABC-20                        200
    ABC-1                        ABC-20                       RAW-1                         200 100
    ABC-1                        ABC-1                        ABC-30                        300
    ABC-1                        ABC-30                       RAW-3                         300 100
    ABC-1                        ABC-1                        HARDWARE-1                    401
    ABC-1                        ABC-1                        HARDWARE-2                    402

    Hi,
    As long as there's only one root, you can say ORDER SIBLINGS BY, but you can't do that in a sub-query (well, you can, but usually there's no point in doing it in a sub-query). If the CONNECT BY is being done in a sub-query, there is no guarantee that the main query will preserve the hierarchical order that the sub-query provides.
    The query you posted doesn't require a suib-query, so you can say:
    SELECT     CONNECT_BY_ROOT b.parent_part                         AS part_nbr
    ,     b.parent_part
    ,     b.child_part
    --,     SYS_CONNECT_BY_PATH(b.line_nbr,' ')                    AS seq
    FROM     bill_test1 b
    WHERE          CONNECT_BY_ROOT b.parent_part     = 'ABC-1'
    CONNECT BY     parent_part     = PRIOR child_part
    ORDER SIBLINGS BY     b.line_nbr     
    ;I said the query you posted doesn't require a sub-query. It also doesn't require dual, so I suspect what you posted is a simplification of what you're really doing, and that may need a sub-query. In particular, if you intend to GROUP BY part_nbr, then you need the sub-query. We can repeat the CONNECT_BY_ROOT expression in the WHERE clause (or, now that I think about it, use a START WITH clause instead of WHERE), but, for some reason, we can't use CONNECT_BY_ROOT in a GROUP BY clause; we need to compute CONNECT_BY_ROOT in a sub-query, give it a name (like part_nbr), and GROUP BY that column in a super-query.
    This assumes that there is only one root node. ORDER SIBLINGS BY means just that: children of a common parent will appear in order, but the root nodes, who have no parents, will not necessarily be in order.
    Here's what I meant by using START WITH instead of WHERE:
    SELECT     CONNECT_BY_ROOT b.parent_part                         AS part_nbr
    ,     b.parent_part
    ,     b.child_part
    --,     SYS_CONNECT_BY_PATH(b.line_nbr,' ')                    AS seq
    FROM     bill_test1 b
    START WITH     b.parent_part     = 'ABC-1'
    CONNECT BY     parent_part     = PRIOR child_part
    ORDER SIBLINGS BY     b.line_nbr     
    ;This should be much more efficient, because it narrows down the results before you waste time getting their descendants.
    Using a START WITH clause here is analagous to me sending you an e-mail, saying "Come to a meeting a my office at 3:00."
    Using a WHERE clause here is analagous to me sending an e-mail to everyone in the company, saying "Come to a meeting a my office at 3:00", and then, as people get here, telling everyone except you that they can go back.
    ORDER SIBLINGS BY was introduced in Oracle 9.
    Edited by: Frank Kulash on Dec 9, 2010 2:39 PM
    Added version with START WITH clause

  • Where's the metadata for STORE IN clause of a table with partition?

    Hi Experts,
    I created a table with a range-interval partition with STORE IN clause. It's definition:
    CREATE TABLE interval_part (
    person_id NUMBER(5) NOT NULL,
    first_name VARCHAR2(30),
    last_name VARCHAR2(30))
    PARTITION BY RANGE (person_id)
    INTERVAL (100) STORE IN (TSP_1, TSP_2, TSP_3) (
    PARTITION p1 VALUES LESS THAN (101))
    TABLESPACE TSP_1;
    I can not find the metadata for STORE IN clause in ALL_TAB_PARTITIONS, ALL_TABLES. Where is the metadata for the STORE IN clause? How can I find the tablespace list (TSP_1, TSP_2, TSP_3)?
    Thanks,
    David

    DBMS_METADATA.GET_DDL returns the definition of the table. But I just need the value of the tablespace list, for example, TSP_1, TSP_2, TSP_3. Is there any view which stored the value?
    Thanks,
    David

  • Query SQL datastore with XML where clause source

    Hope I am in the right place.  New to Bus Obj Data Services Designer....I have cerated xml schemas, added it to the page as an xml source in.  Mapped a test xml file and all is well there.  I have added a query that grabs the xml.
    I need to then query the MS SQL datastore ans use  the data form the xml query as the where clause.  How is this done?  Or do I put a query on the datastore for all the data in a table then do anotehr query filtering one with the other?  seems like that would be rather heavy and low performance.  The results will then be sent back out as xml (schema and test file already set up as an xml out)
    Thanks!

    Thanks for the tips.
    I'm trying to implement this option, using your ViewDefHelper.
    I´m running into a problem though. After I create my dynamic View Object using a ViewDef, I need to create some view links.
    So I get the AttributeDefs of the columns (source, and destination) from the method findAttributeDef (which is the whole purpose of performance in my post). This method is returning the correct Attribute Def, but when I create the view Link with the method createViewLinkBetweenViewObjects(java.lang.String vlName,
    java.lang.String accessorName,
    ViewObject master,
    AttributeDef[] srcAttrs,
    ViewObject detail,
    AttributeDef[] destAttrs,
    java.lang.String assocClause)
    My destination query is generating the where clause as:
    null = ?
    Any Ideas what I'm doing wrong ?
    Thanks again.
    John.

  • Query with order by clause

    Hi,
    I found a query with order by clause in procedure which is taking long time.
    Stats are upto date.
    Total Rows :650000.
    It is ordered by primary key column.
    select * from table_name order by col1;
    col1 is a primary key.No of cpu's used is 4.
    can anyone suggest me a better solution to improve the performance of a query.
    Is it better to use parallel hint for above scenario.
    Any help really apprecaited.
    Thanks in advance.

    Hi,
    Thanks for ur immediate reply.
    It doesn't have where clause.
    below is the plan
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    Plan hash value: 619071987
    | Id  | Operation                   | Name                 | Rows  | Bytes | Cos
    |   0 | SELECT STATEMENT            |                      |   671K|   255M| 125
    |   1 |  TABLE ACCESS BY INDEX ROWID| FULL_ITEM_FACILITIES |   671K|   255M| 125
    |   2 |   INDEX FULL SCAN           | FIF_PK               |   671K|       |
    9 rows selected
    Executed in 0.094 secondsThanks in advance
    Edited by: unique on Jun 22, 2009 8:26 AM

  • Strange behavior in inner query with group by clause

    Hi All,
    I found a very strange behaviour with Inner query having a group by clause.
    Please look the sample code
    Select b,c,qty from (select a,b,c,sum(d) qty from tab_xyz group by b,c);
    This query gives output by summing b,c wise. But when i run the inner query it gives error as "not a group by expression "
    My question is - though the inner query is wrong, how is it possible that this query gives output.
    it behaves like -
    Select b,c,qty from (select b,c,sum(d) qty from tab_xyz group by b,c);
    Is it a normal behaviour ?
    If it is a normal behaviour, then how group by behaves inside a inner query.
    Thanks !!

    This case I have tested already and it throws error.
    But why the initial posted query is not throwing
    error even the inner query is wrong.
    In what way oracle behaves for the initial posted
    query?what is the scenario that throws the error? is it at the time when you only run the inner query or the whole query?

  • ORA-00604 ORA-00904 When query partitioned table with partitioned indexes

    Got ORA-00604 ORA-00904 When query partitioned table with partitioned indexes in the data warehouse environment.
    Query runs fine when query the partitioned table without partitioned indexes.
    Here is the query.
    SELECT al2.vdc_name, al7.model_series_name, COUNT (DISTINCT (al1.vin)),
    al27.accessory_code
    FROM vlc.veh_vdc_accessorization_fact al1,
    vlc.vdc_dim al2,
    vlc.model_attribute_dim al7,
    vlc.ppo_list_dim al18,
    vlc.ppo_list_indiv_type_dim al23,
    vlc.accy_type_dim al27
    WHERE ( al2.vdc_id = al1.vdc_location_id
    AND al7.model_attribute_id = al1.model_attribute_id
    AND al18.mydppolist_id = al1.ppo_list_id
    AND al23.mydppolist_id = al18.mydppolist_id
    AND al23.mydaccytyp_id = al27.mydaccytyp_id
    AND ( al7.model_series_name IN ('SCION TC', 'SCION XA', 'SCION XB')
    AND al2.vdc_name IN
    ('PORT OF BALTIMORE',
    'PORT OF JACKSONVILLE - LEXUS',
    'PORT OF LONG BEACH',
    'PORT OF NEWARK',
    'PORT OF PORTLAND'
    AND al27.accessory_code IN ('42', '43', '44', '45')
    GROUP BY al2.vdc_name, al7.model_series_name, al27.accessory_code

    I would recommend that you post this at the following OTN forum:
    Database - General
    General Database Discussions
    and perhaps at:
    Oracle Warehouse Builder
    Warehouse Builder
    The Oracle OLAP forum typically does not cover general data warehousing topics.

  • How to group the values with this partition over clause ?

    Hi,
    I have a nice request :
    select  c.libelle "Activité", sum(b.duree) "Durée"
    from    fiche a, activite_faite b,
            activites c, agent d
    where   a.date_activite
    BETWEEN TO_DATE('20/09/2009', 'DD/MM/YYYY') AND TO_DATE('26/10/2009', 'DD/MM/YYYY')
    AND     a.agent_id = 104
    AND     a.fiche_id = b.fiche_id
    AND     b.activites_id = c.activites_id
    AND     a.agent_id = d.agent_id
    group   by c.libelle
    order   by sum(b.duree)It gives me this nice result :
    ACTIVITE  DUREE
         Tonte            27I want to get a percentage, i use ratio_to_report
    select  a.fiche_id, c.libelle "Activité", ratio_to_report(duree) over (partition by c.activites_id) * 100 "Durée"
    from    fiche a, activite_faite b,
            activites c, agent d
    where   a.date_activite
    BETWEEN TO_DATE('20/09/2009', 'DD/MM/YYYY') AND TO_DATE('26/10/2009', 'DD/MM/YYYY')
    AND     a.agent_id = 104
    AND     a.fiche_id = b.fiche_id
    AND     b.activites_id = c.activites_id
    AND     a.agent_id = d.agent_idIt gives me this less nice result :
    Tonte 7,40740740740740740740740740740740740741
    Tonte 33,33333333333333333333333333333333333333
    Tonte 33,33333333333333333333333333333333333333
    Tonte 25,92592592592592592592592592592592592593I would like to get this result :
    Tonte 100I tried "grouping" values in the partition over clause but without success.
    Any help appreciated from the slq-masters :
    Regards,
    Christian

    Christian from France wrote:
    I would like to get this result :
    Tonte 100
    Hi,
    Why not this
    select  c.libelle "Activité", 100 "Durée"
    from    fiche a, activite_faite b,
            activites c, agent d
    where   a.date_activite
    BETWEEN TO_DATE('20/09/2009', 'DD/MM/YYYY') AND TO_DATE('26/10/2009', 'DD/MM/YYYY')
    AND     a.agent_id = 104
    AND     a.fiche_id = b.fiche_id
    AND     b.activites_id = c.activites_id
    AND     a.agent_id = d.agent_id
    group   by c.libelle
    order   by sum(b.duree)Because it would always be 100 (if you are taking as percentage) be what ever the count of duree be.
    Or did I miss something in understanding the requirement.
    Regards
    Anurag

  • Insert performance issue with Partitioned Table.....

    Hi All,
    I have a performance issue during with a table which is partitioned. without table being partitioned
    it ran in less time but after partition it took more than double.
    1) The table was created initially without any partition and the below insert took only 27 minuts.
    Total Rec Inserted :- 2424233
    PL/SQL procedure successfully completed.
    Elapsed: 00:27:35.20
    2) Now I re-created the table with partition(range yearly - below) and the same insert took 59 minuts.
    Is there anyway i can achive the better performance during insert on this partitioned table?
    [ similerly, I have another table with 50 Million records and the insert took 10 hrs without partition.
    with partitioning the table, it took 18 hours... ]
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    Plan hash value: 4195045590
    | Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 643K| 34M| | 12917 (3)| 00:02:36 |
    |* 1 | HASH JOIN | | 643K| 34M| 2112K| 12917 (3)| 00:02:36 |
    | 2 | VIEW | index$_join$_001 | 69534 | 1290K| | 529 (3)| 00:00:07 |
    |* 3 | HASH JOIN | | | | | | |
    | 4 | INDEX FAST FULL SCAN| PK_ACCOUNT_MASTER_BASE | 69534 | 1290K| | 181 (3)| 00:00
    | 5 | INDEX FAST FULL SCAN| ACCOUNT_MASTER_BASE_IDX2 | 69534 | 1290K| | 474 (2)| 00:00
    PLAN_TABLE_OUTPUT
    | 6 | TABLE ACCESS FULL | TB_SISADMIN_BALANCE | 2424K| 87M| | 6413 (4)| 00:01:17 |
    Predicate Information (identified by operation id):
    1 - access("A"."VENDOR_ACCT_NBR"=SUBSTR("B"."ACCOUNT_NO",1,8) AND
    "A"."VENDOR_CD"="B"."COMPANY_NO")
    3 - access(ROWID=ROWID)
    Open C1;
    Loop
    Fetch C1 Bulk Collect Into C_Rectype Limit 10000;
    Forall I In 1..C_Rectype.Count
    Insert test
         col1,col2,col3)
    Values
         val1, val2,val3);
    V_Rec := V_Rec + Nvl(C_Rectype.Count,0);
    Commit;
    Exit When C_Rectype.Count = 0;
    C_Rectype.delete;
    End Loop;
    End;
    Total Rec Inserted :- 2424233
    PL/SQL procedure successfully completed.
    Elapsed: 00:51:01.22
    Edited by: user520824 on Jul 16, 2010 9:16 AM

    I'm concerned about the view in step 2 and the index join in step 3. A composite index with both columns might eliminate the index join and result in fewer read operations.
    If you know which partition the data is going into beforehand you can save a little bit of processing by specifying the partition (which may not be a scalable long-term solution) in the insert - I'm not 100% sure you can do this on inserts but I know you can on selects.
    The APPEND hint won't help the way you are using it - the VALUES clause in an insert makes it be ignored. Where it is effective and should help you is if you can do the insert in one query - insert into/select from. If you are using the loop to avoid filling up undo/rollback you can use a bulk collect to batch the selects and commit accordingly - but don't commit more often than you have to because more frequent commits slow transactions down.
    I don't think there is a nologging hint :)
    So, try something like
    insert /*+ hints */ into ...
    Select
         A.Ing_Acct_Nbr, currency_Symbol,
         Balance_Date,     Company_No,
         Substr(Account_No,1,8) Account_No,
         Substr(Account_No,9,1) Typ_Cd ,
         Substr(Account_No,10,1) Chk_Cd,
         Td_Balance,     Sd_Balance,
         Sysdate,     'Sisadmin'
    From Ideaal_Cons.Tb_Account_Master_Base A,
         Ideaal_Staging.Tb_Sisadmin_Balance B
    Where A.Vendor_Acct_Nbr = Substr(B.Account_No,1,8)
       And A.Vendor_Cd = b.company_no
          ;Edited by: riedelme on Jul 16, 2010 7:42 AM

  • Query hangs with outer query

    Hi,
    OS: SPARC 64 bit
    Oracle Version: 10.2.0.3.0 64 bit
    My query hangs when I include the outer query. When I execute without outer query It comes out in a fraction of second but when I includes outer query it starts hang
    Below is my original query which hangs
    select * from (select raw_sql_.**, rownum raw_rnum_ from (SELECT /*+ FIRST_ROWS */ NETWORK_ID||'","'||CALLER_NUMBER||'","'||CALLED_NUMBER FROM CDR FROM CDR WHERE 1 = 1
    AND day_of_year = 99 AND INTERFACE = 'TRAFIC' AND TIME_STAMP BETWEEN to_date('2009/04/08 00:00:00','yyyy/mm/dd hh24:mi:ss') AND to_date
    ('2009/04/09 00:00:00','yyyy/mm/dd hh24:mi:ss') AND NETWORK_ID IN (1025,1026) order by id desc) raw_sql_ WHERE rownum <= 10000) WHERE raw_rnum_ > 0;
    when I execute this it will come out immediately
    select raw_sql_.**, rownum raw_rnum_ from (SELECT /*+ FIRST_ROWS */ NETWORK_ID||'","'||CALLER_NUMBER||'","'||CALLED_NUMBER FROM CDR FROM CDR WHERE 1 = 1
    AND day_of_year = 99 AND INTERFACE = 'TRAFIC' AND TIME_STAMP BETWEEN to_date('2009/04/08 00:00:00','yyyy/mm/dd hh24:mi:ss') AND to_date
    ('2009/04/09 00:00:00','yyyy/mm/dd hh24:mi:ss') AND NETWORK_ID IN (1025,1026) order by id desc) raw_sql_ WHERE rownum <= 10000
    select * from (select raw_sql_.**, rownum raw_rnum_ from (SELECT /*+ FIRST_ROWS */ NETWORK_ID||'","'||CALLER_NUMBER||'","'||CALLED_NUMBER FROM CDR FROM CDR WHERE 1 = 1
    AND day_of_year = 99 AND INTERFACE = 'TRAFIC' AND TIME_STAMP BETWEEN to_date('2009/04/08 00:00:00','yyyy/mm/dd hh24:mi:ss') AND to_date
    ('2009/04/09 00:00:00','yyyy/mm/dd hh24:mi:ss') AND NETWORK_ID IN (1025,1026) order by id desc) raw_sql_ WHERE rownum <= 10000) WHERE raw_rnum_ > 0;
    but when I includes outer query I hangs it is really very weird for me?
    Here is the explain plan for that query
    Execution Plan
    Plan hash value: 3493649369
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |
    | 0 | SELECT STATEMENT | | 1 | 2015 | 1 (0)| 00:00:01 | | |
    |* 1 | VIEW | | 1 | 2015 | 1 (0)| 00:00:01 | | |
    |* 2 | COUNT STOPKEY | | | | | | | |
    | 3 | PARTITION RANGE SINGLE | | 1 | 5894 | 1 (0)| 00:00:01 | 99 | 99 |
    | 4 | PARTITION LIST ALL | | 1 | 5894 | 1 (0)| 00:00:01 | 1 | 48 |
    |* 5 | TABLE ACCESS BY LOCAL INDEX ROWID| CDR | 1 | 5894 | 1 (0)| 00:00:01 | 4705 | 4752 |
    | 6 | BITMAP CONVERSION TO ROWIDS | | | | | | | |
    |* 7 | BITMAP INDEX SINGLE VALUE | IX_CDR_INTERFACE | | | | | 4705 | 4752 |
    Predicate Information (identified by operation id):
    1 - filter("RAW_RNUM_">0)
    2 - filter(ROWNUM<=10000)
    5 - filter("DAY_OF_YEAR"=99 AND "TIME_STAMP">=TO_DATE('2009-04-08 00:00:00', 'yyyy-mm-dd hh24:mi:ss') AND
    "TIME_STAMP"<=TO_DATE('2009-04-09 00:00:00', 'yyyy-mm-dd hh24:mi:ss') AND ("NETWORK_ID"=1025 OR
    "NETWORK_ID"=1026))
    7 - access("INTERFACE"='TRAFIC')
    can one explain why it happen? what could be the reason? Is it a bug or something? what should I do now? Issue is critical in the production enviromentent
    Waiting for your Valuable Reply
    Thanks In Advance
    With Regards
    Boo

    user454189 wrote:
    I suspect the issue with the where clause (raw_rnum_ > 0)
    Actually I using bitmap index on ' INTERFACE' column. Does it causing a prob or raw_rnum_ causing a problem?Boo,
    a couple of comments:
    1. Why do you use the deprecated FIRST_ROWS hint? From 9i on the FIRST_ROWS_n mode should be used instead, and since you're using a top-N query format the hint should be superfluous anyway since the optimizer should switch to FIRST_ROWS_n mode automatically.
    2. Why do you use a BITMAP index and not a conventional b*tree index? Let me hazard a guess: Because the INTERFACE column has a small number of distinct values? That would be in most cases a bad idea.
    3. What seems to be odd that you're accessing the data via the BITMAP index on INTERFACE, but request an ORDER BY ID DESC. But there is no order by in the execution plan posted. I wonder where the order should come from? Can you show us the DDL of the bitmap index?
    4. What does the plan look like if you run only the inner query without the outer query?
    You can always gain more information by tracing the statement execution or using the GATHER_PLAN_STATISTICS hint together with the DBMS_XPLAN.DISPLAY_CURSOR function.
    Please read this HOW TO: Post a SQL statement tuning request - template posting that explains what you should provide if you have SQL statement tuning question and how to format it here so that the posted information is readable by others.
    This accompanying blog post shows step-by-step instructions how to obtain that information.
    Regards,
    Randolf
    Oracle related stuff blog:
    http://oracle-randolf.blogspot.com/
    SQLTools++ for Oracle (Open source Oracle GUI for Windows):
    http://www.sqltools-plusplus.org:7676/
    http://sourceforge.net/projects/sqlt-pp/

  • Table creation with partition

    following is the table creation script with partition
    CREATE TABLE customer_entity_temp (
    BRANCH_ID NUMBER (4),
    ACTIVE_FROM_YEAR VARCHAR2 (4),
    ACTIVE_FROM_MONTH VARCHAR2 (3),
    partition by range (ACTIVE_FROM_YEAR,ACTIVE_FROM_MONTH)
    (partition yr7_1999 values less than ('1999',TO_DATE('Jul','Mon')),
    partition yr12_1999 values less than ('1999',TO_DATE('Dec','Mon')),
    it gives an error
    ORA-14036: partition bound value too large for column
    but if I increase the size of the ACTIVE_FROM_MONTH column to 9 , the script works and creates the table. Why is it so ?
    Also, by creating a table in this way and populating the table data in their respective partitions, all rows with month less than "JULY" will go in yr7_1999 partition and all rows with month value between "JUL" and "DEC" will go in the second partition yr12_1999 , where will the data with month value equal to "DEC" go?
    Plz help me in solving this problem
    thanks n regards
    Moloy

    Hi,
    You declared ACTIVE_FROM_MONTH VARCHAR2 (3) and you try to check it against a date in your partitionning clause:TO_DATE('Jul','Mon')so you should first check your data model and what you are trying to achieve exactly.
    With such a partition decl, you will not be able to insert dates from december 1998 included and onward. The values are stricly less than (<) not less or equal(<=) hence such lines can't be inserted. I'd advise you to check the MAXVALUE value jocker and the ENABLE ROW MOVEMENT partitionning clause.
    Regards,
    Yoann.

Maybe you are looking for

  • Have 2 or more fill in the blank on one slide

    How is it possible to have 2 or more fill in the blank options in Captivate 8? I have seen posts on here that link to now closed websites.  If anyone could give some advice I would appreciate it hugely. Thanks

  • Problems with old(ish) EIDE drive in new Neo4 system

    I've been building my new system today, the only components I have retained are the optical and hard drives and the memory. System is as follows K8N Neo4 (non SLI edition) Athlon 64 3700+ PC3200 Crucial 1Gb (2x512Mb sticks in dual channel) BFG 7800GT

  • Tcp/ip  bconnection to host has failed,connection refused

    Exception in thread "main" com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host has failed. java.net.ConnectException: Connection refused: connect at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(Un

  • How to save photoshop CS5 extended edited photos in iphoto on Mac?

    Hi this is my first post on here, so i'm unsure if i have put my question in the right place? etc....? I have only just purchased CS5 extended and have just been on a intro course, and today decided to edit a few of my photos in photoshop. i opened m

  • Failed to execute 'postMessage' on 'DOMWindow':

    When I create a SharePoint Provider hosted App in visual studio, visual studio creates two projects: App and web application. both projects runs over HTTPS I created a list in the App and entered some random data. Now, I need to get the data I entere