How do SQL Recursive CTE queries work

แชร์
ฝัง
  • เผยแพร่เมื่อ 29 ธ.ค. 2024

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

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

    Excellent content. Very well explained. Thanks Vlad!

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

      Thanks, Diego. There are more to come.

  • @gssj-o8p
    @gssj-o8p ปีที่แล้ว +1

    Nice explanation!

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

      Thanks. This video is a lesson from my HIgh-Performance SQL video course, so if you liked it, you are going to love the video course.
      vladmihalceastore.teachable.com/p/high-performance-sql-online?coupon_code=BLACKFRIDAY23

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

    Hi Vlad, thanks for your video. May I have several questions as below:
    1. why when the first statement "select 0,0" executed, then these 0,0 sent to i, and consecutive_sum? while the whole statements within "With" haven't finished yet?
    2. IN the second statment i.e. recursive statement "select i + 1, i + 1 + consecutive_sum from consecutive_sum_number" And when i + 1, i+1 + consecutive_sum will be sent to i, and consecutive_sum again for the next iteration?
    In short, it doesn't look like a native recursive isn't it? cause it doesn't seem to be function call same function, so everytime when consecutive_sum is call then within this function we have select 0,0, union with something. it quite confused me.
    Thank you

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

      SQL is a declarative language. You're analyzing the query definition using a procedural mindset. That's why it confused you.
      What you need to do is run EXPLAIN ANALYZE on the query and see exactly the stream operations done by the DB when executing the query.

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

      @@vladmihalcea Thanks Vlad, will try to explore more. anyway subcribed to your channel to see more useful contents.