←back to thread

SQL Design Patterns (2010)

(vadimtropashko.wordpress.com)
149 points mci | 4 comments | | HN request time: 0s | source
Show context
alphazard ◴[] No.45077668[source]
I always tell people to worry about the data structures that you want the database to maintain for you, and not worry about the SQL. You can always use Google to look up the SQL, or now ChatGPT to generate it for you. SQL is a not-that-great language and it intentionally hides what's going on. It is also different enough between databases that you need to pay attention. So learning to design/think in terms of SQL is probably not worth doing.

The set of data structures that you use to model and index a dataset is worth understanding, and designing in that space is a skill worth learning.

replies(4): >>45078199 #>>45078627 #>>45078711 #>>45081027 #
sgarland ◴[] No.45078627[source]
Frankly, this is terrible advice. If you’re not designing your data model around the language it’s going to be queried in, how do you expect to get decent performance out of the database?

Also, in no way does SQL hide anything - it’s a declarative language, and will produce exactly what you tell it to, provided you understand what it is you asked it to do. The query engine is somewhat of a black box, but that is completely orthogonal.

replies(2): >>45078761 #>>45079856 #
paulddraper ◴[] No.45078761[source]
SQL is a declarative language so it —- by definition —- hides the execution.

Not really sure what you’re trying to argue here.

replies(3): >>45079245 #>>45079749 #>>45082341 #
1. sgarland ◴[] No.45079245[source]
Parent made it sound - to me - that you put an input in and hope for the best. If you understand the operators, you can quite confidently predict an output given an input.
replies(1): >>45079453 #
2. halfcat ◴[] No.45079453[source]
> If you understand the operators

That’s the point. In an imperative language if you don’t yet understand (or make a typo, or whatever), you can just print/console.log and find out.

I’ve seen junior devs, data analysts, and LLMs spin their wheels trying to figure out why adding a join isn’t producing the output they want. I don’t think they would figure it out using SQL alone if you gave them a month.

replies(2): >>45081238 #>>45083340 #
3. SkiFire13 ◴[] No.45081238[source]
The equivalent of `print`/`console.log` in SQL would be using subqueries/CTE and run them to see the intermediate result (just like `print`/`console.log` show you intermediate results of the executions in an imperative language).
4. sgarland ◴[] No.45083340[source]
Then you back off, and go back to first principles. Create the minimum example of the problem, and as a sibling comment mentioned, break it down to its constituent parts and observe what happens in each.