Тёмный
No video :(

Many to many relationships in MySQL 

PlanetScale
Подписаться 38 тыс.
Просмотров 30 тыс.
50% 1

Watch video #1 (Bitwise operations) here: • Store 8 feature flags ...
Watch video #2 (storing as JSON) here: • Storing feature flags ...
To learn more about PlanetScale, head to planetscale.co...!
💬 Follow PlanetScale on social media
• Twitter: / planetscale
• Discord: / discord
• TikTok: / planetscale
• Twitch: / planetscale
• LinkedIn: / planetscale

Опубликовано:

 

26 авг 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 65   
@dumboluzz
@dumboluzz 9 месяцев назад
Thanks Aaron! I don't even use Planetscale or MySQL, but these videos are honestly the best SQL-DB related content on RU-vid. It really takes a lot of presentation skills to make these videos that informative and entertaining. Keep it up!
@dave6012
@dave6012 9 месяцев назад
+1 to everything you just said. I primarily use mongodb and I’m still enthralled by this content 😂
@rafaelhernand3z
@rafaelhernand3z 9 месяцев назад
100 percent
@felipeflores5403
@felipeflores5403 9 месяцев назад
For real. Insta subscribed even if I don't use planetscale. Great stuff!
@vikingthedude
@vikingthedude 8 месяцев назад
Same. I use sqlite and postgres and I still find these usefule
@vasiovasio
@vasiovasio 9 месяцев назад
Great video! Please, because these videos are related put a part 1, 2, and 3 on the title for future users to find them easily.
@riccardopalleschi
@riccardopalleschi 9 месяцев назад
algorithm doesn’t like part videos
@vasiovasio
@vasiovasio 9 месяцев назад
@@riccardopalleschi Hehe, ok let's put them in an array ;)
@lucass8119
@lucass8119 9 месяцев назад
There's even more benefits to this that, IMO, make it simply the best option. One is the lack of data duplication in the DB. Since we're doing this in a very normalized and RDBMS-friendly way we're really storing the minimum amount of data to make it work. The JSON method has a ton of repeated data, stored as strings. You might see "dark mode": true for thousands of rows. Another benefit is data integrity. Leveraging the DB to enforce a schema is usually the correct choice. We can't insert a flag that doesn't exist, we can't insert for a user that doesn't exist. With JSON there's nothing stopping garbage data from being inserted, leading to silent bugs. The application then has to enforce the schema... programmatically. "dar mode": true is just a bit too easy to slip by.
@charlesbcraig
@charlesbcraig 9 месяцев назад
PlanetScale is becoming the gold standard of SQL tutorials. Did not see that coming!
@adrianorocha-dev
@adrianorocha-dev 9 месяцев назад
RU-vid started recommending me videos with Aaron in the Laravel channel too lol
@zhanezar
@zhanezar 9 месяцев назад
ive just binged watched almost all your videos , im going to do your course next , thanks for doing this
@isaacferreira7673
@isaacferreira7673 9 месяцев назад
I really appreciate your videos like this!
@chrispian
@chrispian 9 месяцев назад
Brilliant as always. I'm a big fan of many to many like this, so flexible. But I do also like the json method for some stuff too. Bitwise is just too mathy lol.
@FGj-xj7rd
@FGj-xj7rd 9 месяцев назад
Props to the ORMs for abstracting this very important relation.
@thedelanyo
@thedelanyo 9 месяцев назад
Your only video that gives me an in-depth understanding of SQL and stuffs. I just wish you can do a full tutorial on MySQL 😊
@batvetone
@batvetone 9 месяцев назад
Is there any downside of not having the `id` column on the lookup table and instead having [`user_id` and `flag_id`] being a primary key?
@scottlowe4781
@scottlowe4781 9 месяцев назад
Not as long as there’s a combo unique constraint that limits to 1 of each pair. Otherwise, if you could apply the relation multiple times, then it could be helpful to have a separate id on the join table so you can tell them apart.
@Pekz00r
@Pekz00r 5 месяцев назад
ORMs get a lot of hate in some circles, but you seem to be a strong advocate for it. Could you make a video about why you should use an ORM?
@ahmad-murery
@ahmad-murery 9 месяцев назад
Linking tables are very useful for course enrolment system (student-course, teacher-course, room-course, .certificate_template-course ..) just to name a few example of many to many relationships. I was always call it a Linking table until I read somewhere that it's called a Bridge table. the same meaning though. Thanks Aaron!
@DaviMartins99
@DaviMartins99 7 месяцев назад
Learned like 7 new things in 15 minutes
@himanshutripathi7441
@himanshutripathi7441 8 месяцев назад
Very exhaustive and eloquent. I love these videos. Ps. I used to find sql boring.
@isaacfink123
@isaacfink123 9 месяцев назад
One interesting approach to getting the data in an array is using json functionality, ive only ever seen it in drizzle and using postgres, i went through the generated query and its pretty performant plus the database is probably faster at json stuff than my js application
@ennioVisco
@ennioVisco 9 месяцев назад
Could you compare the performances among the three approaches?
@limitlesskode
@limitlesskode 9 месяцев назад
This is exactly how I would handle this. Great video 👍🏾
@GerryDanen
@GerryDanen 9 месяцев назад
We call them junction tables. Good video!
@GringoDotDev
@GringoDotDev 9 месяцев назад
Your videos are consistently amazing Aaron!
@samyaza5752
@samyaza5752 9 месяцев назад
Love your videos! Thank you!
@dcebotarenco
@dcebotarenco 8 месяцев назад
Why did you use unique constraints? Why not composed primary key? When would you use a surrogate 'id' column vs composed primary key? Would like your opinion on this ))
@ContortionistIX
@ContortionistIX 9 месяцев назад
why not have (user_id, flag_id) as the primary key?
@medilies
@medilies 9 месяцев назад
Thank you Steve
@ennioVisco
@ennioVisco 9 месяцев назад
FINALLY THE LAST EPISODE!
@nicolaicornelis2853
@nicolaicornelis2853 9 месяцев назад
I don't understand why you have a separate primary key in `users_flags` - shouldn't that just be the unique combination of user and flag? Also, the flag ID index is also required for a foreign key constraint on flags, not just for indexing flag ID alone.
@mme725
@mme725 9 месяцев назад
This was one of my questions as well, the primary key one. Also I think that the foreign key is optional, depending on if you need to use the constraint for cascading operations, referential integrity itself can be handled in the application layer.
@sudeshryan8707
@sudeshryan8707 9 месяцев назад
Having a seperate primary key helps when using a db management app for update delete tasks etc.. without primary key That wont work. There mey b other uses also.
@nelson6e65
@nelson6e65 9 месяцев назад
@@sudeshryan8707 Yes, you can use a separated id primary key or use user_id + flag_id as compound primary key directly (instead of adding a UNIQUE index).
@nicolaicornelis2853
@nicolaicornelis2853 9 месяцев назад
You define it is a primary key, you just do PRIMARY(user_id,flag_id), so that would still work.@@sudeshryan8707
@nicolaicornelis2853
@nicolaicornelis2853 9 месяцев назад
Doing referential integrity in the application layer is a big no-no. Foreign key constraints are there exactly to avoid that. In this case, there should be a foreign key between both user_flags => user and user_flags => flag@@mme725
@bielarusajed
@bielarusajed 8 месяцев назад
But why to do that when I can just make a Boolean columns for each flag in the Users table?
@SashNone
@SashNone 9 месяцев назад
Please, make video where you need to track when user had wich flag. Show current flags, or at particular date.
@RaicaBogdan
@RaicaBogdan 9 месяцев назад
So the options .... 1. Pretty savi , not gonna use it or next year I'll put a cross over my head 2. interesting, useful when you don't know the actual structure or maybe you want json back into your app 3. ORM's way love it, currently what I use, not by choice but that I find it more logical. to have everything separate. Thank you for the serie, I did learn some new stuff in the first 2 videos!
@fredyy
@fredyy 9 месяцев назад
Why are you not using REPLACE in 6:28 instead of on duplicate key
@sohailyunusmogambo
@sohailyunusmogambo 9 месяцев назад
One again great video! My boss says you should never ever create queries from the application. You should always use stored procedures for performance and security reasons. Is there any weight to this argument?
@DomskiPlays
@DomskiPlays 9 месяцев назад
Aaron youre the man
@korzinko
@korzinko 9 месяцев назад
Is there any particular reason not to use a composite primary key on the user_flags table?
@Thomas-jj1ev
@Thomas-jj1ev 9 месяцев назад
Which editor / SQL App is this?
@akulnurislamimanudin
@akulnurislamimanudin 8 месяцев назад
My question too
@audunhilden
@audunhilden 8 месяцев назад
1:26 what program is that?
@justine_chang39
@justine_chang39 9 месяцев назад
could the flags table be an enum instead?
@BatmanBruceWayne
@BatmanBruceWayne 9 месяцев назад
I was always told that when you do an EXIST (or NOT EXIST) sub-query, you have to use SELECT 1 instead of SELECT * (for performance reasons). Is that true? or it does not matter at all?
@FGj-xj7rd
@FGj-xj7rd 9 месяцев назад
MariaDB (MySQL fork) completely ignores 1 or any select columns. * Is correct.
@nelson6e65
@nelson6e65 9 месяцев назад
The foreign keys on the intermediate table were missing. 😅
@glorrin
@glorrin 9 месяцев назад
What about using an enum in the "relation table" instead of using a full table for the flags ? For me it has the benefice of searchign them by name instead of using the id, and you can have autocomplete, I lose on having a description though.
@FunkatronicGeek
@FunkatronicGeek 9 месяцев назад
From what I understand, you have to do an ALTER TABLE command to add or remove enum values, which rewrites the whole table. Not only that, it'd be tied to one table. Using a separate means you can add and remove without messing with any tables using the flags, plus you can use the flags on multiple tables
@glorrin
@glorrin 9 месяцев назад
@@FunkatronicGeek I trust you on there, I am helped by prisma a lot on this point, it is a lot easdier for me to use enums
@ganeshbabu8263
@ganeshbabu8263 12 дней назад
What is the name of the software that he used to execute command ?
@PlanetScale
@PlanetScale 12 дней назад
TablePlus!
@reed6514
@reed6514 9 месяцев назад
In your JOINs video, you didn't show your EXPLAINS or schema & you got some details wrong. The IN and EXISTS queries had the same exact execution plan. The JOIN created a temporary table of posts (presumably with > 90,000 views). You described the join as duplicating results bc of the DISTINCT filtering, but I'm just not sure that's true from my tests.
@bertilow
@bertilow 9 месяцев назад
Thumbs up!
@anhedonie92
@anhedonie92 9 месяцев назад
My insert statement went from 20 seconds to 2 seconda when writing my own SQL instead of dumb ORM doing the same select 30 times instead of 0 times. A lot of similar problems in other parts of the app. It's really wierd that you suggest using ORMs, given that the rest of stuff you make is excelent quality, ORMs are just not it. DX is awesome, but the performance is atrocious in my case (and many other devs agree).
@SeanCassiere
@SeanCassiere 9 месяцев назад
This video's title needs to be changed so people know that this is part of the feature flag series.
@dave6012
@dave6012 9 месяцев назад
“If you aren’t using an ORM, you should be!” _20 primeagan fanboys are typing_
Далее
RAND is too slow (in MySQL)
17:32
Просмотров 13 тыс.
Avaz Oxun - 10 yillik yubiley konsert dasturi 2023
2:52:33
Faster than a regular database index
13:39
Просмотров 19 тыс.
Many-to-Many Relationships - The Whiteboard #12
13:24
SQLAlchemy: The BEST SQL Database Library in Python
16:39
Pagination in MySQL - offset vs. cursor
13:20
Просмотров 57 тыс.
You don't need NoSQL (use MySQL)
31:26
Просмотров 74 тыс.
Working with time series data in MySQL
20:35
Просмотров 21 тыс.
Storing feature flags as JSON (with indexing)
14:10
Просмотров 22 тыс.
Faster database indexes (straight from the docs)
13:28
Просмотров 126 тыс.