简体   繁体   中英

SQL query optimization Oracle

I have this SQL query that first selects from a relative short table a number that is used after for another select, this time from a very large table, certain info using the code from the first one. This takes more than 30 minutes for only one select and i need to optimize as i have to run 300 selects like this one but with different SWNAMEs. I would appreciate any hints and tips that you can give me. Thank you !

SELECT SWOBJECTID 
FROM   MBR_INST_PRODUCTS 
WHERE  SWPRODRELEASEID IN 
       (SELECT SWPRODRELEASEID 
        FROM   ORO_PPY_OPTIONS 
        WHERE  SWNAME LIKE 'Nov Flexibil Offer:Net Unlimited for 1MON')
AND rownum <2;

How about a simple join?

SELECT m.swobjectid
  FROM mbr_inst_products m
       JOIN oro_ppy_options o ON o.swprodreleaseid = m.swprodreleaseid
 WHERE     o.swname = 'Nov Flexibil Offer:Net Unlimited for 1MON'
       AND ROWNUM < 2;

Make sure swprodreleaseid columns are indexed.

I would write this query as:

SELECT ip.SWOBJECTID 
FROM  MBR_INST_PRODUCTS ip JOIN
      ORO_PPY_OPTIONS po
      ON po.SWPRODRELEASEID = ip.SWPRODRELEASEID
WHERE po.SWNAME = 'Nov Flexibil Offer:Net Unlimited for 1MON') AND
      rownum = 1;

For this query, you want indexes on ORO_PPY_OPTIONS(SWNAME, SWPRODRELEASEID) and MBR_INST_PRODUCTS(MBR_INST_PRODUCTS) .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM