Read any book by C.J.Date (especially this one ), for all the reasons SQL is poorly designed. I also think SQL is a big big mess full of leaky abstractions that forces you to do things in unituitive ways. My knowledge of LINQ is much less than SQL (partly also because I was writing plenty of SQL before LINQ existed). > "Yes, EF queries are more readable to many developers who know C# well but don't want to get used to SQL." It's slightly old fashioned but that's just fashion. It's a DSL designed for the job, you really can't get much better (except for Elastic Search use cases, etc.). It is more readable for a lot of use cases. Ok this is a bit of a strawman (although it is based on experience) but I think saying SQL is less readable is a red herring. By writing the damn SQL to begin with they'd have to tame the beast earlier on and address the design flaws in their schema and/or application. They discover "indexed views" and all is well until you start to have locking problems, so more hacks are needed. Which of the 10 table scans or index scans to tackle first? And how do you tackle it? The query plan for those beasts is intractable. But the problem with that is DB apathy + EF leads to some real performance problems as systems scale that grinds the application to a halt with SQL queries longer than dissertations, to which the developers need a quick hack to fix. Yes, EF queries are more readable to many developers who know C# well but don't want to get used to SQL. Just like Python and C# are equally readable to the respective cohorts that are used to programming in those languages. This is one way in which I mean SQL is bad. (Contast to the LINQ examples, or perhaps a shell pipline.) In a way, this is the substance of the original article. I need to basically read the entire statement to understand the parts. When I examine an SQL expression, and then visualize the relational operators involved, I find a very poor correspondence between the SQL expression and the relational algebra. We can ask: How well does SQL allow us to express an algorithm in relational terms? (Let's ignore that that SQL introduces some non-relational impurities that may have practical value - eg column order, row order, duplicate rows.) When we solve problems using relations, we benefit by thinking in terms of relations. So, we use relations to represent the data in the application domain, and use the operators of relational algebra to take relational inputs and produce relational outputs. The foundation theory is the relational model of data, and the use of operators from relational algebra. But in practice I find outer joins are more often used in these sort of situations.) (EDIT: I should probably call this "too many joins" instead, since it's not really specific to outer joins. If you don't know about this mistake, it's easy to get the wrong answer from aggregate functions like AVG or COUNT. Thinking imperatively about JOINs is also a helpful way of understanding a mistake I call "too many outer joins", which I wrote about here. You can even think about the joins "imperatively". Especially if your answer corresponds to an existing table, put that in the FROM, and then add whatever joins you need. I've trained a lot of non-developers (and new-developers) to use SQL, and one of my favorite tips is, "Start with FROM."Įven sooner than "start with FROM" is "What does each row of the result mean?" Is it a sale? A month of sales? A customer? If you can answer what you want, then it's usually easy to start there. Optimizer nuances aside, I agree with this and think it's helpful for anyone writing SQL.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |