The ultimate way to optimize SQL statements?
Hi all
I hope that this discovery you in a good mood
I have a few SQL I need to optimize.
In your experience what is the best way to find all the bottlenecks 'True' in the SQL itself.
It's my workflow:
Step 1:
Explain the plain: find all the analyses of full Table right at the front.
Step 2:
Run the SQL through Grid control at the place where you can just "run" SQL here.
Step 3:
Create a SQL Tuning with the SQL Code that has just been executed.
Step 4:
Run SQL Access Advisor and use the SQL code that has just been run.
Step 5:
To run the SQL SQL Tuning Advisor.
I know there are several way to do it, but what is your "workflow."
Thanks for any help...
Thank you
Lady Allora.
I was approached by one of the Dev and he asked me to run faster than 5 minutes.
OK - but it is an ARTIFICIAL target and is NOT necessarily realistic or feasible.
This makes it a RESEARCH project. You are looking for, you analyze, you try to determine if this goal is realistic or even possible.
There is only one table that has rows 3 million inside and they do a "union all" join on tables that have a few hundred thousand lines in them.
This means that EACH of the queries in this "union all" can be considered as a separate entity. You can take each of the queries ONE AT A TIME and determine:
1. how many lines it can return
2. what execution plan used
3. what indexes and statistics are available. Are there stats? They are up to date? How they were collected?
4. that if whatever, in execution plans seems out of the ordinary - perhaps an index is used when it shouldn't, perhaps an index is NOT used when it is possible, perhaps a clue is needed
All this is LOOKING. As others have said if you know how many rows in the table, how many need to be returned and indexes are available, you can estimate the time MINIMUM it would take to get them. No matter what you do you will not get any faster than that.
And for a UNION ALL of four motions operation, you can add these 4 'planned' to get the time MINIMUM it might take. That becomes your time back as LOW as POSSIBLE.
If it is greater than the target, your goal is NOT possible.
Ok, so many people say over and over again and more than a presence FULL ACCESS TABLE in the plan to explain is not bad.
NO! This is NOT what they say. You wrong interpret what they tell you.
Full scans are NOT NECESSARILY bad. Same 14 of them are NOT NECESSARILY bad. One or more of them COULD BE bad or even all of them could be bad.
They tell you not to make the assumption that a FTS in the plan is bad. Are not these analyses and make the research/control over them, but what you do NOT assume that you must try to eliminate one or all of them.
Tags: Database
Similar Questions
-
What is the best way to optimize a SQL query: call a function or doing a join?
Hi, I want to know what is the best way to optimize a SQL query, call a function inside the SELECT statement, or make a simple join?
It depends on. Could be a. Could be the other. Could be no difference. You would need to compare with your tables in your environment with your settings.
If you put a gun to my head, I was given no other information and required that I answered the question, I would tend to wait that the join would be more effective. In general, if you can do something in pure SQL, it will be more effective than if you call PL/SQL.
Justin
-
the number of refills for SQL statements
Hello
in 10g R2, how to see the number of refills for SQL statements? Any question? High value? What earned is low?
Thank you.First run a statspack or AWR report and take a look in v$ librarycache
Numbers are irrelevant. The reports are a little more relevant, but not necessarily a problem.
Published by: Robert Geier on January 29, 2010 10:04
-
How to use the T distribution table in sql statements?
Hi all
I'm in the need to use the T distribution table in sql... I don't know how to use...
Is there a function to use the values of table in sql statements?
Can someone please help me in this?How about this http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions157.htm#i1279931?
Concerning
Etbin
-
Way to create SQL statements via sqldeveloper
Is it possible that one can use sqldeveloper to create sql statements?
Is the statement that I'm having a problem with: -.
and even if EGMGAMEVARIATION contains a column called ENDDATE I mean: -.SELECT EGMGAMEVARIATIONPK FROM EGMGAMEVARIATION WHERE EGMPK=$row[0] AND STARTDATE >= TRUNC(current_date) AND (NVL(ENDATE, current_date+1) >= TRUNC(current_date))
'ENDATE': identifier not valid when I run my PHP script, so I thought that if I could get the system to help me build the command I could do better.First, you say the name of the column is ENDDATE, yet in your query, you wrote ENDATE, then Yes, it is an invalid identifier :)
But yes, if you like there is a Query Builder: right-click inside the SQL worksheet to invoke it.Have fun
K. -
How to find the redo generated by each SQL statement?
Database version is 10.2.0.4. OS is AIX.
We must again excessive generation during a specific time. We want to identify what a statement contributes to excessive recovery.
ADDM shows this as a first observation
Waiting on event "log file sync" during the execution of operations of COMMIT and ROLLBACK consumed at the time of the important data.
Is it possible to know which statement sql generates how many redo in bytes for a moment?
Thank you
DelphineIs it possible to know which statement sql generates how many redo in bytes for a moment?
It will not help you.
For example, you can see a lot of UPDATE, DELETE, INSERT from the apps statements. Then? What you do with them? If you can modify the application to eliminate the useless LMD - it would be great of course. But it is unlikely.When the DML statements also generate Redo, does not cause them too much expectations "log file sync", because the writer log buffer empty buffer as soon as it fulfills more than 30% after a certain time or on Commit / Rollback.
Waiting on event "log file sync" during the execution of operations of COMMIT and ROLLBACK consumed at the time of the important data.
Right. This is because the writer written newspaper here synchronous, reliable, he waits until the HDD writes data down and meets its written OK.
And hard drives are not the fastest things in the computer. They are mechanical - that's why.I would recommend:
1. place files redo log on quick drives used preference dedicated only to this end. If other I/O will often disturb these readers resulting securities heads change causing longer HDD expected.
2 consider using faster technology such as SAN or SSD. -
How to add the number of the column by another county sql statement
My problem is
SELECT Count (DISTINCT num) OF tmp_table;
the foregoing will return 13.
UPDATE seq_table a SET a.currentvalue = a.currentvalue + 1 + (SELECT Count(DISTINCT num) FROM tmp_table;) WHERE a.seq_type LIKE 'ABC% ';
the result of updating should be = a.currentvalue + 1 + 13
How is that possible? There is syntax error...
Not sure if this was clear ;-), but there's a semicolon behind tmp_table and SQL does not understand that.
Then
UPDATE seq_table SET a.currentvalue = a.currentvalue + 1 + (SELECT Count(DISTINCT num) FROM tmp_table) WHERE a.seq_type LIKE 'ABC% ';
-
HP Pavilion - the best way to optimize?
SYSTEM INFORMATION: Pavilion PU131AV / a1050y, Windows XP SP3 32-bit, Nvidia GeForce 6600, MCE, Intel Pentium 4 CPU 3.20 GHz, 2 GB RAM
PROBLEM: Office seems to have problems running the basic operations. For example:
a. when copying large amounts of data (50 + GB) to one external hardrive to another (via USB), Pavilion will restart. This was never the case before. Was able to perform the same task via my laptop Presario (AMD Turion 64 Mobile Technology ML-32, 1.79 GHz, 384 MB RAM) with no problem and effectively transferred to 150 GB of info with the cell value.
b. it took an hour and a half to format an external hard drive 300 GB (via USB) with the Pavilion. It took only 5 minutes to format an external hard drive 200 GB (via USB) with the Presario.
c. when downloading 4 GB with a value of the info of a DVD on the Pavilion, the computer will restart.
QUESTION: What can I do to ensure that my flag is optimized? How can I solve these issues the best?
Thank you very much
Angela
``````````````````````````````````````````
old computer: HP Pavilion PU131AV / a1050y, Intel Pentium 4 CPU 3.20 GHz, 2 GB RAM, Windows XP MCE, SP3 32-bit, Nvidia GeForce 6600
new computer: HPE-180 t, Windows 7 Pro (64 bit), Nvidia GeForce GT 220, Intel Core i7 - 930 quad-core CPU @ 2.80 GHz, 8 GB of RAMTX, looks like it's time to use some of these new tools for backup and perform a destructive system recovery. Computers access naturally more slow times of installing and uninstalling the programs. The registry have assign traces remaining. The problem is, most of the registry cleaners, cause more problems than they solve. Thus, a good recovery system solves this problem.
-
The analysis of a sql statement without executing it
Hello everyone,
I would like to know a way of parsing sql statements to validate them, so I would get the error messages in advance without executing them.
Here we have the difficult task to analyze several sql scripts and send corrections to the development team and thirty third companies before applying them in our production databases. I am ready to create a program web/pl sql, making this difficult task, at least one program to identify errors such as lack of owner of the table, nonexistent tables, syntax errors and so on...
Any information will be a great help!
Thanks in advance.Hi and welcome to the forum.
Tip1:
http://asktom.Oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:3648254441315Tip2:
to bookmark this forum (SQL and PL/SQL)
Bookmark http://tahiti.oracle.com (The Oracle Documentation)
Bookmark http://asktom.oracle.comTip3:
On all the sites mentioned, you can do a quick search on key words of your interest and you will get the examples and explanations returned. -
I need help in the sql statement
Hi all
im working in the hr schema
I need sql statement to answer my question
I need information to all employees
where average wage = average wage department 50
Sorry I can't speak English very well
I thank allThere is no need to do so in the two motions. All you need is:
select * from ( select e.*, avg(case department_id when 50 then salary end) over() dept_50_avg_sal from hr.employees e ) where salary <= dept_50_avg_sal / EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID DEPT_50_AVG_SAL ----------- -------------------- ------------------------- ------------------------- -------------------- --------- ---------- ---------- -------------- ---------- ------------- --------------- 198 Donald OConnell DOCONNEL 650.507.9833 21-JUN-07 SH_CLERK 2600 124 50 3475.55556 199 Douglas Grant DGRANT 650.507.9844 13-JAN-08 SH_CLERK 2600 124 50 3475.55556 115 Alexander Khoo AKHOO 515.127.4562 18-MAY-03 PU_CLERK 3100 114 30 3475.55556 116 Shelli Baida SBAIDA 515.127.4563 24-DEC-05 PU_CLERK 2900 114 30 3475.55556 117 Sigal Tobias STOBIAS 515.127.4564 24-JUL-05 PU_CLERK 2800 114 30 3475.55556 118 Guy Himuro GHIMURO 515.127.4565 15-NOV-06 PU_CLERK 2600 114 30 3475.55556 119 Karen Colmenares KCOLMENA 515.127.4566 10-AUG-07 PU_CLERK 2500 114 30 3475.55556 125 Julia Nayer JNAYER 650.124.1214 16-JUL-05 ST_CLERK 3200 120 50 3475.55556 126 Irene Mikkilineni IMIKKILI 650.124.1224 28-SEP-06 ST_CLERK 2700 120 50 3475.55556 127 James Landry JLANDRY 650.124.1334 14-JAN-07 ST_CLERK 2400 120 50 3475.55556 128 Steven Markle SMARKLE 650.124.1434 08-MAR-08 ST_CLERK 2200 120 50 3475.55556 EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID DEPT_50_AVG_SAL ----------- -------------------- ------------------------- ------------------------- -------------------- --------- ---------- ---------- -------------- ---------- ------------- --------------- 129 Laura Bissot LBISSOT 650.124.5234 20-AUG-05 ST_CLERK 3300 121 50 3475.55556 130 Mozhe Atkinson MATKINSO 650.124.6234 30-OCT-05 ST_CLERK 2800 121 50 3475.55556 131 James Marlow JAMRLOW 650.124.7234 16-FEB-05 ST_CLERK 2500 121 50 3475.55556 132 TJ Olson TJOLSON 650.124.8234 10-APR-07 ST_CLERK 2100 121 50 3475.55556 133 Jason Mallin JMALLIN 650.127.1934 14-JUN-04 ST_CLERK 3300 122 50 3475.55556 134 Michael Rogers MROGERS 650.127.1834 26-AUG-06 ST_CLERK 2900 122 50 3475.55556 135 Ki Gee KGEE 650.127.1734 12-DEC-07 ST_CLERK 2400 122 50 3475.55556 136 Hazel Philtanker HPHILTAN 650.127.1634 06-FEB-08 ST_CLERK 2200 122 50 3475.55556 138 Stephen Stiles SSTILES 650.121.2034 26-OCT-05 ST_CLERK 3200 123 50 3475.55556 139 John Seo JSEO 650.121.2019 12-FEB-06 ST_CLERK 2700 123 50 3475.55556 140 Joshua Patel JPATEL 650.121.1834 06-APR-06 ST_CLERK 2500 123 50 3475.55556 EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID DEPT_50_AVG_SAL ----------- -------------------- ------------------------- ------------------------- -------------------- --------- ---------- ---------- -------------- ---------- ------------- --------------- 142 Curtis Davies CDAVIES 650.121.2994 29-JAN-05 ST_CLERK 3100 124 50 3475.55556 143 Randall Matos RMATOS 650.121.2874 15-MAR-06 ST_CLERK 2600 124 50 3475.55556 144 Peter Vargas PVARGAS 650.121.2004 09-JUL-06 ST_CLERK 2500 124 50 3475.55556 180 Winston Taylor WTAYLOR 650.507.9876 24-JAN-06 SH_CLERK 3200 120 50 3475.55556 181 Jean Fleaur JFLEAUR 650.507.9877 23-FEB-06 SH_CLERK 3100 120 50 3475.55556 182 Martha Sullivan MSULLIVA 650.507.9878 21-JUN-07 SH_CLERK 2500 120 50 3475.55556 183 Girard Geoni GGEONI 650.507.9879 03-FEB-08 SH_CLERK 2800 120 50 3475.55556 186 Julia Dellinger JDELLING 650.509.3876 24-JUN-06 SH_CLERK 3400 121 50 3475.55556 187 Anthony Cabrio ACABRIO 650.509.4876 07-FEB-07 SH_CLERK 3000 121 50 3475.55556 190 Timothy Gates TGATES 650.505.3876 11-JUL-06 SH_CLERK 2900 122 50 3475.55556 191 Randall Perkins RPERKINS 650.505.4876 19-DEC-07 SH_CLERK 2500 122 50 3475.55556 EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID DEPT_50_AVG_SAL ----------- -------------------- ------------------------- ------------------------- -------------------- --------- ---------- ---------- -------------- ---------- ------------- --------------- 194 Samuel McCain SMCCAIN 650.501.3876 01-JUL-06 SH_CLERK 3200 123 50 3475.55556 195 Vance Jones VJONES 650.501.4876 17-MAR-07 SH_CLERK 2800 123 50 3475.55556 196 Alana Walsh AWALSH 650.507.9811 24-APR-06 SH_CLERK 3100 124 50 3475.55556 197 Kevin Feeney KFEENEY 650.507.9822 23-MAY-06 SH_CLERK 3000 124 50 3475.55556 37 rows selected. SQL>
SY.
-
Hi all
A simple matter of time spent in v$ sql.
I know that this means that a total duration when a query runs.
I think that
time elapsed time = cpu + user + application_wait_time o wait times
+ concurrency_wait_time + cluster_wait_time + plsql_exec_time + java_exec_time
of course, the passage of time could not be exactly the same with a sum of above things, because its value is the cumulative value.
but I have a few weird data. its value is 130% of the amount. I have no idea whence the other 30%.
its value is too big to ignore.
does anyone have an idea?
(this is a kernel environment)
Thanks in advance...Hello
If you draw the session (10046) an application, following will be the result in the file path for each SQL statementSELECT "COSTCODE","INSERTDATETIME","LOTID","SOURCELOTID","STAGE","SUPPLIERID" FROM "ACTL_PARTINFO_CUST" "A" WHERE "SUPPLIERID"='RD1' AND "INSERTDATETIME"= TO_DATE('2010-08-18 07:05:00', 'yyyy-mm-dd hh24:mi:ss') AND "STAGE"=:1 AND "LOTID" LIKE 'C%' AND "COSTCODE"='A' AND "SOURCELOTID" LIKE 'F%' call count cpu elapsed disk query current rows ------- ------ -------- ---------- ---------- ---------- ---------- ---------- Parse 1 0.00 0.00 0 0 0 0 Execute 300372 3.27 69.85 0 0 0 0 Fetch 300371 1916.42 6551.42 0 100023544 0 0 ------- ------ -------- ---------- ---------- ---------- ---------- ---------- total 600744 1919.69 6621.27 0 100023544 0 0 Misses in library cache during parse: 0 Optimizer mode: ALL_ROWS Parsing user id: 61 (DWDB_REPORTING) Elapsed times include waiting on following events: Event waited on Times Max. Wait Total Waited ---------------------------------------- Waited ---------- ------------ SQL*Net message to client 300371 0.02 0.64 SQL*Net message from client 300371 5.33 4860.35 latch: cache buffers chains 7199 0.38 49.62 latch free 99 0.04 0.72 latch: enqueue hash chains 5 0.03 0.07
Here you can see the total elapsed time next to the database including waiting events.
Salman
-
The temporary and tables using SQL tuning tools
The application that I support uses temporary tables for the majority of queries... Looking at the SQL tuning advisor and more of other oracle tuning tools, they seem well managing temporary tables.
It's what Happens (from what I can tell).
(1) oracle identifies a SQL statement (or the ADMINISTRATOR only), to be tuned.
(2) the original execution statistics are saved for comparison
(3) oracle tries to find a new plan (but at this point, the temporary table is empty).
(4) it tries to execute the new plan (once again the temporary table is empty).
(5) it comparies the execution time of the new plan against the original plan
The comparison, of course, is not a reasonable comparison.
Does anyone have experience with this problem? My first thought is for 'premium' of the temporary table, then run the Advisor of tuning in the same session (hoping that it will use the values in the temporary table).
Other than that, rereading of the database seems to be the best way to adjust sql plan changes using baselines.Expected.
-
00900 invalid SQL statement error
I am myself to write stored procedures, teacher in TOAD 10.5 with Oracle 10 g. I get the error ORA-00900: invalid SQL statement. Here's the code, cut to the minimum sample size strip. I don't see where I'm doing something wrong.
If I cut out the slider (take it down to just "Begin" and "End"), it runs, but I don't see anything wrong with the cursor.
Any ideas?
CREATE OR REPLACE PROCEDURE IN_PROCESS_CASES_BOS
IS
V_HELLO VARCHAR2 (10);
CURSOR C_MAIN IS
SELECT 'HELLO' FROM DUAL;
BEGIN
C_MAIN OPEN;
LOOP
EXTRACT THE C_MAIN IN V_HELLO;
WHEN THE OUTPUT C_MAIN % NOTFOUND;
END LOOP;
CLOSE C_MAIN;
END;
END IN_PROCESS_CASES_BOS;
/select * from user_errors; NAME TYPE SEQUENCE LINE POSITION ------------------------------ ------------ ---------- ---------- ---------- TEXT -------------------------------------------------------------------------------- ATTRIBUTE MESSAGE_NUMBER --------- -------------- IN_PROCESS_CASES_BOS PROCEDURE 1 21 1 PLS-00103: Encountered the symbol "END" ERROR 103
You have an extra END; Remove it and the procedure compiles and runs.
-
How to concatenate two sql statements?
Hello
How can I combine the following two sql statements so that the result of a line of the first statement appears before the lines of my second sql statement. The reason I need it is to order the lines correctly.
Select the username, id
some abusers
where id = 0
Select the username, id
some abusers
where id! = 0
order by username
Thank you
jYou should ask in the forum of the Apex:
Oracle Application Express (APEX)Nicolas.
-
problem when creating a trigger: SQL statement ignored
Hello people,
I am trying to create a trigger, but it is not created. Instead, I get the error message that a SQL statement at line 22 was ignored. It's the line indicating IF num2 = 1 THEN. I'd be happy if someone could point me in the right direction or solve my problem.
CREATE OR REPLACE TRIGGER TriggerLogement BEFORE INSERT OR update ON tenants
FOR EACH LINE
DECLARE
NUM INTEGER;
num2 INTEGER;
NUM3 INTEGER;
paysLocataire VARCHAR2 (255);
categorieLocataire VARCHAR2 (1);
BEGIN
SELECT COUNT (ns) IN the number OF tenants WHERE nomBat =: new.nomBat;
IF num > 0 THEN
SELECT paid IN the country OF sports WHERE ns =: new.ns;
SELECT COUNT (country) IN number OF athletes sp, tenants lo WHERE sp.ns = lo.ns AND paysLocataire AND lo.nomBat = pays =: new.nomBat;
IF num = 0 THEN
raise_application_error (-20000, "building already in use for another nationality");
ON THE OTHER
SELECT COUNT (ns) IN num2 OF tenants WHERE nLogement =: new. NLogement AND nomBat =: new.nomBat;
IF num2 = 2 THEN
raise_application_error (-20000, 'full accommodation');
ON THE OTHER
IF num2 = 1 THEN
CateogrieLocataire INTO SELECT category OF athletes WHERE ns = new.ns;
SELECT COUNT (ns) IN num3 FROM tenant lo, sportsmen sp WHERE lo.ns = sp.ns
AND lo.nLogement =: new. NLogement AND lo.nomBat =: new.nomBat AND sp.categorie = categorieLocataire;
IF num3 = 0 THEN
raise_application_error ("-20000, ' already in use for the other sex");
END IF;
END IF;
END IF;
END IF;
END IF;
END;
If you need more information or if you have any questions about my posts please leave your questions or comments. I hope this isn't how completely wrong to enforce some constraints that I can't do with CONSTRAINT and CHECK in the schema definition.
Thanks for your help and your attention.
SebastianHello
Whenever you have a problem that raises an error, display the full error message; do not paraphrase just part of it.
In the triggers line numbers from the first statement DECLARE or BEGIN, so line 22 of your trigger is:
SELECT categorie INTO cateogrieLocataire FROM Sportifs WHERE ns = new.ns;
You are missing a colon before 'new': it should be:
SELECT categorie INTO cateogrieLocataire FROM Sportifs WHERE ns = :new.ns;
A FOR EACH ROW trigger on tenants cannot ask tenants. It's a shame: there are many useful things, you could do if that were allowed, but it's not.
I'm not sure of what all queries. At least one of them:SELECT COUNT (ns) INTO num2 FROM Locataires WHERE nLogement = :new.NLogement AND nomBat = :new.nomBat; IF num2 = 2 THEN raise_application_error(-20000,'accomodation full');
can be replaced by a UNIQUE constraint. (Constraints are better than triggers, in any case.)
If you can't do what you want with constraints, you can leave anyone directly INSERT or update the table: force them to use a procedure stored instead. You can have an INSTEAD OF trigger on a view, which is essentially the same, but allows you to use DML commands.
If you need help, post some sample data and some examples of DML operations that must be allowed, given the data and some examples of DML operations that should not be allowed.
Maybe you are looking for
-
Hi I'm new powerpc g4 with powerpc2.1 cpu + memory sd ram 768 m + geforce 2 mx vga I have a small question 1. my lcd screen appear as in the picture. How to fix? 2.i can't watch youtube videos / listen to the radio online like tunein/coolism. I updat
-
I have a good Wi - fi network at home using an Airport Extreme and Airport Express, but am moving my office on the other side of the House. The walls are plaster that inhibit the signal. Can I connect another Express to my extreme via an Ethernet cab
-
Audio out of sync in TV recorded video only.
I have a problem. I have a Gateway FX7020, tuner Pinnacle PCTV 800i, Nvidia Gforce GTS 250 and, only the recorded tv is out of sync, tv live is fine! but records are often out of sync... rarely synchronization, as 90% of the cases they are not "."
-
I have a computer that has Windows 2000 Pro, I can use the disk to upgrade to Windows XP with this OS? It's an old computer, but it works very well. I want to switch to XP using the Windows upgrade disc. But in the specifications it lists only 98, 9
-
Always 'class not registered' is the answer to why MovieMaker cannot import as many files. I finally realized that if I have all the "Windows"associated files with QuickTime (which I do often because QuickTime Pro has been my editor that works, but I