Tobias_Petry.sql Profile Banner
Tobias_Petry.sql Profile
Tobias_Petry.sql

@tobias_petry

Followers
21,245
Following
278
Media
553
Statuses
7,827

The Database Guy. I am helping you get better with MySQL and PostgreSQL. Building: @stackbricksapp

Darmstadt, Germany
Joined June 2013
Don't wanna be here? Send us removal request.
Explore trending content on Musk Viewer
Pinned Tweet
@tobias_petry
Tobias_Petry.sql
8 months
I am thrilled to announce the official launch of the @IndexingBook . Do you lack indexing knowledge? It has never been easier to learn! This broad topic is explained in a novel, easy-to-understand way supported by graphics that visualize all concepts. 🔥
32
114
424
@tobias_petry
Tobias_Petry.sql
7 months
PHP did the markup and server code mixing 20 years ago and collectively decided its a bad idea as it becomes unmaintanable pretty fast. Now that gets further complicated by also mixing with frontend-stack complexity... Can somebody explain to me why that is a good idea now?
Tweet media one
490
566
4K
@tobias_petry
Tobias_Petry.sql
2 years
⚡️ Database Tip For e.g. a dashboard, multiple queries on the same rows have to be executed to calculate different statistics. However, these queries can also be combined into one query that has to scan the rows only once!
Tweet media one
22
201
1K
@tobias_petry
Tobias_Petry.sql
10 months
Your app's biggest performance problems are probably databases, not tech-stack related.
@kentcdodds
Kent C. Dodds 🌌
10 months
Your app's biggest performance problems are probably backend, not frontend related.
91
177
2K
38
63
883
@tobias_petry
Tobias_Petry.sql
2 years
⚡️ Database Tip Sometimes you have date ranges in your database and you don't want them to overlap. Two people staying in the same room at the same time in a hotel is a big problem. You can define constraints for your tables so that time ranges can never overlap!
Tweet media one
16
136
841
@tobias_petry
Tobias_Petry.sql
2 years
⚡️ Database Tip Sometimes you want to get e.g. the last three orders for *every* customer. Normal joins can't do that. You have to execute n+1 queries in code, which is slow! But with lateral joins, you can do one for-each loop join in SQL 🤯
Tweet media one
35
160
787
@tobias_petry
Tobias_Petry.sql
4 months
35GB is a joke for any database. There is no need to change anything. Always find out if something is really slow or you just think it is. And when you found slow queries, just optimize them. Suggesting to switch the database technology is the worst feedback you can give.
@levelsio
@levelsio
4 months
What's the SQLite strategy for when databases get too big? Photo AI's photos.db is 35.2GB with 7,270,478 photos in it now (just metadata, pics are stored on R2) Should I make a script that empties older photos and put them in a photos_archive.db and keep the photos.db fast?
Tweet media one
254
35
1K
15
59
750
@tobias_petry
Tobias_Petry.sql
11 months
🎉 The FREE MySQL Explain Tool is live Even after years of optimizing queries, I find MySQL's EXPLAIN output hard to understand. For someone with less experience, it is almost impossible. So I've built a free tool in the past months to simplify it.
18
168
649
@tobias_petry
Tobias_Petry.sql
1 year
⚡️ Database Tip For e.g. a dashboard, multiple queries on the same rows have to be executed to calculate different statistics. However, these queries can also be combined into one query that has to scan the rows only once!
Tweet media one
8
99
637
@tobias_petry
Tobias_Petry.sql
2 years
⚡️ Database Tip Did you know there are alternative ways of storing trees in a database without a parent_id and many queries to get all ancestors/children or the complex nested set concept? You can store the materialized path for every row to get much easier tree management!
Tweet media one
31
106
607
@tobias_petry
Tobias_Petry.sql
3 years
⚡️ Database Tip Sometimes you have very complex queries involving multiple calculation steps. Instead of nesting queries or doing it in application code you can use Common Table Expressions (CTE) to refine your data in every step and even reuse former steps.
Tweet media one
17
119
600
@tobias_petry
Tobias_Petry.sql
2 years
⚡️ Database Tip Creating indexes is a handcraft learned from experience, multiple-column indexes is a lot more complicated. But it doesn't have to be complicated! Here are 3 simple rules for the column ordering of multiple column indexes, solving 80% of the perf problems.
Tweet media one
23
132
599
@tobias_petry
Tobias_Petry.sql
2 years
⚡️ Database Tip Sometimes you have very complex queries involving multiple calculation steps. Instead of nesting queries or doing it in application code, you can use Common Table Expressions (CTE) to refine your data in every step and even reuse former steps.
Tweet media one
19
86
583
@tobias_petry
Tobias_Petry.sql
3 years
⚡️ Database Tip Did you know there are alternative ways of storing trees in a database without a parent_id and many queries to get all ancestors/children or the complex nested set concept? You can store the materialized path for every row to get much easier tree management!
Tweet media one
24
93
587
@tobias_petry
Tobias_Petry.sql
2 years
⚡️ Database Tip Everyone knows the LIMIT clause. But what do you do if you want to have e.g. the employees with the TOP 3 salaries *and* not exclude the 4th or 5th one earning the same as the 3rd? The WITH TIES clause can return more results if the value is the same. Great!
Tweet media one
13
103
557
@tobias_petry
Tobias_Petry.sql
22 days
So Vercel pushed the idea of edge rendering to an entire generation of developers. And now admits that it was a bad idea... And why? Because your database is not at the edge. Its somewhere else and your paying big latency for _every_ query. Told you all the time!
@leeerob
Lee Robinson
23 days
So, @vercel reverted all edge rendering back to Node.js 😬 Wanted to correct the record here as it's something I've advocated for in the past, and share what I've learned since then. Also, the "edge" naming has been a bit confusing, so let's clear that up here as well. What is…
113
206
2K
30
47
556
@tobias_petry
Tobias_Petry.sql
2 years
⚡️ Database Tip Deleting an unused index is still a risky operation: If you are wrong (and it is still needed) the database will become slow. Before deleting it, you can make the index invisible first and make it visible again instantly if you still need it.
Tweet media one
14
82
547
@tobias_petry
Tobias_Petry.sql
9 months
[Howto] Creating Indexes for JOINs - an excerpt from the upcoming @IndexingBook Optimizing joins seems complicated. How should the following query be optimized? It is using multiple tables and not just one! 👇 The full explanation
Tweet media one
3
71
532
@tobias_petry
Tobias_Petry.sql
2 years
I've been sharing weekly database tips on Twitter for one year. To celebrate this milestone, I've repackaged the best ones into an eBook 🎁 Get your *FREE* copy and discover so much you didn't know before! And follow me for more ;)
19
130
538
@tobias_petry
Tobias_Petry.sql
3 years
⚡️ Database Tip Sometimes you want to make columns unique but you can't because e.g. there are still soft-deleted rows in the table witht the same value. By only including relevant rows (partial index) you can still enforce uniqueness, and you can even simulate it for MySQL!
Tweet media one
14
98
526
@tobias_petry
Tobias_Petry.sql
6 months
⚡️ Database Tip Sometimes you want to get e.g. the last three orders for *every* customer. Regular joins can't do that. You have to execute n+1 queries in code, which is slow! But with lateral joins, you can do a for-each loop join in SQL
Tweet media one
8
65
516
@tobias_petry
Tobias_Petry.sql
1 year
SQL is the only thing you can learn today and is still not outdated in 10+ years. The most rewarding thing: learn once, apply your whole career.
@craigkerstiens
Craig Kerstiens
1 year
Devs will do anything but learn SQL
39
37
444
25
69
513
@tobias_petry
Tobias_Petry.sql
3 months
So basecamp is using their MySQL database as a queue running millions of jobs each day. But you say that a database couldn't handle your (tiny) load and you have to use something more complex? I doubt it.
@dhh
DHH
3 months
We've shipping Mission Control: The missing web UI for Solid Queue! This is what we use internally to run millions of daily jobs. Please help us refine it for inclusion in Rails 8.
4
40
388
24
50
503
@tobias_petry
Tobias_Petry.sql
8 months
A database index cannot be infinitely large. At some point, you will get an error message that the size limit is exceeded and the index creation is canceled. But there are some tricks that you can still create an index for e.g. many big string columns. 👇 Learn More
Tweet media one
5
63
496
@tobias_petry
Tobias_Petry.sql
1 year
⚡️ Database Tip Sometimes you want to get e.g. the last three orders for *every* customer. Normal joins can't do that. You have to execute n+1 queries in code, which is slow! But with lateral joins, you can do one for-each loop join in SQL 🤯
Tweet media one
11
84
476
@tobias_petry
Tobias_Petry.sql
9 months
A Different View On B+ Trees For Database Indexes - a chapter preview from the upcoming @IndexingBook that I am writing Each article or book explaining database indexes starts by describing what B+ trees are: the distinction of leaf nodes (the most bottom rectangles) vs. inner…
Tweet media one
Tweet media two
5
56
463
@tobias_petry
Tobias_Petry.sql
3 years
⚡️ Database Tip Sometimes you have date ranges in your database and you don't want them to overlap. Two people staying in the same room at the same time in a hotel is a big problem. You can define constraints for your tables that time ranges can never overlap!
Tweet media one
13
101
461
@tobias_petry
Tobias_Petry.sql
1 year
📣 Announcement: I quit my job! For a long time, I felt the need to change something. So from today on, I am a freelance database consultant! And as I now have much more time to work on stuff, you will see many cool things in the following months. Stay tuned!
49
8
452
@tobias_petry
Tobias_Petry.sql
2 years
Here's the first screenshot of {Project Foo} which I am working on. A free desktop application to run multiple different databases versions (even ancient ones) all at the same time on your development machine. It will have full support for linux, macOS (intel + m1) and windows.
Tweet media one
27
46
443
@tobias_petry
Tobias_Petry.sql
2 years
⚡️ Database Tip When doing statistical aggregations by time, you may have e.g. days without data leading to strange results when charting the results. But you don't have to fill these gaps manually with code, the database can do that for you.
Tweet media one
15
65
442
@tobias_petry
Tobias_Petry.sql
8 months
⚡️ Database Tip Sometimes you want to get e.g. the last three orders for *every* customer. Regular joins can't do that. You have to execute n+1 queries in code, which is slow! But with lateral joins, you can do a for-each loop join in SQL
Tweet media one
7
77
440
@tobias_petry
Tobias_Petry.sql
2 years
⚡️ Database Tip Most developers are puzzled that indexes are not used for e.g. WHERE LOWER(email) = ?. But contrary to common belief, an index can be created for these cases! It's called a function-based index and is supported by MySQL and PostgreSQL.
Tweet media one
8
76
426
@tobias_petry
Tobias_Petry.sql
2 years
⚡️ Database Tip You don't have to execute multiple queries to calculate different aggregates. With the filter clause you can narrow the rows which should be included for the calculation. So you may need to scan the table only once, the performance impact can be massive 🔥
Tweet media one
10
74
428
@tobias_petry
Tobias_Petry.sql
2 years
⚡️ Database Tip Everyone knows the LIMIT clause. But what do you do if you want to have e.g. the employees with the TOP 3 salaries *and* not exclude the 4th or 5th one earning the same as the 3rd? The WITH TIES clause can return more results if the value is the same. Great!
Tweet media one
13
70
424
@tobias_petry
Tobias_Petry.sql
2 years
A common problem in databases is hot rows that need to be updated very often, e.g. counters. I've used this pattern for a long to remove write contention lock but didn't know it has a name.
12
78
422
@tobias_petry
Tobias_Petry.sql
8 months
[Howto] Creating Indexes for Subqueries - an excerpt from the upcoming @IndexingBook Subqueries are still believed to be slow, although they are just missing matching indexes. Creating good ones for subqueries is not particularly complicated. 👇 The full explanation
Tweet media one
3
59
415
@tobias_petry
Tobias_Petry.sql
6 months
⚡️ Database Tip Deleting hundreds of thousands of rows is slow, impacts your performance and doesn't free the allocated disk space. But you can delete old data very efficiently if you partition your table by time ranges and drop one of them.
Tweet media one
6
49
410
@tobias_petry
Tobias_Petry.sql
2 years
⚡ Database Tip Creating indexes is a handcraft learned from experience, multiple-column indexes is a lot more complicated. But it doesn't have to be complicated! Here are 3 simple rules for the column ordering of multiple column indexes, solving 80% of the perf problems.
Tweet media one
14
74
399
@tobias_petry
Tobias_Petry.sql
2 years
⚡️ Database Tip Every tutorial for pagination is sharing the same inefficient and wrong concept of pagination with OFFSET and LIMIT. Cursor pagination is much more efficient and won't show rows multiple times which will happen sometimes! It's a simple change, just do it!
Tweet media one
21
59
393
@tobias_petry
Tobias_Petry.sql
3 years
⚡️ Database Tip When storing JSON values in your database, you should still use a schema. MySQL does provide the excellent function JSON_SCHEMA_VALID which will validate the column against a @jsonschema definition. Make use of it!
Tweet media one
8
72
389
@tobias_petry
Tobias_Petry.sql
1 month
Your SQL query is slow and you need to create an index. But which one? An index on a single column is wrong 99% of the time... 👇 Learn with 5 tweets why you always need a multi-column index
Tweet media one
19
47
440
@tobias_petry
Tobias_Petry.sql
10 months
Beware of MySQL adding columns after another one. Before 8.0.29 the full table needs to be re-created when this option is used which locks it up until finished. Without the option, the column can be added instantly. So is the ordering that important to you? 😉
@enunomaduro
Nuno Maduro ☁️ 🦹
10 months
This @laravelphp tip never gets old! If you wanna throw in a bunch of columns right after an existing column, just go ahead and rock that "after()" method. 💅🏻
Tweet media one
24
48
340
33
55
359
@tobias_petry
Tobias_Petry.sql
8 months
Why Can a Unique Index Store the Same Value Twice? If your unique index includes nullable columns, its behavior to enforce uniqueness may not be what you expect it to do. 👇 Learn More
Tweet media one
8
47
355
@tobias_petry
Tobias_Petry.sql
9 months
After much work, the new landing page for the upcoming @IndexingBook is live 🥳 It showcases everything that makes this book different from anything you've seen before. What's your opinion? Good? Bad? Any ideas for improvement?
21
54
347
@tobias_petry
Tobias_Petry.sql
7 months
And thats an honest question! I am so far away from the frontend world that I just can't understand the reasoning. Did they decide now that creating all those API endpoints is too much work?
21
4
331
@tobias_petry
Tobias_Petry.sql
2 years
⚡ Database Tip Recursive queries are a great solution to e.g. querying multiple levels in a tree with just one query. But you should use cycle detection otherwise your query might run forever or fail for loops in your data.
Tweet media one
7
58
330
@tobias_petry
Tobias_Petry.sql
4 months
⚡️ Database Tip Deleting hundreds of thousands of rows is slow, impacts your performance and doesn't free the allocated disk space. But you can delete old data very efficiently if you partition your table by time ranges and drop one of them.
Tweet media one
7
51
333
@tobias_petry
Tobias_Petry.sql
1 year
Have you tried optimizing a query with EXPLAIN? I often do not understand it myself. So much (useless) information and the important ones are hard to see. That will no longer be the case! I wrote a *FREE* tool to make this output easy to understand. More infos soon... 😉
Tweet media one
17
29
332
@tobias_petry
Tobias_Petry.sql
1 year
⚡️ Database Tip Most developers are puzzled that indexes are not used for e.g. WHERE LOWER(email) = ?. But contrary to common belief, an index can be created for these cases! It's called a function-based index and is supported by MySQL and PostgreSQL.
Tweet media one
9
56
326
@tobias_petry
Tobias_Petry.sql
3 years
⚡️ Database Tip Most developers are puzzled that indexes are not used for e.g. WHERE LOWER(email) = ? Most developers are unaware of it, but you CAN create an index so this will be very fast!!! It's called a functional index and is supported by MySQL and PostgreSQL.
Tweet media one
10
68
328
@tobias_petry
Tobias_Petry.sql
9 months
How To Create Multi-Column Indexes: From Left to Right - a chapter preview from the upcoming @IndexingBook that I am writing An index on a single column is simple, easy to understand and nobody has problems using them. The real problem and performance improvement opportunity is…
Tweet media one
Tweet media two
Tweet media three
Tweet media four
8
49
316
@tobias_petry
Tobias_Petry.sql
11 months
⚡️ Database Tip There are alternative ways of storing trees in a database without a parent_id relationship or the complex nested set concept. You can store the materialized path for every row for easier tree management!
Tweet media one
13
40
321
@tobias_petry
Tobias_Petry.sql
2 years
⚡ Database Tip Duplicate rows are created easily by mistake, but can be deleted much easier: You can in a *single* SQL query specify the duplicate rows to keep and also keep more than one!
Tweet media one
14
65
317
@tobias_petry
Tobias_Petry.sql
1 year
Most developers still believe @MySQL and @mariadb to be the same. But over the years they developed completely different features. I am currently collecting all the differences to write a very big article. What missing features in one of the databases did you encounter?
28
32
317
@tobias_petry
Tobias_Petry.sql
1 year
👀 New Preview for my MySQL Explain Tool Even EXPLAINs for simple joins display a lot of meaningless internal information about a query's execution. While the important ones are hidden. Compare what MySQL shows and what I extract from that. What do you like more? 😉
Tweet media one
21
30
303
@tobias_petry
Tobias_Petry.sql
3 years
⚡️ Database Tip There can be a faster way to group a table by multiple attributes compared to executing many queries. With GROUPING SETS the table needs only to be scanned once instead of multiple times. The performance improvement can be massive 🔥
Tweet media one
6
68
297
@tobias_petry
Tobias_Petry.sql
1 year
👀 New Preview for my MySQL Explain Tool Simple plans are easy to understand. But with subqueries? It is now much easier to understand the relationship between the main query and subqueries - and whether they are independent or dependent. Release next week 😉
Tweet media one
20
28
292
@tobias_petry
Tobias_Petry.sql
1 year
I say the same for years: Choose a relational DB (PostgreSQL/MySQL), add Redis for caching etc and optionally add an OLAP DB like ClickHouse for large-scale analytics. DON‘T COMPLICATE YOUR TECH STACK WITH FAANG SOLUTIONS DESIGNED FOR MUCH BIGGER SCALE!
11
46
281
@tobias_petry
Tobias_Petry.sql
2 years
You may not need a gazillion servers for your startup. Stack Exchange is running on 23 servers serving 1.3B requests/day. They use a few beefy machines instead of a lot more commodity servers to keep their maintenance low. Database Servers? Only 4! 🤯
8
62
284
@tobias_petry
Tobias_Petry.sql
1 year
🎉 My change for Laravel 10.x was merged to replace DB::raw() with database expressions that can generate SQL code dependent on the database being used! It would be great if everyone can respond with actual raw() statements used, that I should support! 👇
Tweet media one
18
23
278
@tobias_petry
Tobias_Petry.sql
10 months
⚡️ Database Tip Sometimes you are updating the same rows concurrently, e.g. with counters. But each query has to wait for all the ones before to finish. You can prevent this locking problem by spreading the counter updates to many more rows.
Tweet media one
6
52
280
@tobias_petry
Tobias_Petry.sql
1 year
⚡️ Database Tip Deleting hundreds of thousands of rows is slow, impacts your performance and doesn't free the allocated disk space. But you can delete old data very efficiently if you partition your table by time ranges and drop one of them.
Tweet media one
5
53
281
@tobias_petry
Tobias_Petry.sql
11 months
👀 New Laravel Package Laravel Queries can now be submitted directly from your code to to get understandable EXPLAIN information. There isn't any more excuse for not optimizing your queries ;)
Tweet media one
10
48
277
@tobias_petry
Tobias_Petry.sql
1 year
🎉 Laravel package released In the past it was troublesome working with raw() statements because they would not work on all databases. But now you can use them with new database-indendepent versions. And use some more advanced stuff... Check it out:
Tweet media one
16
42
266
@tobias_petry
Tobias_Petry.sql
2 years
⚡️ Database Tip Your application will have bugs and any data stored may be corrupt forever. But with constraints on the data model, rules would have prevented saving incorrect data in the first place! Use them as a last frontier to make sure you always have valid data.
Tweet media one
7
49
263
@tobias_petry
Tobias_Petry.sql
1 year
⚡️ Database Tip When storing JSON values in your database, you should still use a schema. MySQL does provide the excellent function JSON_SCHEMA_VALID which will validate the column against a JSON schema definition. Make use of it!
Tweet media one
5
40
260
@tobias_petry
Tobias_Petry.sql
2 years
⚡️ Database Tip Extending a traditional database schema with NoSQL-like JSON columns can make the schema more understandable. But you should also ensure these JSON documents conform to an expected schema!
Tweet media one
12
50
259
@tobias_petry
Tobias_Petry.sql
2 years
⚡️ Database Tip When doing statistical aggregations by time, you may have gaps in your data. You don't have to fill them manually with code! You can generate a series of dates from a start to end time and use these days to join to your statistical data with gaps.
Tweet media one
17
35
253
@tobias_petry
Tobias_Petry.sql
2 years
I still don't have a final name for my ebook that will be released next week. My first idea was "Database Secrets for Developers" but that is too clickbaity. I don't love the current title "The Database Handbook for Developers" either as I am only sharing many tips. Your ideas?
Tweet media one
68
11
252
@tobias_petry
Tobias_Petry.sql
9 months
⚡ Database Tip Duplicate rows are created easily by mistake and can be removed almost as easy: You can in a *single* SQL query identify them and also specify which one to keep! It is the fastest way you can do it.
Tweet media one
6
42
249
@tobias_petry
Tobias_Petry.sql
3 years
I finished a large chunk on improving the enhanced @PostgreSQL driver for @laravelphp . The new version has a lot of new indexing functionality to make your database queries really fast and use all the power of PostgreSQL 🔥 👇 All new features explained one-by-one
Tweet media one
2
49
251
@tobias_petry
Tobias_Petry.sql
2 years
⚡️ Database Tip Many applications use the table's numeric primary key in the URL: Bots can scrape all data by incrementing the ID and competitors know your number of customers/resources and growth.Adding a random UUID which is used in URLs solves this.
Tweet media one
19
45
249
@tobias_petry
Tobias_Petry.sql
1 year
⚡️ Database Tip Did you know there are alternative ways of storing trees in a database with simplified querying and much easier tree management? Materialized paths are easier to query than parent_id relationships and easier to update than nested sets.
Tweet media one
8
49
247
@tobias_petry
Tobias_Petry.sql
2 years
⚡️ Database Tip Your application probably has numerous indexes to guarantee fast performance. For columns which are only used in equality checks, you can use hash indexes, which can be smaller and faster. You don't need to use the standard b-tree index always!
Tweet media one
13
40
247
@tobias_petry
Tobias_Petry.sql
2 years
⚡️ Database Tip Tag searching can be done wholly differently: You can store the tag primary keys in a JSON array and effectively search for overlapping tag ids or missing ones without very complex joins. A single where instead of multiple (slow) joins to do the same thing.
Tweet media one
12
34
243
@tobias_petry
Tobias_Petry.sql
11 months
With previous patches being merged into Laravel, I was now able to create one that has been requested for quite some years: User::where(...)->ddRawSql() It prints the generated SQL query *with* bindings embedded safely into the query 🤯
12
22
245
@tobias_petry
Tobias_Petry.sql
1 year
I use database queues in most projects. They are a lot more performant than you believe. And you can do nice tricks with transaction safeties that job queuing and your logic are perfectly in sync. And one infrastructure component less to manage 😉
14
28
240
@tobias_petry
Tobias_Petry.sql
1 year
Can you? 😁
Tweet media one
8
24
235
@tobias_petry
Tobias_Petry.sql
3 months
⚡️ Database Tip Sometimes you have date ranges in your database and you don't want them to overlap. Two people staying in the same room at the same time in a hotel is a big problem. You can constrain your tables to disallow conflicting values!
Tweet media one
6
31
239
@tobias_petry
Tobias_Petry.sql
1 year
🎉 I‘ve been awarded a MySQL Rockstar 2022 award for the SQL educating stuff I created last year. 🤩
Tweet media one
27
9
237
@tobias_petry
Tobias_Petry.sql
8 months
⚡️ Database Tip When doing statistical aggregations by time, you may have e.g. days without data leading to strange results when charting the results. But you don't have to fill these gaps manually with code, the database can do that for you.
Tweet media one
8
42
234
@tobias_petry
Tobias_Petry.sql
1 year
⚡ Database Tip Duplicate rows are created easily by mistake, but can be deleted much easier: You can in a *single* SQL query specify the duplicate rows to keep and also specify which one to keep! It is the fastest way you can do it.
Tweet media one
8
30
233
@tobias_petry
Tobias_Petry.sql
2 years
⚡️ Database Tip Many applications are vulnerable to enumeration attacks: The numeric primary key is used in URLs, and incrementing the value will find all records. In my experience, adding a random UUID which is used in URLs instead is the simplest solution for the problem.
Tweet media one
16
40
235
@tobias_petry
Tobias_Petry.sql
7 months
phpMyAdmin is still the most widely used MySQL tool but lacks any help in understanding EXPLAIN output. I proposed adding an option to analyze EXPLAIN plans with my free service to help a big audience of developers tuning queries. Waiting for feedback 🤞
10
19
229
@tobias_petry
Tobias_Petry.sql
2 months
This is probably the best reason WHY i use PostgreSQL if I don’t need anything very specific: The rich ecosystem of extensions has solutions for probably everything I may need. I don‘t have to use new-niche-hype-database.
Tweet media one
8
28
232
@tobias_petry
Tobias_Petry.sql
1 year
⚡️ Database Tip With PostgreSQL your INSERT/UPDATE/DELETE queries can return the data of affected rows. You can use this to more efficiently implement many operations by selecting, updating and fetching rows all in one query for maintenance operations.
Tweet media one
4
29
228
@tobias_petry
Tobias_Petry.sql
2 years
Spoiler: I am working on a free ebook that compiles my best database tips. It will be launched in a few weeks celebrating 12 months of sharing database knowledge every week 🥳 Can you recommend any ebook covers? I need some inspiration.
13
9
222
@tobias_petry
Tobias_Petry.sql
3 months
Everyone should try @caddyserver to replace nginx as it is more easy. And with FrankemPHP built by @dunglas even the PHP integration gets easier and more powerfull - no more php-fcgi needed 🎉
Tweet media one
15
33
226
@tobias_petry
Tobias_Petry.sql
1 year
⚡️ Database Tip Sometimes you want to make columns unique, but you can't because e.g. there are still soft-deleted rows in the table with the same value. By only including relevant rows (partial index), you can still enforce uniqueness.
Tweet media one
6
36
222
@tobias_petry
Tobias_Petry.sql
2 years
⚡️ Database Tip Every tutorial for pagination is sharing the same inefficient and wrong concept of pagination with LIMITs. Cursor pagination is much more efficient and won't show rows multiple times which will happen sometimes!
Tweet media one
8
37
223
@tobias_petry
Tobias_Petry.sql
2 years
My free database book is finally on @ProductHunt today! 🎉 Did you read it? Did you love/hate it? Did you learn something new? I don't believe you saying no 😛 I would really appreciate it if you share your opinion on PH ❤️
11
38
219
@tobias_petry
Tobias_Petry.sql
2 years
⚡️ Database Tip Most developers are puzzled that indexes are not used for e.g. WHERE LOWER(email) = ?. But contrary to common belief, an index can be created for these cases! It's called a function-based index and is supported by MySQL and PostgreSQL.
Tweet media one
7
35
218
@tobias_petry
Tobias_Petry.sql
2 years
⚡️ Database Tip In most applications, all rows are physically sorted in the database file by their insertion order. By sorting them instead optimally for your application a huge databases will still be amazingly fast.
Tweet media one
8
41
218
@tobias_petry
Tobias_Petry.sql
1 year
⚡️ Database Tip You don't have to execute multiple UPDATE queries because each one is dependent on some data stored in another table. You can join an UPDATE with other tables to do row updates which depend on data stored in other tables.
Tweet media one
3
45
219
@tobias_petry
Tobias_Petry.sql
2 years
⚡️ Database Tip Most developers are puzzled that indexes are not used for e.g. WHERE LOWER(email) = ?. But contrary to common belief, an index can be created for these cases! It's called a function-based index and is supported by MySQL and PostgreSQL.
Tweet media one
10
45
213
@tobias_petry
Tobias_Petry.sql
1 year
⚡️ Database Tip Sometimes you have date ranges in your database and you don't want them to overlap. Two people booking the same hotel room at the same time is a big problem. You can define constraints for your tables that those ranges never overlap!
Tweet media one
7
28
215
@tobias_petry
Tobias_Petry.sql
7 months
Microservices have been invented to scale teams and not applications. High-traffic serverless is not cheaper than EC2 machines but you can sometimes do more with less effort. You should know which problem technologies solve and not blindly follow them
13
45
216
@tobias_petry
Tobias_Petry.sql
1 year
⚡️ Database Tip When doing statistical aggregations by time, you may have e.g. days without data leading to strange results when charting the results. But you don't have to fill these gaps manually with code, the database can do that for you.
Tweet media one
8
31
211
@tobias_petry
Tobias_Petry.sql
1 year
⚡️ Database Tip If you're using numeric primary keys in your URLs, your app may be vulnerable to enumeration attacks. A simple fix? Use random UUIDs in URLs instead while keeping a numeric primary key!
Tweet media one
16
34
207
@tobias_petry
Tobias_Petry.sql
1 year
📣 Announcement I repeatedly see the same misconceptions and need for practical knowledge about indexes. You only find introductory stuff but nothing for real applications. I will change that with a full book dedicated to indexes.
14
46
207