Picking the right string column datatype - CHAR vs VARCHAR vs TEXT

Ғылым және технология

System Design for SDE-2 and above: arpitbhayani.me/masterclass
System Design for Beginners: arpitbhayani.me/sys-design
Redis Internals: arpitbhayani.me/redis
Build Your Own Redis / DNS / BitTorrent / SQLite - with CodeCrafters.
Sign up and get 40% off - app.codecrafters.io/join?via=...
In the video, I explained the different string data types in databases such as CHAR, VARCHAR, and TEXT. CHAR stores fixed-length strings, VARCHAR stores variable-length strings without padding, while TEXT allows storing strings of any length. I highlighted the trade-offs, use cases, and debunked misconceptions about these data types. I emphasized the importance of understanding database documentation for specifics, performance differences (negligible in modern databases), and considerations when choosing between VARCHAR, TEXT, and CHAR based on requirements like foreign key checks, quick index lookups, and maximum length constraints.
Recommended videos and playlists
If you liked this video, you will find the following videos and playlists helpful
System Design: • PostgreSQL connection ...
Designing Microservices: • Advantages of adopting...
Database Engineering: • How nested loop, hash,...
Concurrency In-depth: • How to write efficient...
Research paper dissections: • The Google File System...
Outage Dissections: • Dissecting GitHub Outa...
Hash Table Internals: • Internal Structure of ...
Bittorrent Internals: • Introduction to BitTor...
Things you will find amusing
Knowledge Base: arpitbhayani.me/knowledge-base
Bookshelf: arpitbhayani.me/bookshelf
Papershelf: arpitbhayani.me/papershelf
Other socials
I keep writing and sharing my practical experience and learnings every day, so if you resonate then follow along. I keep it no fluff.
LinkedIn: / arpitbhayani
Twitter: / arpit_bhayani
Weekly Newsletter: arpit.substack.com
Thank you for watching and supporting! it means a ton.
I am on a mission to bring out the best engineering stories from around the world and make you all fall in
love with engineering. If you resonate with this then follow along, I always keep it no-fluff.

