473,509 Members | 2,763 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Tuning SQL statements

35 New Member
Can somebody please help me enhance this sql statement to run faster.




Expand|Select|Wrap|Line Numbers
  1. CREATE VIEW tryView AS
  2. (SELECT ser_id, (SELECT dy_id FROM dy WHERE ser.dsy_id=dy_rid) as new_dy_id FROM sequence ser
  3. WHERE dsy_id IN (SELECT dy_rid FROM dy WHERE dy_id IN (SELECT dy_id FROM lookuptab GROUP BY dy_id HAVING count(*) = 1)))
  4.   UNION
  5. (SELECT 
  6.   ser_id, 
  7.   substr(
  8.     concat(
  9.       concat((SELECT dy_id FROM dy WHERE ser.dsy_id=dy_rid), '.'), 
  10.       (SELECT count(*) FROM lookuptab am 
  11.       WHERE 
  12.         isused='YES' and 
  13.         am.dy_id=(SELECT dy_id FROM dy WHERE dy_rid = ser.dsy_id)
  14.       )
  15.     ), 
  16.     1,
  17.     64
  18.   ) 
  19.   as new_dy_id
  20. FROM series ser
  21. WHERE dsy_id IN (SELECT dy_rid FROM study WHERE dy_id IN (SELECT dy_id FROM lookuptab GROUP BY dy_id HAVING count(*) > 1)));
Feb 11 '08 #1
4 1573
subashsavji
93 New Member
Can somebody please help me enhance this sql statement to run faster.


Code: ( oracle8 )
try to use index on that columns which in beging used in the conditional clause
use proper index which suitable for your query.
Feb 12 '08 #2
Dave44
153 New Member
Can somebody please help me enhance this sql statement to run faster.


Code: ( oracle8 )
ok, first it would help us a lot if you could provide the create table statements for us, it makes it easier for us to help you.

second as a general rule of thumb you want to avoid using IN and NOT IN unless the lists are very small or specific strings which you hard code in and DONT CHANGE. unless the IN list is some static strings you usually can replace an IN with a JOIN and similarly a NOT IN with an ANTI-JOIN.
And you definately want to avoid nested IN statements like the plague. Do some reading on how oracle must process an IN list and you will understand why large IN lists are a performance killer.

so while i dont have the tables and thus cannot test this out the first part of your union query would become something like this:
Expand|Select|Wrap|Line Numbers
  1. SELECT ser_id,
  2.        dy_id
  3. FROM   sequence ser,
  4.        dy,
  5.        (SELECT dy_id 
  6.         FROM   lookuptab 
  7.         GROUP  BY dy_id 
  8.         HAVING count(*) > 1) lut
  9. WHERE  lut.dy_id = dy.dy_id
  10. AND    ser.dsy_id = dy.dy_rid
  11.  
other than what i have written i would really need table and index create statements to see what the query is doing.

there are so many factors involved in tuning there literally are whole volumes books written on the subject. things like size of tables, poorly written SQL, are indexes being used by the RBO or hints needed. lots of stuff.
Feb 12 '08 #3
kwartz
35 New Member
Here are the tables. Thanks

code (oracle 8)
Expand|Select|Wrap|Line Numbers
  1. DROP TABLE Lookuptab;
  2. CREATE TABLE Lookuptab (
  3.   DY_ID         VARCHAR2(64) NOT NULL,
  4.   ACCN_NUM         VARCHAR2(16) NOT NULL,
  5.   COMBO_DY_COUNT  VARCHAR2(4) DEFAULT 0 NOT NULL,
  6.   ISUSED           VARCHAR2(3) DEFAULT 'NO' NOT NULL,
  7.   UNIQUE (ACCN_NUM)
  8. );
  9.  
  10. CREATE INDEX AM_ISUSED ON Lookuptab (ISUSED);
  11. CREATE INDEX AM_DY_ID ON Lookuptab (DY_ID);
  12. --CREATE INDEX AM_ACCN_NUM ON Lookuptab (ACCN_NUM);
  13.  
  14. COMMIT;
  15.  
  16.  
  17.  
  18.  
  19.  
  20. SQL> desc dy
  21.  Name                                      Null?    Type
  22.  ----------------------------------------- -------- --------------------
  23.  DY_RID                                   NOT NULL NUMBER(9)
  24.  SPAT_RID                                 NOT NULL NUMBER(9)
  25.  SVIS_RID                                           NUMBER(9)
  26.  SRP_RID                                            NUMBER(9)
  27.  DY_ID                                    NOT NULL VARCHAR2(64)
  28.  SDY_ID                                           VARCHAR2(16)
  29.  STD_LAST_UPD_DATE                                  DATE
  30.  STD_STATUS_ID                                      VARCHAR2(16)
  31.  STD_LOCK                                           VARCHAR2(64)
  32.  STD_LOCK_LOCATION                                  VARCHAR2(64)
  33.  STD_MARKED_BY                                      VARCHAR2(64)
  34.  STD_MARK_LOCATION                                  VARCHAR2(64)
  35.  MOD_ID                                           VARCHAR2(64)
  36.  STD_PRI_ID                                         VARCHAR2(16)
  37.  SCH_STD_START_DATE                                 DATE
  38.  SCH_STD_STOP_DATE                                  DATE
  39.  SCH_STD_LOC                                        VARCHAR2(64)
  40.  REASON_FOR_STD                                     VARCHAR2(64)
  41.  STD_ARRIVAL_DATE                                   DATE
  42.  STD_DATE                                           DATE
  43.  STD_COMPLETION_DATE                                DATE
  44.  STD_VERIF_DATE                                     DATE
  45.  STD_ID_ISSUER                                      VARCHAR2(64)
  46.  NUM_SERIES                                         VARCHAR2(12)
  47.  NUM_ACQS                                           VARCHAR2(12)
  48.  STD_READ_DATE                                      DATE
  49.  STD_DESCRIPTION                                    VARCHAR2(64)
  50.  STD_COMPO_STATUS_ID                                VARCHAR2(10)
  51.  SCH_STD_LOC_AE_TITLES5                             VARCHAR2(85)
  52.  STD_COMMENTS                                       VARCHAR2(4000)
  53.  READING_PHYS5                                      VARCHAR2(325)
  54.  PROC_CODE_SQ1                                      VARCHAR2(16)
  55.  PERF_PHYS_NAMES                                    VARCHAR2(325)
  56.  OTHER_STUDY_NUMS5                                  VARCHAR2(65)
  57.  STD_STATUS                                         VARCHAR2(16)
  58.  STD_EVER_COMPLETED                                 VARCHAR2(1)
  59.  STD_TR_LOCK                                        VARCHAR2(64)
  60.  STD_TR_LOCK_LOCATION                               VARCHAR2(64)
  61.  STD_STAT                                           VARCHAR2(1)
  62.  STD_STAGE                                          VARCHAR2(16)
  63.  STD_REL_IMG_SEND                                   VARCHAR2(1)
  64.  
