Count Millions of Rows Fast with Materialized Views: Databases for Developers: Performance #6

แชร์
ฝัง
  • เผยแพร่เมื่อ 22 มิ.ย. 2020
  • Querying returning totals per day, week or month can process billions of rows. But only return a handful.
    You can make these queries orders of magnitude faster by precomputing the result using materialized views.
    Watch this video to learn how these work.
    For details on fast refresh restrictions, see:
    www.oracle.com/pls/topic/look...
    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.
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 46

  • @theaugmenter
    @theaugmenter 3 ปีที่แล้ว +27

    Thanks. This is hands down the best tutorial I've ever watched, on anything!

    • @TheMagicofSQL
      @TheMagicofSQL  3 ปีที่แล้ว +2

      Thanks, glad you found this useful :)

  • @welltv1142
    @welltv1142 2 ปีที่แล้ว

    Best SQL Tutorial channel as a whole. Theory is explained on such a basic level, so everyone can understand. Please keep up the awesome work! :)

    • @TheMagicofSQL
      @TheMagicofSQL  2 ปีที่แล้ว +1

      You're welcome, glad you find these useful :)

  • @brandonbraner
    @brandonbraner 2 ปีที่แล้ว +1

    At first I saw the bricks and though wtf is this.... they really really helped. Great Job

  • @sagarkumar-en1se
    @sagarkumar-en1se 3 ปีที่แล้ว +4

    Sir.. Your teaching style is unique.Easily understood.. Thanks.. Much appreciated

  • @oah8465
    @oah8465 2 ปีที่แล้ว +1

    Now, I see where mysql lacks hugely. Thank you man. Fantastic video as usual.

  • @baddream29
    @baddream29 ปีที่แล้ว +1

    That is really great and simple explanation, thanks

  • @nhungbi2401
    @nhungbi2401 3 หลายเดือนก่อน

    I love your teaching vibe!!!

    • @TheMagicofSQL
      @TheMagicofSQL  3 หลายเดือนก่อน

      Thanks, glad you enjoy these!

  • @dhatrimukkamalla
    @dhatrimukkamalla 3 ปีที่แล้ว +2

    Am I your 10,000th subscriber? Very engaging video!

    • @TheMagicofSQL
      @TheMagicofSQL  3 ปีที่แล้ว +1

      I do believe you are, thanks :)

  • @User-ty2ml
    @User-ty2ml 2 ปีที่แล้ว +1

    10 out of 10. Wish you good luck!!!!

  • @Grantmadeachannel
    @Grantmadeachannel 2 ปีที่แล้ว +2

    @2:45 query rewrite
    @5:10 fast refresh with log
    @7:30 DBMS_MVIEW.EXPLAIN_MVIEW
    @7:43 fast refresh on COMMIT
    @8:10 query rewrite stale_tolerated (DB can use query rewrite on MV with stale data - maintains MV speed)

  • @ash432
    @ash432 2 ปีที่แล้ว

    Subscribed sir!

  • @koskarvounis
    @koskarvounis 3 ปีที่แล้ว +1

    9:01 "Coming for you with axes" 🤣

  • @jhonatanizidoro
    @jhonatanizidoro 3 ปีที่แล้ว +1

    top, bem didático

  • @marcelvanLare
    @marcelvanLare 4 ปีที่แล้ว +2

    Nicely done. Good followup would be about importance of indices of fast mviews on refresh. Starters forget that. How to deal with a bulk update on base tables in respect to refreh. Normal fast refresh is row by row so slow on bulk. Option atomic_refresh. Option Out_of_place.

    • @TheMagicofSQL
      @TheMagicofSQL  4 ปีที่แล้ว

      Thanks, I'll bear that in mind for future videos.

  • @dummuvikash4957
    @dummuvikash4957 2 ปีที่แล้ว

    great

  • @glauberbispocruzcarvalho2235
    @glauberbispocruzcarvalho2235 2 ปีที่แล้ว

    duudeee, this explanation using bricks was perfect, thank you a lot *-*
    by the way, i'm trying to learn some advanced concepts of sql, do you have any suggestion about what should i study ?
    (sorry bout my english i'm not a native speaker)

    • @TheMagicofSQL
      @TheMagicofSQL  2 ปีที่แล้ว +1

      Thanks!
      For advanced SQL, I'd dig into:
      Analytic/window functions
      Pattern matching (match_recognize)
      On devgym.oracle.com we have a huge library of SQL quizzes; you're sure to find some here to expand your skills
      And I've got lots of articles on blogs.oracle.com/sql/ covering various aspects you may find useful.

    • @glauberbispocruzcarvalho2235
      @glauberbispocruzcarvalho2235 2 ปีที่แล้ว

      @@TheMagicofSQL Thanks

  • @tamanebp
    @tamanebp 3 ปีที่แล้ว +1

    Great info! I suppose this doesn't help if I have to make a query based on a time range though :(

    • @TheMagicofSQL
      @TheMagicofSQL  3 ปีที่แล้ว +1

      It depends on what your query and MV are! As long as it's possible to derive the result of your query using the data stored in an MV, it's possible

    • @tamanebp
      @tamanebp 3 ปีที่แล้ว

      @@TheMagicofSQL Whoah, I didn't actually expect a reply, thanks! This query could possibly contain up to 5 fields, not including the datetime field, so I wonder if that be too much of a combinatorial explosion. Watching some of your other vids, has given me some other ideas though.

    • @TheMagicofSQL
      @TheMagicofSQL  3 ปีที่แล้ว +3

      You can have up to 1,000 columns in an MV, 5 should be no trouble :)

  • @shrutisharma3469
    @shrutisharma3469 2 ปีที่แล้ว +1

    My query is failing due to out of temp storage even after increasing space. perf team suggested use_nl(a,b,c,d,e) like that. can you explain how this works and how it will help?

    • @TheMagicofSQL
      @TheMagicofSQL  2 ปีที่แล้ว +2

      The USE_NL hint instructs the optimizer to use nested loops to join the tables. Will it help? That depends on what your current plan is!

  • @kumarsatyam5218
    @kumarsatyam5218 2 ปีที่แล้ว

    how does the materilized view are behind the scence syncing the changes in the underlying table?

    • @TheMagicofSQL
      @TheMagicofSQL  2 ปีที่แล้ว

      As discussed at 5:29, for fast refresh you need to create materialized view logs on the tables used in the MV. The database then reads these changes to update the MV.
      Without this a refresh reruns the whole query

  • @livethemoment8419
    @livethemoment8419 ปีที่แล้ว

    @5:55, why do I need to have both primary key and rowid together while creating materialized view log? Any one of those 2 is sufficient right?

    • @TheMagicofSQL
      @TheMagicofSQL  ปีที่แล้ว

      The more information you include in the MV log, the more refresh options you have. Including both gives you more options in the future.
      The MV log should include all the columns you want to use in (fast refreshable) MVs. You need to include the ROWID in some types of queries to allow them to fast refresh. Which also means you need the ROWID in the log. The primary key is also often necessary for joins etc.

    • @livethemoment8419
      @livethemoment8419 ปีที่แล้ว

      Thanks for the response.

  • @MrBoomBoom225
    @MrBoomBoom225 3 ปีที่แล้ว +1

    So if you were to dumb this down..
    If I'm following this correctly -
    So with a materialized view it doesn't need to rerun and recalculate the entire query like a traditional view and updates are made if there's a delta with the base tables?
    If so, why the heck isn't everybody using this then? This sounds like a solution delivered by God!

    • @TheMagicofSQL
      @TheMagicofSQL  3 ปีที่แล้ว +2

      That's a reasonable sum up
      "why the heck isn't everybody using this then?"
      Good question :) But it's worth pointing out there are a few reasons not to use MVs:
      - Some queries are ineligible for fast refresh (applying the deltas) - count distinct is the classic example (though Oracle Database does a solution for that now)
      - For fast queries, the overhead of maintaining the MV isn't worth the speed gains you get
      - Apps can have 1,000s of queries; creating MVs to support them all is impractical; you're better off reserving these for a few critical-yet-slow queries
      I do agree that applications would benefit from using these more widely - particularly for reporting aspects

  • @prashant_chhetri09
    @prashant_chhetri09 2 หลายเดือนก่อน

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

    • @TheMagicofSQL
      @TheMagicofSQL  2 หลายเดือนก่อน

      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

  • @kanishksaxena7735
    @kanishksaxena7735 3 ปีที่แล้ว

    how can we make a materialized view in java... hibernate...Urgent Help

    • @TheMagicofSQL
      @TheMagicofSQL  3 ปีที่แล้ว +2

      I'm not familiar with Hibernate, so I'm not sure exactly. It's just a SQL statement though, so you can create it using whatever allows you to run custom SQL

  • @kirankumar-fi7pc
    @kirankumar-fi7pc 2 ปีที่แล้ว

    Sir,,it's Oracle,
    SQL server different syntax

    • @TheMagicofSQL
      @TheMagicofSQL  2 ปีที่แล้ว +4

      The videos on this channel use Oracle SQL

  • @kokizzu
    @kokizzu 2 ปีที่แล้ว

    i thought this for clickhouse XD

  • @scarlatum
    @scarlatum 2 ปีที่แล้ว

    - How count items fast?
    - Just remember quantity of them, dummy.