Пікірлер: 34

  • @Basukinathkr
    @Basukinathkr5 ай бұрын

    Thanks Arpit. I have seen very exerienced people using varchar as a one-size-fits-all approach. They simply put any random number with it and it's done. In an enterprise environment, changing this using some liquibase script or any other approach not only involves lots of re-discussion but also break stuff. This topic of CHAR vs VARCHAR vs TEXT is very much important to understand and implement.

  • @rocksh1234
    @rocksh12345 ай бұрын

    Arpit, the explanation that you provide is extremely well-designed and in-depth. Its always a treat to watch your videos. Since you dive deep into system design concepts, request you to create a solid video on SOLID principles, this would help all levels of engineers.

  • @yash_renaissance_athlete
    @yash_renaissance_athlete5 ай бұрын

    Hi Arpit, great video as usual. It would be great if you can create a video about the behind-the-scenes of the disk IO involved with GETting a row (all the jazz around blocks, page seeks, etc.). That would also end up emphasizing and justifying the reason why there’s an additional latency of fetching a long TEXT/VARCHAR from a different page lookup and why DBs prefer to keep their rows short. Rest, keep on making such amazing videos.

  • @AsliEngineering

    @AsliEngineering

    5 ай бұрын

    That is my next video. Adding it here would have made this video an hour long. Next few videos will be about Heap tables and Toast tables.

  • @yash_renaissance_athlete

    @yash_renaissance_athlete

    5 ай бұрын

    @@AsliEngineering Thanks a ton. Appreciate it! Will wait eagerly for the next one :) My obsidian is filled with the notes of your videos by the way 😂 Cheers!

  • @DD-ds7ui
    @DD-ds7ui5 ай бұрын

    best channel! Thank you for sharing your knowledge 🙏🏽

  • @rohitdeshmukh197
    @rohitdeshmukh1975 ай бұрын

    Great content, exactly what I wanted to know. Thank you

  • @sharadkaushik79
    @sharadkaushik795 ай бұрын

    thanks Arpit bhai

  • @gecarter53
    @gecarter535 ай бұрын

    Good comparison of the 3 data types. What about NVARCHAR?

  • @arshghaiwat5241
    @arshghaiwat52415 ай бұрын

    Thanks arpit❤

  • @dhruvgarg722
    @dhruvgarg7225 ай бұрын

    We can also have index on TEXT field, can you elobrate on reason why varchar is better for quick index lookup for exactness?

  • @AsliEngineering

    @AsliEngineering

    5 ай бұрын

    that will be in my next couple of videos. some really interesting decisions taken by postgreSQL here.

  • @dataoil3620
    @dataoil36205 ай бұрын

    Thanks Arpit, another great video! Just a suggestion to make videos more interestiing, 1. I think you should use white background without any lines. 2. Just use 1 or 2 types of inks. 3. Also I think writing in slides format is better because if someone wants to read on the page, its little confusing to what to look at and where to start from. Thanks again.

  • @AsliEngineering

    @AsliEngineering

    5 ай бұрын

    Thank you for the suggestion. I tried with typed slides, but that felt more like lecture and less like a video. Plus here I can scribble and doodle. But point taken, let me make some alterations.

  • @drunkcse7476
    @drunkcse74765 ай бұрын

    Please make a video on index only scan vs index scan vs bitmap index.

  • @snehil3209
    @snehil32095 ай бұрын

    I'm here from X. What a content man!!! Already subscribed. I'm in 4th year Plz guide me how should i start system design from your playlist.

  • @AsliEngineering

    @AsliEngineering

    5 ай бұрын

    Start with kzread.info/head/PLsdq-3Z1EPT36NJXTutvKcreetuHCr9a- and then explore other videos from other playlists. Whenever you dont understand or come across a new term. DFS.

  • @whenkunda8447
    @whenkunda84475 ай бұрын

    @arpit, can you give a usecase for char? I find it hard to believe major dbs chose to implement it if there is no use case?

  • @whenkunda8447

    @whenkunda8447

    5 ай бұрын

    Never-mind gen AI to the rescue 😂 • Fixed-length fields: CHAR is useful when you need to store data that always has a fixed length, like an ISBN number or a credit card number. • Alignment and formatting: CHAR can help with aligning data in tables or reports, ensuring consistent spacing and formatting. • Compatibility: In some legacy systems or older databases, CHAR might be required for compatibility reasons.

  • @AsliEngineering

    @AsliEngineering

    5 ай бұрын

    It is a legacy column. Old systems and use cases had a requirement. Now it is not much prevalent.

  • @AsliEngineering

    @AsliEngineering

    5 ай бұрын

    But even these are now stored with varchar. Earlier it helped with displays without post processing

  • @whenkunda8447

    @whenkunda8447

    5 ай бұрын

    Thank you very much. I appreciate the response!

  • @anandatole6529
    @anandatole65295 ай бұрын

    Hi Arpit do you have any advance course on MongoDB

  • @AsliEngineering

    @AsliEngineering

    5 ай бұрын

    nope. I do not have a course on MongoDB.

  • @anujverma8057
    @anujverma805711 күн бұрын

    Good information but it would be best if the information is in hindi .

  • @harshil1466
    @harshil14662 ай бұрын

    Can the promotional stuff go to the end

  • @AsliEngineering

    @AsliEngineering

    2 ай бұрын

    No. Given my videos are heavy on engineering, most people don't watch till the end. I need to promote things at the beginning.

  • @harshil1466

    @harshil1466

    2 ай бұрын

    @@AsliEngineering ahh makes sense is there any way we can get a separate paid version ? Cause this is something i always get irritated by causing me to close the video.

  • @kaushikkumarbora
    @kaushikkumarbora5 ай бұрын

    Arpit take some vitamin d

  • @AsliEngineering

    @AsliEngineering

    5 ай бұрын

    Yes. since last few months I have been doing this more often :)

  • @oldgangster4119

    @oldgangster4119

    5 ай бұрын

    Why?

  • @VedankPande
    @VedankPande5 ай бұрын

    I'm designing a new-ish schema right now and was contemplating between varchar and text. Immaculate timing!🫡

  • @AsliEngineering

    @AsliEngineering

    5 ай бұрын

    Right on time it seems 😅

  • @VedankPande

    @VedankPande

    5 ай бұрын

    @@AsliEngineering 🙌🙌

Келесі