50年長盛不衰,SQL爲什麼如此成功?

{"type":"doc","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"本文最初發佈於arctype博客,經原作者授權由InfoQ中文站翻譯並分享。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"1971年3月,英特爾推出世界上第一款通用微處理器——"},{"type":"link","attrs":{"href":"https:\/\/spectrum.ieee.org\/tech-history\/silicon-revolution\/chip-hall-of-fame-intel-4004-microprocessor","title":"","type":null},"content":[{"type":"text","text":"英特爾4004"}]},{"type":"text","text":"。它有約2300個晶體管,售價60美元。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"時間快進到50年後,最新的iPhone有將近120億個晶體管。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"我們今天使用的許多編程語言直到90年代才推出(Java是在1996年推出的)。不過,有一種編程語言現在仍然像近50年前推出時一樣流行:SQL。本文將討論關係型數據庫產生的背景、SQL爲什麼越來越流行,以及我們可以從它的成功中學到什麼。"}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"早期數據庫管理的歷史—IDS和CODASYL"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/infoq\/7d\/7d9debd5b16f99e440334c3a8e13fe1e.png","alt":null,"title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"1962年,查爾斯·w·巴赫曼(與埃利希·巴赫曼沒有關係)是通用電氣一個小團隊的一員。一年後,巴赫曼團隊推出了後來被公認爲第一個數據庫管理系統的集成數據存儲系統(IDS)。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"10年後,巴赫曼獲得圖靈獎(通常被稱爲計算機科學領域的諾貝爾獎),以表彰他對IDS計算的貢獻。"}]},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":"IDS是什麼?"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在20世紀60年代早期,計算機科學剛開始成爲一個學術領域。ASCII直到1963年才推出。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"要理解IDS,我們必須首先理解促成其發展的兩大驅動力:"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"numberedlist","attrs":{"start":1,"normalizeStart":1},"content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":1,"align":null,"origin":null},"content":[{"type":"text","text":"磁盤存儲的推出"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":2,"align":null,"origin":null},"content":[{"type":"text","text":"向高級編程語言的遷移"}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"磁盤存儲"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/infoq\/34\/342380a7ccd51860a07d1ed9feb5d948.png","alt":null,"title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":"center","origin":null},"content":[{"type":"text","text":"移動一臺RAMAC 305"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"1956年,IBM推出第一款商用硬盤驅動器——RAMAC 305。磁盤驅動器的引入使得程序員可以直接跳轉到磁盤上的某個位置進行數據檢索和更新。與其前身磁帶驅動器相比,這是一個巨大的改進,後者需要在磁帶上順序移動來檢索特定的數據片段。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"但是現在,開發人員必須找出記錄在磁盤上存儲的位置。由於早期操作系統中"},{"type":"link","attrs":{"href":"https:\/\/medium.com\/@princeabhishek410\/understanding-file-management-system-in-operating-system-4c7fbfc306f2","title":"","type":null},"content":[{"type":"text","text":"文件管理系統"}]},{"type":"text","text":"的侷限性,這是一項只有有經驗的程序員才能完成的高級任務。開發人員需要一種解決方案來簡化磁盤驅動器的使用。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"高級編程"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"與此同時,在"},{"type":"link","attrs":{"href":"https:\/\/en.wikipedia.org\/wiki\/Diffusion_of_innovations","title":"","type":null},"content":[{"type":"text","text":"採用曲線"}]},{"type":"text","text":"上,計算機科學開始從創新者轉變爲早期採用者。像彙編這樣的低級編程語言早期在學術界很流行,但是出於易用性考慮,普通程序員開始轉向高級編程語言,比如COBOL。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"link","attrs":{"href":"https:\/\/cacm.acm.org\/magazines\/2016\/7\/204036-how-charles-bachman-invented-the-dbms-a-foundation-of-our-digital-world\/fulltext?mobile=false#body-3","title":"","type":null},"content":[{"type":"text","text":"那麼什麼是IDS呢?"}]},{"type":"text","text":"IDS解決了磁盤存儲和高級編程問題。IDS允許開發人員使用高級編程語言(如COBOL)來構建從磁盤存儲輸入和檢索數據的應用程序。由於這個功能,IDS獲得了第一個數據庫管理系統的殊榮。"}]},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":"CODASYL:一個數據庫管理系統的新標準"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"1969年,數據系統語言委員會(CODASYL)發佈了一份報告,提出一個數據庫管理標準。巴赫曼是委員會的一員,該報告主要參照了IDS。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"CODASYL數據模型引入了許多我們今天使用的數據庫管理系統的核心特性:"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"模式"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"數據定義語言(DDL)"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"數據操作語言(DML)"}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"最重要的是,IDS和CODASYL引入了一種新的數據建模方法,這種方法影響了SQL的最終開發——網絡數據模型。"}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"網絡數據模型——比如今的關係模型更好?"}]},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/infoq\/94\/944701fdf866a3d7b6b36a499005efd6.png","alt":null,"title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":"center","origin":null},"content":[{"type":"text","text":"網絡模型示例"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"數據模型是一種描述(模型)世界(數據)的標準化方法。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"前面的層次數據模型使用樹型結構來描述數據,但是這些樹型結構僅限於一對多的關係。新的網絡模型允許記錄有多條父記錄,從而創建一個圖結構。通過支持多個父節點,網絡模型能夠對多對一和多對多關係進行建模。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在網絡模型中,表之間的關係存儲在集合中。每個集合都有一個所有者(即教師)和一個或多個成員(即班級和學生)。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"網絡模型的其中一個主要好處是,集合中的相關記錄是通過指針直接連接的。集合是使用next、prior和owner指針實現的,這樣就可以像鏈表一樣輕鬆遍歷。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"網絡數據模型的低級特性提供了性能優勢,但也付出了代價。網絡數據模型增加了存儲成本,因爲每個記錄都必須額外存儲指向前一條記錄和父記錄的指針。"}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"關係模型的到來"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/infoq\/6e\/6ef8d7228aa1b6fd8b111a15d8f97fd3.png","alt":null,"title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":"center","origin":null},"content":[{"type":"text","text":"關係模型示例"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"1970年,在IDS誕生8年後,Edgar F. Codd在他的開創性論文《"},{"type":"link","attrs":{"href":"https:\/\/www.seas.upenn.edu\/~zives\/03f\/cis550\/codd.pdf","title":"","type":null},"content":[{"type":"text","text":"A relational model of Data for Large Shared Data Banks"}]},{"type":"text","text":"》中引入關係模型(這也爲他贏得了圖靈獎)。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Codd指出,數據庫中的所有數據都可以用元組(SQL中的行)表示,這些元組被分組成關係(SQL中的表)。爲描述數據庫查詢,他發明了一種一階謂詞邏輯的形式,稱爲元組關係演算。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"元組關係演算引入了一種聲明性語言用於查詢數據。使用聲明性編程語言,程序員只需說明他們想做什麼,而不必描述如何做。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"對開發人員來說,這種新的聲明性語言更容易使用。關係模型公開了所有數據。開發人員可以用一條命令,從一個表中檢索所有數據或者讀取一行數據。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在指針迷宮中查找數據的日子已經一去不復返了。"}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"關係數據模型 vs 網絡數據模型"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"關係型數據庫通過數據規範化降低了網絡型數據庫的高昂存儲成本。規範化是一個分解表以消除冗餘的過程,可以減少磁盤佔用。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"然而,關係型數據庫增加了CPU成本。爲了處理規範化數據,關係型數據庫必須將表加載到內存中,並使用計算能力將表“連接”在一起。讓我們通過一個例子來看下這個過程:在一個關係模型中,給定老師,查找所有的班級和學生。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"首先,數據庫系統執行一個操作來檢索所有相關的班級。然後,它將執行第二個操作來檢索學生數據。所有這些數據都將存儲在內存中,在返回結果前,它將運行第三個操作來合併數據。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/infoq\/df\/df4e9975b832c80fa8ee3dd45e64f4cb.png","alt":null,"title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":"center","origin":null},"content":[{"type":"text","text":"關係模型和網絡模型的性能對比"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在一個使用真實數據的性能案例研究中,"},{"type":"link","attrs":{"href":"https:\/\/raima.com\/network-model-vs-relational-model\/","title":"","type":null},"content":[{"type":"text","text":"Raima"}]},{"type":"text","text":"發現,網絡數據庫模型的插入性能好23倍,查詢性能快123倍。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"那麼爲什麼關係型數據庫會成爲領先的數據庫解決方案?"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"易用性"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"關係模型更容易修改,它的聲明性語法簡化了程序員的工作。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"摩爾定律在背後發揮了神奇作用。計算成本持續下降,最終,生產力的提高抵消了關係模型所增加的計算成本。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"快進50年,現在,數據中心中最昂貴的資源是CPU。"}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"SQL崛起"}]},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/infoq\/d0\/d05b2c76dfddf16960b7321de29b96c7.png","alt":null,"title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"最後,我們迎來了大家都喜歡的SQL。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在Codd的論文發表4年後,Donald Chamberlin和Raymond Boyce發表了《"},{"type":"link","attrs":{"href":"https:\/\/dl.acm.org\/doi\/10.1145\/800296.811515","title":"","type":null},"content":[{"type":"text","text":"SEQUEL: A Structured English Query Language"}]},{"type":"text","text":"》。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"他們將SEQUEL描述爲“一組關於表格結構的簡單操作,[…]和一階謂詞演算同樣強大。”IBM看到其潛力,並在20世紀70年代早期迅速開發出SEQUEL的第一個版本,作爲其System R項目的一部分。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"由於與英國Hawker Siddeley飛機公司的"},{"type":"link","attrs":{"href":"https:\/\/en.wikipedia.org\/wiki\/SQL","title":"","type":null},"content":[{"type":"text","text":"商標問題"}]},{"type":"text","text":",其名稱後來改爲SQL。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"SQL的下一個大發展是在近十年後。1986年,美國國家標準協會(ANSI)和國際標準化組織(ISO)發佈第一個官方SQL標準:SQL-86。該標準"},{"type":"link","attrs":{"href":"https:\/\/www.db-book.com\/","title":"","type":null},"content":[{"type":"text","text":"將SQL分爲以下幾個部分"}]},{"type":"text","text":":"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"數據定義語言(DDL):此類命令用於定義和修改模式及關係;"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"數據操作語言(DML):此類命令用於查詢、插入和刪除數據庫信息;"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"事務控制:此類命令用於指定事務的時間;"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"完整性:此類命令用於對數據庫信息設置約束;"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"視圖:此類命令用於定義視圖;"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"授權:此類命令用於指定可以訪問的用戶;"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"嵌入式SQL:此類命令用於具體說明如何將SQL嵌入其他語言。"}]}]}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"SQL的競爭者"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"從1974年到今天,有許多競爭者試圖從SQL統治的查詢語言市場中搶佔市場份額。通常,這些新語法是針對特定的新技術:"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Lisp ->CLSQL"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":".NET ->LINQ"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Ruby on Rails ->ActiveRecord"}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"35年過去了,在數據庫中,SQL仍然無處不在。SQL作爲一種查詢語言是如何保持統治地位的?我們可以從它的故事中學到什麼?"}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"SQL統治市場50年的祕密"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/infoq\/d4\/d4b74de0f24361585324666fd1a2fd3c.png","alt":null,"title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":"center","origin":null},"content":[{"type":"text","text":"Stack Overflow開發者調查,2017"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在文章開頭,我們首先介紹了巴赫曼推出的第一個數據庫管理系統IDS。我們討論了爲什麼磁盤存儲和高級編程需要一種處理數據的新方法。然後,CODASYL來了,規範了數據庫管理。IDS和CODASYL引入了新的網絡數據模型,而最終,Codd投下了關係模型。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"這個過程持續了8年。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"SQL是如何在接下來的50年裏堅持下去的呢?我認爲主要有四個原因:"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"numberedlist","attrs":{"start":1,"normalizeStart":1},"content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":1,"align":null,"origin":null},"content":[{"type":"text","text":"基於第一性原則構建"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":2,"align":null,"origin":null},"content":[{"type":"text","text":"布什內爾定律"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":3,"align":null,"origin":null},"content":[{"type":"text","text":"傾聽和調整"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":4,"align":null,"origin":null},"content":[{"type":"text","text":"採用API"}]}]}]},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":"基於第一性原則構建"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"第一性原則是一個基本命題,它不能從任何其他命題或假設中推導出來。例如,將碳氫化合物與氧氣結合,產生化學反應。這仍然是驅動每一輛車的內燃機原理。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"1970年,Codd爲數據庫創建了一個新的第一性原則:元組關係演算。這個新創建的邏輯引出了關係模型,然後引出SQL。元組關係演算是化學反應,關係模型是內燃機,SQL是汽車。"}]},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":"布什內爾定律"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"僅僅建立在第一性原則上並不能保證其成功。彙編是程序員所能做到的最接近輸入1和0的程序,但它仍然被COBOL(後來是C)所取代。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"它缺少的一個關鍵要素是可用性。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"從網絡模型到關係模型的轉換,我們看到同樣的情況。網絡模型性能更好,但是現在每個公司都在使用關係型數據庫,因爲它很容易(入手)。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"blockquote","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"最好的遊戲易於學習而難於精通。——Atari創始人諾蘭·布什內爾"}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"諾蘭·布什內爾知道如何讓人們使用新產品。但遺憾的是,彙編既難學又難精通。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"SQL找到了完美的平衡。10個左右的SQL命令,任何人都可以學會其中的20%,並完成80%的工作。但是要想精通,需要經過長期的積累,具備豐富的索引、視圖和優化經驗。"}]},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":"傾聽和調整"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"查詢語言不是一塊永恆的巨石,而是一組隨時間變化的自適應標準。隨着時間的推移,SQL標準一直在不斷調整,並加入了來自用戶的反饋。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"從概念最初提出開始,我們看到了10種不同的SQL標準,它們都有重要的更新。以下是三項比較大的:"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"SQL:1999:添加了正則表達式匹配、遞歸查詢(例如傳遞閉包)、觸發器、對過程語句和流控制語句的支持、非標量類型(數組)和一些面向對象的特性(例如結構化類型)。支持在Java中嵌入SQL(SQL\/OLB),反之亦然(SQL\/JRT)。"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"SQL:2003:引入了與XML相關的特性(SQL\/XML)、窗口函數、標準化序列和自動生成值的列(包括標識列)。"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"SQL:2016:添加行模式匹配、多態表函數、JSON。"}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"SQL語法不是強制性的,它只是提供了一個數據庫標準,每種數據庫都可以創建它們自己的實現(T-SQL、MySQL、PSQL等)。"}]},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":"採用API"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"SQL成功的最後一個祕密是應用程序編程接口(API)的興起。API通過抽象底層實現,只公開開發人員需要的對象或操作,簡化了編程。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"API讓SQL可以使用專門的語法適應新技術的發展。2006年,Hadoop引入分佈式文件系統(HDFS),SQL語法最初是無法訪問該系統的。然後,在2013年,Apache創建了Apache Impala,它允許開發人員使用SQL查詢HDFS數據庫。"}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"小結"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"SQL是當今最普遍的編程語言之一,但我們經常忘記它的歷史有多久了。它的旅程開始於現代計算機的黎明,由2位圖靈獎獲得者賦予了它生命。對於爲什麼SQL能夠保持其主導地位,我已經分享了我的看法:第一性原則、布什內爾定律、調整和API。您認爲促成SQL成功的主要因素是什麼?請給我留言。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"還有一項50年來都沒有改變的技術。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"SQL編輯器"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"隨着越來越多的人學習SQL,數據庫使用越來越需要協作。如今,開發人員可能會與營銷團隊的成員一起分析用戶數據,或者與數據科學家一起調試查詢。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"原文鏈接:"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"https:\/\/blog.arctype.com\/sql-50-years\/"}]}]}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章