3 ms·
> Is there a way to program that doesn't do something like that? Logic and relational programming (Prolog, SQL) comes pretty close. "Here's some rules about th
by paulddraper 8y ago
> Is there a way to program that doesn't do something like that?
Logic and relational programming (Prolog, SQL) comes pretty close. "Here's some rules about the data. Execute."
- TeMPOraL 8y agoAnd yet for any but toy-level (and logic/relational math research) programming, you have to pay attention to how it works under the hood. I remember university classes in Prolog. Solving logical puzzles tended to be declarative, but trying to write any actual program involved shifting to the mindset that you're dealing with a regular programming language with a built-in DFS engine underneath (the same way programming in JS involves learning you have a hidden event loop running in the background). For practical use of SQL, you need to be able to choose between equivalent queries based on how the database engine actually turns them into lookups.
- lmm 8y ago> And yet for any but toy-level (and logic/relational math research) programming, you have to pay attention to how it works under the hood. Maybe 30 years ago. It's really not so important nowadays. Computers are fast. > For practical use of SQL, you need to be able to choose between equivalent queries based on how the database engine actually turns them into lookups. Maybe there are some cases where you need to, but there are also million-dollar businesses that have succeeded while only ever writing their SQL queries as naively as possible. The notion that all non-toy practical uses need to understand such low-level details is just utterly false.
- zbentley 8y ago> there are also million-dollar businesses that have succeeded while only ever writing their SQL queries as naively as possible. Citation needed. Given engineering staff sizes and the amount of performance problems RDBMSes have, that seems highly doubtful.
- lmm 8y agoPersonal working experience; afraid I'm not willing to name specific past employers here.
- yorwba 8y agoEven then you need to understand the underlying execution model. Prolog has cuts that guide the backtracking engine. SQL performance is hard to optimize without looking at query plans.
- paulddraper 8y agoIf you are working with large data sets and want it fast then yes. But in regards to "Is there a way to program that doesn't do something like that?", I would say relational is that way.
- fake-name 8y agoWhen writing SQL, I think of "what is the DB engine going to do when I ask this". I don't see that as being substantially different.
- paulddraper 8y ago:) You must be psychic if you can figure out what the DB engine is going to do without running it. Bitmap scan, parallel index scan, merge join, nested loop join, etc. I always have to try and see.
- zbentley 8y agoIt's not a superpower at all--instead, I'd argue that it's the most important skillset (after understanding the relational model itself) for interacting with RDBMSes at scale. You don't necessarily have to know whether an index scan is going to be parallelized or whether the CBO is going to switch to a loop because its heuristics think your result set is likely tiny to think about things like "is this data being accessed via the right indexes? Is the data likely in memory or not? Will my joins, given my consistency level, impose locks or concurrency considerations on the tables I expect?"
- fake-name 8y agoOh, I'm not generally correct, but my process of "writing" generally goes: - Guess what I think is going to happen - EXPLAIN ANALYZE - Ohhh, it did [thing]. Lemme tweak if I can convince it to do [other thing] that should work better - <Repeat> I'd argue testing against the DB is a core part of the process for writing a query.