Feb 12 '08 #4
amitpatel66
2,367 Recognized Expert Top Contributor
Try this query:

Expand|Select|Wrap|Line Numbers
  1. CEATE view tryview AS
  2. (SELECT s.ser_id, 
  3.  select dy_id from dy where dy_rid = d.dy_rid) as new_dy_id
  4. FROM sequence ser, dy d 
  5. WHERE ser.dsy_id = d.dy_rid
  6. AND d.dy_id IN (SELECT dy_id FROM lookuptab GROUP BY dy_id HAVING COUNT(*) = 1))
  7. UNION
  8. (SELECT s.ser_id,SUBSTR(d.dy_id||'.'||(select count(*) from lookuptab WHERE isused='YES' AND dy_id = d.dy_id),1,64) AS new_dy_id
  9. FROM series ser, dy d 
  10. WHERE ser.dsy_id = d.dy_rid
  11. AND ser.dsy_id IN (SELECT dy_rid FROM study WHERE dy_id IN (SELECT dy_id FROM lookuptab GROUP BY dy_id HAVING COUNT(*) > 1)));
  12.  
Feb 12 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
2895
by: Maryam | last post by:
Hi, I am having problems getting anything useful out of the index tuning wizard. I have created a table and inserted data into it. When i run the index tuning wizard i expect 2 indexes to be...
12
8319
by: serge | last post by:
I have an SP that is big, huge, 700-800 lines. I am not an expert but I need to figure out every possible way that I can improve the performance speed of this SP. In the next couple of weeks I...
1
1637
by: kmounkhaty | last post by:
Hi Guru, My company, every thing we need is to buy from a vendor. However, we have PEOPLESOFT CRM app that has around 6000 tables and around 5000 views and none stored proc. We start seeing the...
1
2027
by: Jean-Marc Blaise | last post by:
Hi, I find much regrettable that Database Engine Tuning Advisor be not part of MS-Express Edition ... A server without such help is not a server. Besides, you've got the tutorials, but not the...
0
1226
by: meytal.weiss | last post by:
Hi, I am using the dta utility successfully. I have problem to tune query without specifying the schema as prefix in case the tuning session is not with the login that own the schema, the dta...
3
2020
by: mleal | last post by:
Does anyone have some more detailed information about how Oracle and MS implement / allow Tuning on Oracle 10g and SQL Server 2005 and the differences between them? Which of them, In a deep...
13
4578
by: atlaste | last post by:
Hi, I'm currently developing an application that uses a lot of computational power, disk access and memory caching (to be more exact: an information retrieval platform). In these kind of...
0
20305
by: Medhatithi | last post by:
Hi, I have been in several ways benefiited from this site. I would like to share some sql tuning techniques(simple, but effective) with you all. SQL Tuning Tips Oracle Tips Session #6 ...
4
3076
by: Tommy Hayes | last post by:
Hello all, I want to use the SQL Server 2005 Tuning Advisor on our database, and I'm hoping someone here can just confirm the steps for me. We have a 10GB database that has a number of...
3
7893
by: dunleav1 | last post by:
In 9.1 and 9.5 (Linux 64 bit) when a buffer pool is set to self- tuning, how are blocks configured in respect to blocked vs non-blocked when self-tuning is set to on? (ie) I have one bufferpool...
0
7233
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7135
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7342
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7410
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7067
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5650
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3215
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3201
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1570
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.