Why oh why, weird performance on joining large tables

Hello.
I have a large table cotaining dates and customer data. Organised as:
DATE CUSTOMER_ID INFOCOLUMN1 INFOCOLUMN2 etc...
Rows per date are a couple of million.
What I'm trying to do is to make a comparison between date a and date b and track changes in the database.
When I do a:
SELECT stuff
FROM table t1
INNER JOIN table t2
  ON t1.CUSTOMER_ID = t2.CUSTOMER_ID
WHERE t1.date = TO_DATE(SOME_DATE)
AND t2.date = TO_DATE(SOME_OTHER_DATE)I get a result in about 40 seconds which is acceptable.
Then I try doing:
SELECT stuff
FROM (SELECT TO_DATE(LAST_DAY(ADD_MONTHS(SYSDATE, 0 - r.l))) AS DATE FROM dual INNER JOIN (SELECT level l FROM dual CONNECT BY LEVEL <= 1) r ON 1 = 1) time
INNER JOIN table t1
  ON t1.date = time.date
INNER JOIN table t2
  ON t1.CUSTOMER_ID = t2.CUSTOMER_ID
WHERE t2.date = ADD_MONTHS(time.date, -1)Ie i generate a datefield from a subselect which I then use to join the tables with.
When I try that the query takes an hour or two to complete with the same resultset as the first example.
THe only difference is that in the first case I give the dates literally but in the other case I generate them in the subselect. It's the same dates and they are formatted as dates in both cases.
Any ideas?
Thanks
Edited by: user1970293 on 2010-apr-29 00:52
Edited by: user1970293 on 2010-apr-29 00:59

When I try that the query takes an hour or two to complete with the same resultset as the first example.If you get the same results, than why change the query to the second one?
THe only difference is that in the first case I give the dates literally but in the other case I generate them in the subselect. It's the same dates and they are formatted as dates in both cases.Dates are dates,... the formatting is just "pretty"
This
select to_date(last_day(add_months(sysdate
                                  ,0 - r.l)))
  from dual
inner join (select level l from dual connect by level <= 1) r on 1 = 1doesn't make much sense... what is it supposed to do?
(by the way: you are doing a TO_DATE on a DATE...)

