Database Performance Regrets and Schema Changes

I absolutely love this post. I've seen a lot of databases where it seemed that the people designing it did not realize they were making performance decisions they would later regret. Once people feel the pain of those decisions, the databse and app have often been around so long that it is often too late to convince them to change it because changing the database schema means app layer changes they don't want to make. These folks will frequently say the recommended changes can't be done "because it would be too much work." Then those same people will often ask, "Is there anything else we can do to make it perform better?" I understand the desire for some other answer that involves less work. But sometimes there are no other answers. A house sitting on a busted foundation can only be "prettied up" so much. #database

Database Performance Tuning Rule #8: Your schema is a performance decision you made. What that means: Every data model decision has a query cost attached to it. Storing status as a VARCHAR instead of a smallint: → Every index on that column is larger. → Every comparison takes more CPU. → Trivial individually. Expensive at 500M rows. Normalizing a user profile into six tables: → Every profile page load needs six joins. → At 10,000 users/day: fine. → At 10,000 users/minute: those joins become the bottleneck. Putting created_at as a nullable column: → Now your time-range queries need IS NOT NULL checks. → The planner estimates null proportion from statistics. → Bad statistics → wrong plan → wrong index. Ask these questions at schema design time:  • What is the most frequent query this table will serve?  • What is the write rate at peak?  • How will this table look at 10x current row count?  • Which columns will appear in WHERE clauses? Are they indexed-friendly types?  • Are there any nullable FK columns? (Each one is a potential lock incident waiting to happen in MySQL.) Schema reviews are performance reviews. Most teams treat them as correctness reviews. Correctness is table stakes. Performance is what you'll be pinged about. ───────────────────────────────────────────────── ♻️ Repost to every engineer who designs tables. Follow Haider Z. 📩 Real incidents, RCAs, SQL queries every week → https://lnkd.in/d3M5-pJA

“Putting created_at as a nullable column: → Now your time-range queries need IS NOT NULL checks. → The planner estimates null proportion from statistics. → Bad statistics → wrong plan → wrong index.” Columns that should never be null should be NOT NULL for logical reasons, not performance reasons. But even so this feels like a problem that just as easily occurs with not null columns (bad stats) and if you have no null data, why would the stats imply you do?

Like
Reply

I am dealing with a similar situation with a SaaS provider at the moment. I have streamlined their cloud and hardware architecture as much as possible to give them the strongest runway to address issues within their product. However, when the underlying storage is capable of nearly 100 GB per second at the disk level while the database layer is only achieving approximately 50 MB per second, it is difficult to avoid the conclusion that the bottleneck lies within the application or database design rather than the infrastructure.

See more comments

To view or add a comment, sign in

Explore content categories