The Magic of SQL
The Magic of SQL
  • 72
  • 891 031
How to Find Slow SQL: Databases for Developers: Performance #9
In order to tune SQL, you need to know what the slow statement is. But often you're just told that "the database" is slow!
To find the slow components, you need a breakdown of how long each piece of code takes to execute. You can do this in Oracle Database using:
- A SQL trace
- The PL/SQL hierarchical profiler
This video shows you how to do these with Oracle SQL Developer.
The script to spool the trace file is:
-----
set serveroutput off
set pagesize 0
set echo off
set feedback off
set trimspool on
set heading off
set tab off
set long 1000000
spool c:\temp\student_trace.trc
select payload
from v$diag_trace_file_contents
where trace_filename = (
select substr (
value,
instr ( value, '/', -1 ) + 1
) filename
from v$diag_info
where name = 'Default Trace File'
)
order by line_number;
spool off
-----
Need help with SQL?
Ask us over on AskTOM: asktom.oracle.com
Twitter: ChrisRSaxon
Daily SQL Twitter tips: SQLDaily
All Things SQL blog: blogs.oracle.com/sql/
Test your SQL Skills on the Oracle Dev Gym: devgym.oracle.com/
============================
The Magic of SQL with Chris Saxon
Copyright © 2020 Oracle and/or its affiliates. Oracle is a registered trademark of Oracle and/or its affiliates. All rights reserved. Other names may be registered trademarks of their respective owners. Oracle disclaims any warranties or representations as to the accuracy or completeness of this recording, demonstration, and/or written materials (the “Materials”). The Materials are provided “as is” without any warranty of any kind, either express or implied, including without limitation warranties or merchantability, fitness for a particular purpose, and non-infringement.
zhlédnutí: 15 842

Video

How to Make Inserts, Updates, and Deletes Faster: Databases for Developers: Performance #8
zhlédnutí 18KPřed 4 lety
How to Make Inserts, Updates, and Deletes Faster: Databases for Developers: Performance #8
How do nested loop, hash, and merge joins work? Databases for Developers Performance #7
zhlédnutí 66KPřed 4 lety
How do nested loop, hash, and merge joins work? Databases for Developers Performance #7
Count Millions of Rows Fast with Materialized Views: Databases for Developers: Performance #6
zhlédnutí 30KPřed 4 lety
Count Millions of Rows Fast with Materialized Views: Databases for Developers: Performance #6
Why Isn't My Query Using an Index? Databases for Developers: Performance #5
zhlédnutí 12KPřed 4 lety
Why Isn't My Query Using an Index? Databases for Developers: Performance #5
How to Create Database Indexes: Databases for Developers: Performance #4
zhlédnutí 25KPřed 4 lety
How to Create Database Indexes: Databases for Developers: Performance #4
What to Look for in Execution Plans: Databases for Developers: Performance #3
zhlédnutí 15KPřed 4 lety
What to Look for in Execution Plans: Databases for Developers: Performance #3
What are Optimizer Statistics? Databases for Developers: Performance #2
zhlédnutí 18KPřed 4 lety
What are Optimizer Statistics? Databases for Developers: Performance #2
How to Read an Execution Plan: Databases for Developers: Performance #1
zhlédnutí 60KPřed 4 lety
How to Read an Execution Plan: Databases for Developers: Performance #1
Learn 130 SQL Statements in 20 Minutes
zhlédnutí 6KPřed 4 lety
Learn 130 SQL Statements in 20 Minutes
What Are Not Null Constraints? A Video Quiz
zhlédnutí 725Před 5 lety
What Are Not Null Constraints? A Video Quiz
What Are Foriegn Keys? A Video Quiz
zhlédnutí 810Před 5 lety
What Are Foriegn Keys? A Video Quiz
What are Primary Keys - A Video Quiz
zhlédnutí 1,1KPřed 5 lety
What are Primary Keys - A Video Quiz
Columns and Data Types: Databases for Developers #2
zhlédnutí 25KPřed 5 lety
Columns and Data Types: Databases for Developers #2
What is the Dual Table in Oracle Database? A Video Quiz
zhlédnutí 2,8KPřed 5 lety
What is the Dual Table in Oracle Database? A Video Quiz
How do SQL queries return correct results? Databases for Developers #18
zhlédnutí 3,6KPřed 6 lety
How do SQL queries return correct results? Databases for Developers #18
How to insert or update rows in one statement: Databases for Developers #17
zhlédnutí 9KPřed 6 lety
How to insert or update rows in one statement: Databases for Developers #17
Hierarchical SQL Queries: Databases for Developers #16
zhlédnutí 61KPřed 6 lety
Hierarchical SQL Queries: Databases for Developers #16
Union, Minus & Intersect: Databases for Developers #15
zhlédnutí 4,6KPřed 6 lety
Union, Minus & Intersect: Databases for Developers #15
How to pivot rows to columns (and back) in SQL: Databases for Developers #14
zhlédnutí 10KPřed 6 lety
How to pivot rows to columns (and back) in SQL: Databases for Developers #14
Analytic Functions: Databases for Developers #13
zhlédnutí 6KPřed 6 lety
Analytic Functions: Databases for Developers #13
How to sort rows with SQL: Databases for Developers #12
zhlédnutí 7KPřed 6 lety
How to sort rows with SQL: Databases for Developers #12
SQL Subqueries: Databases for Developers #11
zhlédnutí 8KPřed 6 lety
SQL Subqueries: Databases for Developers #11
Null: Databases for Developers #10
zhlédnutí 11KPřed 6 lety
Null: Databases for Developers #10
Delete and Truncate: Databases for Developers #9
zhlédnutí 13KPřed 7 lety
Delete and Truncate: Databases for Developers #9
Update and Transactions: Databases for Developers #8
zhlédnutí 13KPřed 7 lety
Update and Transactions: Databases for Developers #8
Insert and Commit: Databases for Developers #7
zhlédnutí 17KPřed 7 lety
Insert and Commit: Databases for Developers #7
How to count, sum, and average rows in SQL: Databases for Developers #6
zhlédnutí 16KPřed 7 lety
How to count, sum, and average rows in SQL: Databases for Developers #6
How inner, outer, and cross joins work: Databases for Developers #5
zhlédnutí 20KPřed 7 lety
How inner, outer, and cross joins work: Databases for Developers #5
How to write SQL queries: Databases for Developers #4
zhlédnutí 19KPřed 7 lety
How to write SQL queries: Databases for Developers #4

