The art of truly understanding database systems boils down to the following principles.
- You cannot do much with data on disk until you read it to memory.
- You cannot do much with data on memory until it is read into the CPU L caches.
- You cannot do much with data on the CPU cache until it is read into the CPU registers.
- Reading from disk (SSD) is 2000~ times slower than reading from memory.
- Reading from memory is 200~ times slower than reading from the CPU cache (L1d)
- Reading from L caches is 20 times slower than reading from the CPU registers
- Disk is abundant.
- Memory is limited.
- CPU cache is a scarce resource.
- And CPU registers are extremely limited.
- When reading a block of bytes from disk to memory, plan to use it fully, over and over again.
- The block of bytes will be cached in the CPU L cached available to you hot. If you don’t use it something else will take its place.
- When your block is kicked out, you incur the cost of bringing it back on
With these principles in mind, a good database engineer will appreciate the colossal task of a simple index scan and rewrite your SQL queries, configuration, data modeling and perhaps the storage engine itself to achieve optimum efficiency.
Finally these are only guiding principles and meant to be broken.
For those interested in databases you can grab my fundamentals of database engineering course
Master's in GeoInformatics - GIS Consultant | GIS Specialist | FME | Python | SQL | ESRI | ArcFM | Telecom | Utility | Geospatial Data Services | Remote Sensing | Urban & Landscape planning
1 个月Very informative
Analista de Informática Legislativa at Senado Federal
1 个月These are excellent tips, but most of the time, performance issues are due to poorly written SQL or a lack of proper indexes in the database. For better diagnostics, learn how to interpret the EXPLAIN output, which reports the access paths being used.
Dev turned data engineer. Will write SQL for food.
1 个月"rewrite... perhaps the storage engine itself". no pressure ??
Frontend Developer | Passionate about JavaScript, React, and Next.js | BCA Student
1 个月Wow, I’m absolutely?thrilled?to see this! Your insights are truly?inspiring?and reflect a?passionate?commitment to excellence. I love how you approached this challenge with such?creativity?and?drive. It’s exciting to witness the impact of your work, and I can’t wait to see what you accomplish next! Keep pushing the boundaries—your efforts are making a difference!
Data Engineering | Distributed Infrastructure, Data Products, Making big data, small | Data Nerd | ex-Amazon
1 个月As the saying goes the most efficient I/O call is the one that is never made.