编程与软件工程erikbern.com
我不想学习你的查询语言(2018)
I don't want to learn your query language (2018)
2018 — 2021,它一次次回到首页
黑点是上首页(≥ 50 分)的那次投稿,空心点是没冲上去的投稿,点越大分数越高。
导读
这篇 2018 年的文章吐槽各类数据系统都要求用户学习自家查询语言或 DSL,主张应尽量复用 SQL 这类通用查询方式。评论区围绕 SQL 是否真的通用、专用查询语言和 ORM 是否各有价值展开了争论。
为什么经久不衰:它触及了“通用 SQL 还是领域专用查询语言”的长期争论,今天在数据库、搜索和数据分析工具选型中仍然值得一读。
HN 评论精选
SQL 适合简单查询,但复杂逻辑和糟糕工具链让它不是万能解。
我只想要回 SQL。它从七十年代就存在,相对标准化,易读,业务人员和工程师都能用。但我也依赖 SQL 并常推荐它,不过这种看法太简单了:SQL 写简单查询容易,写稍复杂的逻辑却极其复杂晦涩;我多次帮业务或分析团队修巨大的 SQL 查询,体验很糟。SQL 周边工具常常很差,十几年来几乎没进化;不用 ORM 从别的语言发 SQL,往往意味着手动拼字符串,没有类型安全。
dgellow查看英文原文
> I just want my SQL back. It's a language everyone understands, it's been around since the seventies, and it's reasonably standardized. It's easy to read, and can be used by anyone, from business people to engineers. I rely a lot on SQL and in general advocate for it, but that’s too simplistic of a view IMHO. SQL makes it easy to write and read simple queries, and ridiculously complicated and arcane to write slightly more complex logic. More than once I’ve been asked to help fix giant SQL queries written by a business or analytics team and that’s a terrible experience. Also, the tooling around SQL is often terrible and almost didn’t evolve during the past 15+ years. SQL queries from another programming language without an ORM means that you do everything by manipulating strings by hand, with zero type safety. Edit: My favorite library in Go is reform, a generator that generates types and implement the Scanner/Valuer interfaces. You annotate your structs, generate the types, add the generates files to git, done. That way you have very limited ORM magic but gain some type safety. And you still have complete control over your SQL queries (which is often frustrating to do with classic ORMs). https://github.com/go-reform/reform Edit 2: the most promising ORM I’ve seen is Prisma, https://www.prisma.io/. I haven’t tried yet, I’m still quite attached to writing most of my SQL by hand because that’s what I know well, but their pitch seems good to me.
专用查询语言与系统架构匹配,不能简单要求它们都换成 SQL。
只有关系数据库才能用纯 SQL 查询。文章里的多数例子并不是关系库,它们解决不同问题,底层架构差异巨大。Lucene 做文本搜索,Splunk 面向不同领域,MongoDB 也不是关系数据库;查询语言直接影响生成的 AST,而 AST 必然与系统能力和内部实现紧密绑定。文章看起来像只粗略看了一眼这些系统做什么。如果 Lucene 只有正则,它不会比 SQL 数据库对字符串跑正则好多少;正因查询语言更细粒度,才能针对该用例优化。
zaptheimpaler查看英文原文
Yeah I think the only way you can use plain, vanilla SQL to query a system is IF its a relational database. Most of the examples are not.. they solve different problems and have vastly different architectures under the hood. Lucene for example doesn't use SQL because its really solving a different problem - text search. Its a language dedicated to what could only be expressed using something like `LIKE` and regexes in SQL. Same with Splunk, it addresses a different domain and solves different problems that cant be easily expressed in SQL. Same with MongoDB.. its not a relational db. Just because there is a mapping from some SQL queries to some Mongo queries, does not mean they are identical databases. The query language directly impacts the AST generated, which is necessarily tied very closely to the exact capabilities/internals of a system. This post just feels like its based on a cursory glance of what the systems do. If all Lucene had was regexes, it would not perform much better than a SQL database throwing regexes at strings. Its precisely because the query language is finer-grained that it can be better optimized for that usecase.
DSL 通过领域专业化提升效率,学习它是使用工具的一部分。
那个“聪明孩子不用 DSL”的梗很好笑,但当真就是垃圾观点。DSL 很重要,因为专业化通常会让工具和人更高效。Splunk 有反映产品架构的专用查询语言;想高效使用一个软件,就得学它的语言。澄清一下:领域特定语言意味着领域特定的概念。当产品不再是通用查询,而是针对特定系统中特定类型的信息查询时,我们就可以利用这些领域知识做出强大的语言。
ThemalSpan查看英文原文
That “smart kids say no to DSLs” meme is funny but also a garbage take if taken at face value. DSLs are important because specializing will generally make you / your tool more effective. Splunk has a special query language that reflects the product’s architecture. If you want to become productive with a piece of software you need to learn its language. Edit: To clarify my position, Domain specific languages mean domain specific ideas. As soon as a product is no longer meant for general queries, but for queries over specific ki day of information in a specific kind of system, we can use that knowledge to make a powerful language in that domain.
SQL 方言差异大,ORM 还提供安全与便利,文章论调过于简单。
暗示 SQL 到处都一样有点谬误。从 Postgres 到 SQL Server、MySQL、Oracle,做法差异很大。select 和 join 大体相同,可能只是逗号之类不同;但一旦进入复杂的大数据操作,就完全是另一回事。数据导入、临时表、insert 还是 update 的选择,各平台都不同。此外,Entity Framework 这类 ORM 能确保语句以处理注入等安全问题的方式准备好;让团队用 ORM,就不必太担心有人用“';DROP tables”之类的名字注册。ORM 有它的位置,SQL 也不是人人都会的铁板一块。文章论点缺乏细微。
alexc05查看英文原文
It is a bit falicous to imply SQL is the same everywhere. If you move from postgres to sql server to mysql to oracle you'll see there are major differences in how things are done. Sure, your select and join is mostly the same, maybe with a few different commas here or there. Once you get into complex large data operations though it's a whole new ballgame. Imports happen in wildly different ways, temp tables, choices of inserts vs. updates is a per-platform choice in some cases. On top of all that, an ORM like entity framework (C#) handles things like making sure the statements are prepared in a way that "handles" major security issues like dependency injection out of the box. If you make your team use an ORM you don't have to worry quite as much about someone named ';DROP tables ' signing up to your system. (Or whatever) ORM has it's place. SQL isn't a monolith that everyone* knows. The discussion is worth having, but I think the OP's argument lacks nuance.
历次讨论
同类还值得读
开源应用架构
The Architecture of Open Source Applications
《开源软件架构》(AOSA)是一本在线免费书,邀请知名开源项目的作者亲自剖析其内部设计,涵盖 SQLAlchemy、LLVM、Audacity、Apache、Bash 等系统。
编程与软件工程上首页 9 次 · 2011–2024aosabook.org编辑精选编程语言简史:简短、不完整且多半错误
A Brief, Incomplete, and Mostly Wrong History of Programming Languages
一篇以戏谑、故意不准确的方式回顾编程语言史的博客文章,用夸张轶事和讽刺定义串起 Lisp、C、C++、Java、JavaScript、PHP 等语言。
编程与软件工程上首页 8 次 · 2009–2021james-iry.blogspot.comSQLite 是如何测试的
How SQLite is tested
SQLite 官方文档页,系统介绍 SQLite 的测试体系:多种测试方法(TCL 测试、模糊测试、回归测试、静态分析等)和海量测试用例,展示了这个小型开源项目如何靠极致测试获得…
编程与软件工程上首页 8 次 · 2009–2025sqlite.org编辑精选高级编程语言(2009)
Advanced programming languages (2009)
Matt Might 的经典文章,按用途推荐“高级编程语言”:如果追求就业就选主流语言,如果追求表达力、学术研究或创业,则推荐 Haskell、OCaml、Scala 等函数式语…
编程与软件工程上首页 8 次 · 2009–2022matt.might.net我的 Forth 与栈机器经历
Yosefk - My history with Forth & stack machines
作者以亲身经历回顾了使用 Forth 语言和栈式机器的历程:既赞叹其简洁优雅、代码量小、可自举的优点,也坦率指出栈操作在实际编程中的痛苦,以及 Forth 社区文化中的问题。
编程与软件工程上首页 8 次 · 2010–2024yosefk.com编辑精选