Komentáře

  • @user-uc1of8xq4q
    @user-uc1of8xq4q Před 6 dny

    I have to create index for a huge table (In Gigabytes) for a new column. But when we tried this, it is bringing down the system completely so we had to drop that. Is there any way we can create this index without downtime.

    • @TheMagicofSQL
      @TheMagicofSQL Před 5 dny

      I'm unsure what "bringing down the system completely" means exactly. In Oracle Database you can CREATE INDEX ... ONLINE which allows the database to write to the table while creating the index which may help here.

    • @user-uc1of8xq4q
      @user-uc1of8xq4q Před 2 dny

      @@TheMagicofSQL Thank you for the quick reply. 'Bringing down' - I was meaning that the CPU and memory were full due to the size of the table and was taking hours to complete. So is there a way to create index in a performant way on this table?

    • @TheMagicofSQL
      @TheMagicofSQL Před 19 hodinami

      While a table in the gigabytes is big, it still shouldn't take hours to create an index on it. Creating an index will only use 1 cpu by default. So either the system only has a couple of cpus (in which case you should look at getting more) or it's running in parallel - reducing the parallelism will help. I would still start by using the ONLINE keyword when creating the index before trying anything else though. It might take a long time, but other operations should continue normally (unless your system does have to few CPUs for the workload)

    • @user-uc1of8xq4q
      @user-uc1of8xq4q Před 8 hodinami

      @@TheMagicofSQL Thanks again. I shall try this and will update here on how it goes.

  • @emilemary
    @emilemary Před 6 dny

    Excellent presentation, the best SQL course!! I love the creativity in your videos. Thank you so much!!

  • @HarrietOmboga
    @HarrietOmboga Před 6 dny

    I like how its explained though I dont get most of it

    • @TheMagicofSQL
      @TheMagicofSQL Před 5 dny

      What is it you're struggling to understand?

  • @SinskariBoi5guys66
    @SinskariBoi5guys66 Před 8 dny

    Refreshing

  • @hindimotivation5231
    @hindimotivation5231 Před měsícem

    I am not able to understand the autotrace part where view part individual elapsed time is 728 micro seconds. How this was calculated , Please elaborate. Thankyou.

    • @hindimotivation5231
      @hindimotivation5231 Před měsícem

      One more doubt , in 3rd sort operation why it dont have any elpsed time as you said in video.

    • @TheMagicofSQL
      @TheMagicofSQL Před 28 dny

      I'm not sure exactly what you're referring to - please clarify. In any case, this value comes from the database measuring how long the operation took.

    • @TheMagicofSQL
      @TheMagicofSQL Před 28 dny

      Again, I'm not sure exactly what you're referring to.

  • @IgorSadovskii
    @IgorSadovskii Před měsícem

    usefull explanation ! thanks a lot!

  • @robertczaja176
    @robertczaja176 Před měsícem

    Well explained!

  • @robertczaja176
    @robertczaja176 Před měsícem

    Perfect video! You can explain things that everyone can understand it!

  • @dothanhlong1847
    @dothanhlong1847 Před měsícem

    .

  • @AndrewCoffman-jq9ld
    @AndrewCoffman-jq9ld Před měsícem

    Been doing MSSQL for 20 years and this was by far the best explanation of these joins. Thanks!

  • @vialvial1246
    @vialvial1246 Před měsícem

    Best explanation! Thank you sir!

  • @sorryShen
    @sorryShen Před měsícem

  • @Somosphere
    @Somosphere Před 2 měsíci

    First time came across such good explanation of these 3 kind of joins. Kudos !!!

  • @sumeetpalit6362
    @sumeetpalit6362 Před 2 měsíci

    Thats the first time i understood how these joins worked... 😅

  • @KaranMidha-ki8ev
    @KaranMidha-ki8ev Před 2 měsíci

    please remove the sound track from videos

    • @TheMagicofSQL
      @TheMagicofSQL Před měsícem

      We'll bear this in mind for future videos

  • @tasty4644
    @tasty4644 Před 2 měsíci

    excellent video

  • @rajatgupta8736
    @rajatgupta8736 Před 2 měsíci

    Crisp and accurate

  • @Noone-bb5qh
    @Noone-bb5qh Před 2 měsíci

    Thank you so much for this video. It really helped me for my interview.

  • @smartsekar9727
    @smartsekar9727 Před 2 měsíci

    Sir what is decimal presicion. Scale used how it store values.according size of values

    • @TheMagicofSQL
      @TheMagicofSQL Před 2 měsíci

      "p is the precision, or the maximum number of significant decimal digits, where the most significant digit is the left-most nonzero digit, and the least significant digit is the right-most known digit. Oracle guarantees the portability of numbers with precision of up to 20 base-100 digits, which is equivalent to 39 or 40 decimal digits depending on the position of the decimal point. s is the scale, or the number of digits from the decimal point to the least significant digit. The scale can range from -84 to 127." docs.oracle.com/en/database/oracle/oracle-database/23/sqlrf/Data-Types.html#GUID-9401BC04-81C4-4CD5-99E7-C5E25C83F608

  • @bobfar
    @bobfar Před 2 měsíci

    I am incredibly grateful to Chris for their invaluable tutorials on hash join, merge join, and nested loop. These concepts always seemed daunting to me when I encountered them in execution plans, but their clear and concise explanations have helped me gain a much deeper understanding. Their expertise and dedication to educating others are truly commendable. A big thank you for demystifying these complex topics and making them accessible to all!

  • @tsunningwah3471
    @tsunningwah3471 Před 2 měsíci

    色相

  • @tsunningwah3471
    @tsunningwah3471 Před 2 měsíci

    田木

  • @datawitharyan
    @datawitharyan Před 3 měsíci

    Thanks bro , Excellent Explanation

  • @prashant_chhetri09
    @prashant_chhetri09 Před 3 měsíci

    Can we do fast refresh in complex materialized view? If its possible how to achieve it?

    • @TheMagicofSQL
      @TheMagicofSQL Před 3 měsíci

      What do you mean by "complex"? There are lots of restrictions on what's possible for fast refresh docs.oracle.com/en/database/oracle/oracle-database/23/dwhsg/basic-materialized-views.html#GUID-505C24CF-5D56-4820-88AA-2221410950E7

  • @LuisMi-vm7ri
    @LuisMi-vm7ri Před 3 měsíci

    Around 6min for complexity, do you use binary or decimal log? I believe it should be binary but one of your calculations (the one for Merge Join = 180) leads me to think you used decimal. Was this a mistake when using your calculator, or is it really meant to be decimal log?

    • @LuisMi-vm7ri
      @LuisMi-vm7ri Před 3 měsíci

      Very nice video btw! Really enjoy the visual and step by step explanations

    • @TheMagicofSQL
      @TheMagicofSQL Před 3 měsíci

      It was a decimal log. The numbers are just approximations to give some idea of complexity. Particularly for sorting the precise figures depend on the sort algorithm and order of the input data set. Whether you use LN or LOG, merge join comes out between nested loops and hash join in the example.

    • @LuisMi-vm7ri
      @LuisMi-vm7ri Před 3 měsíci

      Makes sense! Thank you

  • @dheerajvarthi4657
    @dheerajvarthi4657 Před 3 měsíci

    Thanks a lot 🙏

  • @lawalrasheed_
    @lawalrasheed_ Před 3 měsíci

    Absolute gem!!

  • @mohan1958
    @mohan1958 Před 3 měsíci

    Thanks very much for the detailed study.

  • @nhungbi2401
    @nhungbi2401 Před 4 měsíci

    I love your teaching vibe!!!

  • @TheAbbassss
    @TheAbbassss Před 4 měsíci

    very simple explaining..good work bro

  • @PeterBogaert-fz1kn
    @PeterBogaert-fz1kn Před 4 měsíci

    I'm an Oracle DBA for 30 years and your explanation is the best I ever seen !!! Congrats

    • @TheMagicofSQL
      @TheMagicofSQL Před 4 měsíci

      You're welcome Peter - glad you found this useful!