Don't hide your database indexes!

แชร์
ฝัง
  • เผยแพร่เมื่อ 21 ก.ค. 2024
  • Using a redundant condition is a technique to allow MySQL to use an index where it might otherwise be impossible!
    00:00 Intro
    01:06 Redundant condition drawing
    02:12 Obfuscated indexes in MySQL
    03:04 Obfuscated index example
    04:50 Redundant condition example
    06:18 Explaining the ADDTIME query
    07:18 Adding a redundant condition
    08:59 A second example
    10:41 When to use redundant conditions
    📚 Learn more about PlanetScale at planetscale.com/youtube.
    ------------------
    💬 Follow PlanetScale on social media
    • Twitter: / planetscaledata
    • Discord: / discord
    • TikTok: / planetscale
    • Twitch: / planetscale
    • LinkedIn: / planetscale
  • วิทยาศาสตร์และเทคโนโลยี

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

  • @COLAMAroro
    @COLAMAroro 11 หลายเดือนก่อน +29

    Wow, I'm really glad TH-cam recommended me this channel. This is really well explained, with great examples, even for people (like me) who aren't DBA experts, just devs

  • @clo4
    @clo4 11 หลายเดือนก่อน +14

    Very good explanation! Just a meta-note: timestamps in the description have to start at 0:00 to show in the player

    • @PlanetScale
      @PlanetScale  11 หลายเดือนก่อน +4

      Doh, thank you!

  • @joe5head
    @joe5head 11 หลายเดือนก่อน +6

    Great analogy and communicated superbly. Love it!

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

    This is awesome!

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

    One of the best internet teach is around again. Let's like the video, watch and learn something new today.

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

      Glad you enjoyed it!

  • @s1mplelulu
    @s1mplelulu 11 หลายเดือนก่อน +1

    OMG this is the best I have seen in year

  • @serhiivoichyk
    @serhiivoichyk 8 หลายเดือนก่อน +2

    Really great content, the example on 7:19 is the most interesting one. I've tried it by myself and it really works. However, does it always work? I mean, is there a chance that another database/db engine might execute 'AND' conditions in a less optimal way ignoring the fact that it's beneficial to get results for "circle B" first?

  • @alexaneals8194
    @alexaneals8194 8 หลายเดือนก่อน

    I wanted to add this on a separate comment: sometimes when running explain on a query, you will still get a table scan instead of an index scan because the table does not contain enough rows to make sense for the database to do an index scan. Some databases allow you to "force" the use of an index, but that may lead to performance degradation. Always, test whether using the index increases the query's performance.

  • @alexaneals8194
    @alexaneals8194 8 หลายเดือนก่อน

    This is good advice not just for MySql, but SQL Server also. Although, for your opening comments, don't underestimate the brain. It processes far more information than databases can, it just does it subconsciously. If we had to consciously calculate with a computer everything our brain processes, we would fry it's circuits.

  • @tuval012
    @tuval012 4 หลายเดือนก่อน

    Very good! Very good content very good explanation very good performance.

  • @Formula7Driver
    @Formula7Driver 7 หลายเดือนก่อน

    I have an even better, real-life example of this. So the goal was to determine which cab drivers were inside of 3km radius of a certain point, and the app was calculating the distance for every cab driver to that point, and there were a lot of them. So then I figured out that every cab driver was inside a square of 6x6km. Based on the latitude, I calculated the width and height of that square in degrees, and applied that to the latitude and longitude columns of the taxi drivers table

  • @byronleigh80
    @byronleigh80 11 หลายเดือนก่อน

    Brilliant

  • @ahmedmunna2416
    @ahmedmunna2416 9 หลายเดือนก่อน

    Great videos A A ron
    💗💗💗

  • @guitarhero69
    @guitarhero69 11 หลายเดือนก่อน

    i cant create a free database in planet scale . it asks me for my card info and it wont charge for anything until and unless i choose the pro options but my card always gets declined

  • @JohnRoux
    @JohnRoux 10 หลายเดือนก่อน +1

    Would be even better to show the explain analyze for these, to show the filtering from circle b
    Great stuff though!

  • @dhirajnaik2119
    @dhirajnaik2119 11 หลายเดือนก่อน +1

    So if I have index created on first_name and I use LOWER(first_name) for comparison in a query. Will the index created on first_name not be used??

    • @markusflosbach1852
      @markusflosbach1852 10 หลายเดือนก่อน +2

      It will
      a) not be used
      b) depending on your Collation (Case Insensitive?) Lower() might not even be neccessary
      :-)

    • @dealloc
      @dealloc 9 หลายเดือนก่อน

      There's a video on that, too. "MySQL case insensitive searching (don't use LOWER)"

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

    Great tip

  • @Aalii6
    @Aalii6 8 หลายเดือนก่อน

    👍👍👍

  • @Fanaro
    @Fanaro 11 หลายเดือนก่อน

    Do a video on books about MySQL!

    • @PlanetScale
      @PlanetScale  11 หลายเดือนก่อน +1

      That's a good idea actually... Thank you!

    • @Fanaro
      @Fanaro 11 หลายเดือนก่อน

      @@PlanetScale A beginner to expert roadmap of books would be a great Aaron Francis video I believe.

  • @user-kr6lp7rm5y
    @user-kr6lp7rm5y ปีที่แล้ว +1

    What app is used in the video?

  • @SaiyanJin85
    @SaiyanJin85 5 หลายเดือนก่อน

    ok, that was 10/10... again..

  • @elliejohnson2786
    @elliejohnson2786 11 หลายเดือนก่อน

    What are "Indexes"?

    • @PlanetScale
      @PlanetScale  11 หลายเดือนก่อน

      We actually have a whole section available in our free MySQL for Developers course! This would explain indexes best: planetscale.com/learn/courses/mysql-for-developers/indexes/introduction-to-indexes

    • @Yorgarazgreece
      @Yorgarazgreece 11 หลายเดือนก่อน

      Think of a phone catalog
      In a phone catalog you have a list of names along with a list of phone numbers that match said names. If you want to search in that catalog efficiently, you'd use the pagination feature. So if you want to find what's George's phone number for example, you'd go straight to G page.
      In a database the index in this scenario would be this pagination feature (letters A-Z that relate to contact's names). You could in theory say that this pagination is actually an index on contact name column. Obviously this is a gross oversimplification but it should help you understand why they need to exist and how much the performance increases because of their existence.

  • @RaicaBogdan
    @RaicaBogdan 8 หลายเดือนก่อน

    I won the prize! 👍 😄

  • @medilies
    @medilies 11 หลายเดือนก่อน

    Why not force index?

  • @RajveerSingh-vf7pr
    @RajveerSingh-vf7pr 9 หลายเดือนก่อน

    Although your content is awesome, but I am always reluctant to click on the video because of the long duration
    I always feel like your 10 mins videos can be encapsulated in 2 shorts...
    It does not matter if I am alone, but may be you should try to put up a poll or something to see if I am not alone.

    • @PlanetScale
      @PlanetScale  9 หลายเดือนก่อน

      Thanks for the idea! We've been experimenting and the longer videos do a whole lot better unfortunately. We'll keep experimenting though

    • @GrantGryczan
      @GrantGryczan 9 หลายเดือนก่อน

      I like the longer, more in-depth videos personally, as I'm new to database development. Although I could imagine agreeing and wanting to skip the fluff if I were already experienced.

    • @alexander2576
      @alexander2576 9 หลายเดือนก่อน +1

      Long videos from Aaron are very enjoyable. He shares his happy inner state along with the creatively and funnily wrapped content. So it is not only about tips and tricks, but much more. And I noticed, this way the knowledge also absorbs deeper 😅