Eloquent Where ENUM vs Int Foreign Key: Speed Benchmark

Поделиться
HTML-код
  • Опубликовано: 2 окт 2024
  • An experiment investigation I had in one demo project, with unexpected results.
    Full premium tutorial: laraveldaily.c...
    - - - - -
    Support the channel by checking out my products:
    - My Laravel courses: laraveldaily.c...
    - Filament examples: filamentexampl...
    - Livewire Kit Components: livewirekit.com
    - - - - -
    Other places to follow:
    - My weekly Laravel newsletter: us11.campaign-...
    - My personal Twitter: / povilaskorop
  • ХоббиХобби

Комментарии • 32

  • @trispretty
    @trispretty 3 месяца назад +4

    This was fascinating, cheers! I'm a life time member, I'm going to dive into this. Great research!

  • @wgblondel
    @wgblondel 3 месяца назад +3

    Haha, funny to see you doing this experiment too.
    Few months ago I wanted to experiment using Filament with a huge amount of data, so I cloned the Filament demo and seeded millions of records. The first challenge was to rewrite the seeders and factories in a way that the seeding process doesn't take ages to complete ... 😁 Then I had to optimize some SQL queries, and I noticed the same problem with the deleted_at fields. Had to add some indexes to improve the overall performance.

    • @e.nelson
      @e.nelson 3 месяца назад

      My other issue with filament is that bulk selecting data on a resource table takes ages to hydrate, even worse when you want you to load a form to perform data on these deleted records.

    • @JohnRoux
      @JohnRoux 2 месяца назад +1

      @@e.nelson Yeah, the bulk select will do a count*, so at 5m rows+, it's really not a great option. I end up swapping to only allowing the bulk select for this page.
      You also need to swap to simple pagination to avoid that count query though

  • @jeremyvanderwegen1467
    @jeremyvanderwegen1467 3 месяца назад +2

    Thanks, learned that we can also use multiple column indexes!

  • @laubannenberg5446
    @laubannenberg5446 3 месяца назад +1

    At first I thought this was going to be about PHP enums with casts, not sql enums. It might be interesting to dive deeper into the pros and cons of using only PHP enums (design flexibility?) or only sql enums (performance? ) or both.
    And yeah, it makes sense soft deletes should be a BIG consideration for your use of indexes.

    • @LaravelDaily
      @LaravelDaily  3 месяца назад +1

      PHP enums would have been my next step with status_number field without foreign key, but since it didn't give any performance benefits, I didn't pursue it further.

  • @mohammadsalloum1
    @mohammadsalloum1 3 месяца назад +1

    Thanks, very useful.

  • @vlatkoviamkd
    @vlatkoviamkd 3 месяца назад +1

    Please make a video for Computed properties in Livewire and be more detailed, like the last video of Josh Cirre in "Which Livewire method should I use?".

    • @LaravelDaily
      @LaravelDaily  3 месяца назад +1

      I think it's all pretty clear in the docs, my video wouldn't add something significant.

    • @vlatkoviamkd
      @vlatkoviamkd 3 месяца назад

      @@LaravelDaily maybe When to use computed properties, difference in performance and cashing with computed properties. And when NOT to use them. But either way very much appreciate your work, you are the best.

    • @LaravelDaily
      @LaravelDaily  3 месяца назад

      In my experience I didn't feel much difference, to be honest.
      I would need someone to code me a demo project that I would be able to debug and compare.
      Too much work for too niche topic.

  • @brazenbull36
    @brazenbull36 3 месяца назад

    Awesome video

  • @DoonSafari
    @DoonSafari 3 месяца назад +3

    Hi, Please make a video series on system design video for a Laravel project.

    • @LaravelDaily
      @LaravelDaily  3 месяца назад

      "system design video"? What do you mean exactly, can you rephrase?

    • @EvilVentrue
      @EvilVentrue 2 месяца назад

      ​@LaravelDaily I guess he talk about something like common architectural things such as architectural layers, business domain separation from framework etc.
      As Laravel developer, I also would like to know how we can build Laravel API with best architectural tips. I guess in "Laravel world" we choose our own philosophy with some features and solutions, but maybe we still have other approaches for architectural things?

  • @lazycode258
    @lazycode258 3 месяца назад

    Good day! Do you have any laravel tutorials that employ this vue3, type script, pinia, and axios?

  • @JohnRoux
    @JohnRoux 2 месяца назад

    Another option/improvement here is to make a virtual Stored column for `is_deleted`, a tinyint notnull (boolean) that is computed from (deleted_at IS NOT NULL)
    Then you index that column. You get around the issue with nullable columns, plus your index size is far smaller.
    It's very seldom you need to check if it was deleted before X date, and those times you can look at the `deleted_at`. But 99% of the time your query is going to be just caring about that boolean value

    • @LaravelDaily
      @LaravelDaily  2 месяца назад

      In theory, I agree with you. But I've tested a similar scenario, and "where is_deleted = 0" and "where deleted_at is null" had identical performance, when both indexed.
      Didn't check the index size, though, maybe there is a slight benefit there, to save some disk space.

    • @JohnRoux
      @JohnRoux 2 месяца назад +1

      @@LaravelDaily yeah, I suspect the difference here will be the not null covering and index size
      If there's only 1 nullable Field in the index, as the last index, then it definitely won't make any performance impact, though that index might be a lot smaller

  • @youneschibouti4555
    @youneschibouti4555 3 месяца назад

    great work, thank you

  • @ultrasys
    @ultrasys 3 месяца назад

    I didn’t have the patience to finish watching the video, but I would like to share that every time I heard “tiny int”, my ears screamed in pain.
    There’s something called padding, and it costs in terms of processing. Padding is bad for performance even if you think l it is just a matter of applying a simple calculation. The problem with it is that processors are much more efficient in loading and transferring data in their “native” block size (and this depends on what operation is being done), generally (today, at least) 64bits. Not “tiny” at all.
    Add to that, the weak MySQL code base, which, to me, looses only to MS SQL Server.

  • @abdullajonsharipov6504
    @abdullajonsharipov6504 2 месяца назад

    If not enum, column type varchar and index then ?

  • @Ali-hh9oi
    @Ali-hh9oi 2 месяца назад

    It's obviously slower because you did it wrong, you had to make a constant class of statuses (different file for each entity status, for eg TransactionStatus, ShopStatus, etc) instead of saving that on DB

    •  2 месяца назад

      What you mean?

    • @keenj
      @keenj 2 месяца назад +1

      He used $table->enum not classes. What are you talking about?

    • @Fosterushka
      @Fosterushka 2 месяца назад +2

      bruh, sql query have nothing todo with php

    • @LaravelOnline
      @LaravelOnline 2 месяца назад

      Umm…. No…

  • @373323
    @373323 3 месяца назад

    wow