Similar Messages

  • Performance during joining large tables

    Hi,
    I have to maintain a report which gets data from many large tables as below. Currently it is using join statement to join all 8 tables and causing a very slow performance.
    SELECT
        into corresponding fields of table equip
        FROM caufv
                  join afih on afih~aufnr = caufv~aufnr
                  join iloa on iloa~iloan = afih~iloan
                  join iflos  on iflos~tplnr = iloa~tplnr
                  join iflotx on iflos~tplnr = iflotx~tplnr
                  join vbak on vbak~aufnr = caufv~aufnr
                  join equz on equz~equnr = afih~equnr
                  join equi on equi~equnr = equz~equnr
                  join vbap on vbak~vbeln = vbap~vbeln
        WHERE
    Please suggest me another way, I'm newbie in ABAP. I tried using FOR ALL ENTRIES IN but it did not work. I would very appreciate if you can leave me some sample lines of code.
    Thanks,

    Hi Dear ,
    I will suggest you not to use inner join for such i.e. 8 number of table and that too huge tables. Instead use For All entries wherever possible. But before using for all entries check initial for base table and if its not possible to avoid inner join then try to minimise it. Use inner join between header and item.
    Hope this will help you to solve your problem . Feel free to ask if you have any doubt.
    Regards,
    Vijay

  • MKPF & MSEG Performance issue : Join on table  MKPF & MSEG  taking too much time ..

    Hello Experts,
    I had a issue where we are executing one custom report in which  i used inner join on table  MKPF & MSEG,  some time join statement  took  9-10 min to excute and some time execute within  1-2 min with same test data .
    i am not able to understand what the actaully happing .
    please help.
    code :
       SELECT f~mblnr f~mjahr f~usnam f~bktxt  p~bukrs
        INTO TABLE itab
        FROM mkpf AS f INNER JOIN mseg AS p
            ON f~mblnr = p~mblnr AND f~mjahr = p~mjahr
         WHERE f~vgart = 'WE'
           AND f~budat IN p_budat
           AND f~usnam IN p_sgtxt
           AND p~bwart IN ('101','105')
           AND p~werks IN p_werks
           AND p~lgort IN p_lgort.
    Regards,
    Dipendra Panwar.

    Hi Dipendra,
    if you call a report twice after another with the same test data for data selection, then the second run should be faster, because some data are remaining in memory and needn't to be caught from database. This will be also for the following third und further runs, until the data in the SAP memory will be removed by other programs.
    For performance traces you should try to test with a first run.
    Regards,
    Klaus

  • Performing multiple joins on table

    Hi all,
       I would like to know if performing joins on more than 10 tables has some performance issues? If so, is there any limit on the joins that can be done?
    Is there another way out for this problem?

    Rob Burbank wrote:>
    > >
    Thomas Zloch wrote:
    > > If I had to bet, I'd say no, not included...do you have time to try out with a little test program?
    > Probably not so little, but maybe sometime. I know there are standard SAP views with upwards of 13 or 14 tables, but I doubt if they would be compatable for joining.
    >
    > Rob
    How about a self join? 

  • Slow performance of Query-Large Table how to optimize for performance

    Hi Friends,
    I am an ORacle DBA and just recently I have been asked to Administer an ORacle HRMS Database as a substitute for the HRMS DBA who have gone on vacation.
    I have been reported that few queries are taking a long time to refresh and populate the forms. After some investigation it is found that the tables: HR.PAY_ELEMENT_ENTRY_VALUES_F has some more than 15 million rows in it. The storage parameters specified for table r Oracle Defaults. The table has grown a lot big and even a Count(*) takes more than 7 mins to respond.
    My question is: Is there anyway it can be tuned for better performance without an overhaul. Is it normal for this table to grow this big for 6000 employees data for 4 years....
    Any response/help in this regard will be appreciated. U may please ans me at [email protected]
    Thanks in Advance.
    Rajeev.

    That was a good suggestion by Karthick_Arp, but there is a chance that it is not logically identical depending on the data (I believe that is the reason for his warning).
    Try this rewrite, which moves T6 to an inline view and uses the DECODE function to determine if the one row returned from T6 should be used:
    SELECT
      ASSOC.NAME_FIRST || ' ' || ASSOC.NAME_LAST AS CLIENT_MANAGER
    FROM
      T1 ASSOC,
      T2 CE,
      T3 AA,
      T4 ACT,
      T5 CC,
      (SELECT
        CA.ASSOC_ID
      FROM
        T6 CA
      WHERE
        CA.COMP_ID = :P_ENT_ID
        AND CA.CD_CODE IN ('CMG','RCM','BCM','CCM','BAE')
      GROUP BY
        CA.ASSOC_ID) CA
    WHERE
      CE.ENT_ID = ACT.PRIMARY_ENT_ID(+)
      AND CE.ENT_ID = :P_ENT_ID
      AND ASSOC.ID = DECODE(AA.ASSOC_ID, NULL, CA.ASSOC_ID, AA.ASSOC_ID)
      AND NVL(ACT.ACTIVITY_ID, 0) = NVL(AA.ACTIVITY_ID, 0)
      AND ASSOC.BK_CODE = CC.CPY_NO
      AND ASSOC.CENTER = CC.CCT_NO
      AND AA.ROLE_CODE IN ('CMG', 'RCM', 'BCM', 'CCM', 'BAE');Charles Hooper
    IT Manager/Oracle DBA
    K&M Machine-Fabricating, Inc.

  • Performance for join 9 custom table with native SQL ?

    Hi Expert,
    I need your opinion regarding performance to join 9 tables with native sql. Recently i have to tunning some customize extraction cost  report. This report extract about 10 million cost of material everyday.
    The current program actually, try to populate the condition data and insert into customize table and join all the table to get data using native sql.
    SELECT /*+ ordered use_hash(mst,pg,rg,ps,rs,dpg,drg,dps,drs) */
                mst.werks, ....................................
    FROM
                sapsr3.zab_info mst,
                sapsr3.zab_pc pg,
                sapsr3.zab_rc rg,
                sapsr3.zab_pc ps,
                sapsr3.zab_rc rs,
                sapsr3.zab_g_pc dpg,
                sapsr3.zab_g_rc drg,
                sapsr3.zab_s_pc dps,
                sapsr3.zab_s_rc drs
            WHERE mst.zseq_no = :p_rep_run_id
            AND mst.werks = :p_werks
            AND mst.mandt = rg.mandt(+)
            AND mst.ekorg = rg.ekorg(+)
            AND mst.lifnr = rg.lifnr(+)
            AND mst.matnr = rg.matnr(+)
            ...............................................   unitl all table (9 tables)
            AND ps.mandt = dps.mandt(+)
            AND ps.knumh = dps.knumh(+)
            AND ps.zseq_no = dps.zseq_no(+)
            AND COALESCE (dps.kbetr, drs.kbetr, dpg.kbetr, drg.kbetr) <> 0
    It seems the query ask for database to using hashed table. would that be it will burden the database ? and impacted to others sap process ?
    Please advise
    Thank You and Best Regards

    you can only argue coming from measurements and that is not the case.
    Coming from the code, I see only that you do not understand it at all, so better leave it as it is. It is not a hash table, but a hash join on these table.

  • Join Two tables in UI So that it look like one table.

    Can anyone provide me how to join table in viewing..
    Rite now i am reteiving fields in one table and other field in another table. But while viewing i want to join on UI.
    I am getting gap between these 2 tables.
    How to do that?
    Thanks

    Hi Nitin,
    why you want to join two tables.? if you want to display the data from more then one data source (Node ) then you can use table variant in that case. See the following Links for reference hope it will help.
    [Using Table Cell Variants in NW 2004s|http://wiki.sdn.sap.com/wiki/display/WDJava/UsingTableCellVariantsinNW2004s]
    [Play Sudoku: Using Table Cell Variants in Web Dynpro Java|http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/c0310fd2-f40d-2a10-b288-bcbe0810a961]
    Regards
    Jeetendra

  • Join multiple tables across separate databases

    I needed to perform a join on multiple tables in two separate databases. I am using Sybase ASE 12.5 and jConnect 5.5 JDBC driver.
    Table A is in DB1 and Table B is in DB2. Both DB1 and DB2 reside on the same database server.
    I have set up JNDI bound datasources DS1 for DB1 and DS2 for DB2.
    If the queries involved single tables or multiple tables within the same database, it is simple. But I am not seeing any way where I can perform a join between Tables A and B, which reside in separate databases. The datasources DS1 and DS2 are associated with DB1 and DB2 respectively, so I am not sure if there is anything like performing joins using two data sources.
    One alternative I am facing is using a stored procedure in one database refer the table in the other database, for the join. But I may not be allowed to modify the database; currently, I am allowed to perform READ-ONLY queries.
    So I am looking for any and all options. Please advice.
    Thanks!

    Two choices..
    One find the syntax in DB2 that allows you to do what you want in there. That would often be somelike...
    select a.myfield
    from database1.table1 a, database2.table2 b
    where a.id = b.id
    Obviously the database itself must support this. If it doesn't then you have choice two.
    You extract the data from database1 using java for table1.
    You extract the data from database2 using java for table2.
    You write java code that merges the data from both sources.

  • Why Left and Right Joins if only one of them can serve the same purpose?

    I understand that left join is used to display all the records from left table whereas the right join is used to display all the records from right table in a join.
    However, if we switch the positions of the join tables and perform left join we can get all the records of the left table.
    A left join B -> will give all records from A
    A right join B ->will give all records from B
    B left join A -> will again give all records from B.
    The order in which the data is displayed(ie the field order) can also be maintained in the SELECT clause.
    So, Why do we have left and right joins separately in existance, when only one of them can serve the same purpose?

    Hi,
    I think it's because it is sometime more natural to outer join on left or right.
    In your data model (or the query you are writing), there is some kind of hierarchy between tables : I feel more natural to have the table with lowest hierarchical level (the root table) on the left. So I sometimes prefer to right outer join...
    This is a very personal feeling, I must admit.
    To me what is strange is to have chosen left and right as they refer to a "latin" reading direction => forward join and backward join would be more meaningful for people that read from right to left.
    +And I prefer the new joining syntax that doesn't us the {noformat}(+){noformat} sign...+

  • Why can't I join a network with my IPhone with IOS7?

    Why can't I join a network with my IPhone with IOS7?

    Hi gvtxman,
    The articles below may be able to help you troubleshoot your Wi-Fi issue.
    iOS: Troubleshooting Wi-Fi networks and connections
    http://support.apple.com/kb/TS1398?viewlocale=en_US
    Reset network settings by tapping Settings > General > Reset > Reset Network Settings.
    Note: This will reset all network settings including previously connected Wi-Fi networks and passwords
    iOS and OS X: Recommended settings for Wi-Fi routers and access points
    http://support.apple.com/kb/HT4199
    I hope this information helps ....
    Have a great day!
    - Judy

  • Why can I not join the wifi in the hotel when I am out of the country UK with data roaming turned off, Why can I not join the wifi in the hotel when I am out of the country UK with data roaming turned off

    Why can I not join the wi fi in the hotel on my I.phone using iso7 ???? I have turned off data roaming any ideas?????

    is it free or do you have to sign up and pay and is there a password
    Havee you asked the hotel ???

  • Why do the icons become large

    Why do the icons become large on the ipad mini and how do you fix the issue?

    Check to see if you have Settings > General > Accessibility > Zoom turned On. If so, turn it off.

  • Why can't I join multiple apple id's?

    Why can't I join multiple apple id's? I made a mistake, purchased apps in both now I want everything running through the same Id. I'm not asking for much here.

    Apple's policy states that Apple ID accounts cannot be merged.
    Frequently Asked Questions About Apple ID

  • Why do e-mails containing large attachments fail to deliver to my inbox?

    Why do e-mails containing large attachments fail to deliver to my inbox?

    This may be a limitation to the size of the attachments your ISP will allow. Please check with your ISP first to see the maximum size attachment they will accomodate.

  • Why is Music Folder So Large?

    At the bottom of my iTunes window, it shows my library has 23,346 songs, which accounts for 80GB on my iMac. However, when I check the iTunes Music folder, it says it has 25,649 files, and takes up 120GB. Why is this so much larger???
    I do not have much album artwork included. The album artwork folder is only 65MB.
    Since I have used 75% of my 500GB hard drive, I am looking for places to save space. Any ideas why the Music Folder is so big?

    Your Library view shows how much music iTunes knows about. It doesn't include video for example, you would have to look in your Video window for that. Podcasts etc, are separate too.
    Also, if you ever deleted tracks from iTunes without 'Moving to Trash', they will still be in your Music folder.
    As there is a less than 10% difference in total files, but a 33% discrepancy in size the likeliest cause could be video - do you have video?

Maybe you are looking for

  • How can I watch purchased itunes shows on my tv w/o apple tv?

    I bought the Futurama season pass and I want to watch the episodes in 50 inch HD, but I don't have apple tv and myimac is too far from the tv for a cable so how can I do this? I have a google tv box that will talk to my pc laptop, and an xbox 360 wit

  • How can I print my icloud calendar?

    is there a way to get a full page printout of my monthly icloud calendar?

  • Windows media player on Startup

    On startup windows media player is running even after being closed prior to shutdown. Another windows bug to be fixed, makes me think I should have bought an Apple.

  • User default format in printing inventory list

    Hi experts, I have a question about the user default print format. When I try to print out a output for inventory list, the print format turn to be a format that I donu2019t want to use, I have to change the format manually everytime. Is there any me

  • Uses a non-entity as target entity

    Hi everyone, I need your help because I am working on a project j2ee6 I am using jpa (eclipseLink) when I created entities without relation, all worked perfectly but now that I am trying to set up relation @oneTomany @ManyToOne I got this error all t