開放原始碼 ch2.4 app - oss - db (ver 1.0)
TRANSCRIPT
1O P E N S O U RC E DATA B A S E
專案管理軟體–管理與實務 (開放原始碼)
– 關聯式資料庫– File-Based DB– NoSQL DB
CH 2
2
關聯式資料庫
• 建立在關係模型基礎上的數據庫,借助於集合代數等數學概念和方法來處理數據庫中的數據。現實世界中的各種實體以及實體之間的各種聯繫均用關係模型來表示。
• 將複雜的現實資料,根據正規化去除重複性內容,並且根據實體與關係建立資料的存儲方式。
• 並且透過關係來還原原始資料呈現。• 結構
• TABLE• VIEW• INDEX
3
關聯式資料庫
• SQL(Structured Query Language) 語言是 1974 年由Boyce 和 Chamberlin 提出的一種介於關係代數與關係演算之間的結構化查詢語言,是一個通用的、功能極強的關係性數據庫語言。
• IBM 公司最早使用在其開發的數據庫系統中。• 1987 年得到國際標準組織的支持下成為國際標準。不過
各種通行的數據庫系統在其實踐過程中都對 SQL 規範作了某些編改和擴充。所以,實際上不同數據庫系統之間的SQL 不能完全相互通用。
4
關聯式資料庫
• SQL 包含 3 個部分:• 「資料定義語言」( DDL : Data Definition Language )• 「資料操縱語言」( DML : Data Manipulation Language )• 「資料控制語言」( DCL : Data Control Language )
• 現行大部分關聯式資料庫皆實作與支援 SQL 。• ANSI SQL89 標準
5
關聯式資料庫
• 開放原始碼選擇• MySQL
• http://www.mysql.com/
• PostgreSQL• http://www.postgresql.org/
• Firebird• http://www.firebirdsql.org/
6
物件關聯式資料庫MYSQL
• Oracle• http://www.mysql.com/
• 社群版 GPL• 非商業用途• 開放原始碼• 主要功能清單 http://www.mysql.com/products/community/
• 商業版• 按授權拷貝與連線計價• 提供進階企業功能
• 企業級備份• 企業級監控器• 查詢分析器
7
物件關聯式資料庫POSTGRESQL
• 開放原始碼• 完全免費不限使用用途• 支援已知各應用平台
Limit Value
Maximum Database Size Unlimited
Maximum Table Size 32 TB
Maximum Row Size 1.6 TB
Maximum Field Size 1 GB
Maximum Rows per Table Unlimited
Maximum Columns per Table 250 - 1600 depending on column types
Maximum Indexes per Table 77
8
物件關聯式資料庫POSTGRESQL
• 支援複本同步抄寫• 支援叢集• 支援格網計算• 完全客製化• 可商業銷售用途• Grid Computing
• Data Grid – 採用 PostgreSQL
9
物件關聯式資料庫FIREBIRD
• http://www.firebirdsql.org• 1981 起正式用在商業應用• 25 July, 2000
• 前身是 Borland 的 Inprise 釋出原始碼成為開放原始碼專案。• Mozilla Public Licence V.1.1 (MPL).• 可商業用途
• 支援• Linux, Windows, and a variety of Unix platforms 。
10
物件關聯式資料庫
• 非 SQL 為基礎的關聯式資料庫• 採用程式語言物件導向作為資料庫的基礎設計• 以物件作為資料的儲存概念• 原因
• 關聯式數據庫在管理複雜數據時顯得笨重• 現行程式語言皆為物件導向,用來轉化數據表示和關係數據庫元組的代碼很
冗繁,執行時也有不少耗時。• 在純物件式資料庫中,資料以物件的形式存儲,這些對象只能由其所屬的類
中定義的方法來操作。• 訪問數據可以更快,表的聯合 (join)常常是不必要的(在關係數據庫的表實
現方式下)。這是因為無需查詢只需通過指針(Pointer)就可以直接獲得對象。
• 對版本的支援。一個對象可以看作是他所有版本的集合。無傳統關聯式的 schema異動問題。
12
物件關聯式資料庫NEO4J
• http://neo4j.org/• Neo4j is a high-performance, NOSQL graph
database with all the features of a mature and robust database.
• 開放原始碼, GPLv3 Community edition• 不同授權差異
• Neo4j Community, a high performance, fully ACID transactional graph database – licensed under the GPL
• Neo4j Advanced, adding advanced monitoring – licensed under the AGPL
• Neo4j Enterprise, adding online backup and High Availability clustering – licensed under AGPL
13
物件關聯式資料庫NEO4J
• graph-oriented model• storing data in the nodes and relationships of a
graph.• 利用資料結構的設計,建立的資料模型。
14
物件關聯式資料庫DB4O
• http://www.db4o.com/• 開放原始碼, Free Version is GPL license• 若要商業用途,建議購買商業授權。• 強力支援 Java 與 .Net 平台。• 真正物件導向關聯式資料庫
15
FILE-BASED DB
• 檔案型資料庫• 優勢
• 無安裝過程• 精簡小巧• 適用於行動裝置• 與應用系統嵌入式整合• 支援關聯式絕大部分功能
• 缺點• 不適用於巨量交易資料運作• 受限作業系統檔案的限制• 效能無法與獨立性伺服器相比
16
FILE-BASED DB
• JavaDB• Oracle
• HyperSQL • http://hsqldb.org/
• H2• http://www.h2database.com/html/main.html
• Apache Derby• http://db.apache.org/derby/
• SQLite• http://www.sqlite.org/
17
FILE-BASED DBJAVADB
• http://www.oracle.com/technetwork/java/javadb/overview/index.html
• Sun Java SDK/JRE 內建• 採用 open source Apache Derby 100% 所開發
• Java DB 10.5.3.0, based on Apache Derby 10.5.3.0
• It is fully transactional, secure, easy-to-use, standards-based SQL, JDBC API, and � Java EE yet �small, only 2.5 MB.
• Free under the Apache license.• Portable and 100% Java, CDC, SQL, and JDBC
compliant.
18
FILE-BASED DBAPACHE DERBY
• http://db.apache.org/derby/• Apache License, Version 2.0• IBM 捐贈• 純 Java 設計開發• 約 2.6MB 大小• 運作模式
• 一般 Clinet – Server• 嵌入式• In-Memory
• 符合 ANSI 89• 不需安裝直接使用
19
FILE-BASED DBHYPERSQL
• http://hsqldb.org/• 100% Java Database• fully multithreaded• full SQL-1992 Advanced Level and SQL:2008 core
language features plus an extensive list of SQL:2008 optional features and many extensions.
• over 6 years• 350K jar size
20
FILE-BASED DBHYPERSQL
• 商業版本• http://www.hxsql.com/• HyperXtremeSQL has been developed in parallel with the
open-source HyperSQL (HSQLDB) engine.
21
FILE-BASED DBH2
• http://www.h2database.com• 運作模式
• Embedded and server modes; in-memory databases
• Small footprint: around 1 MB jar file size• Browser based Console application• 支援全文搜尋
22
FILE-BASED DBH2
H2 Derby HSQLDB MySQL PostgreSQL
Pure Java Yes Yes Yes No No
Memory Mode Yes Yes Yes No No
Encrypted Database
Yes Yes Yes No No
ODBC Driver Yes No No Yes Yes
Fulltext Search Yes No No Yes Yes
Multi Version Concurrency
Yes No Yes Yes Yes
Footprint (jar/dll size)
~1 MB ~2 MB ~1 MB ~4 MB ~6 MB
23
FILE-BASED DBSQLITE
• http://www.sqlite.org/• 採用 C 語言所開發• 被 Android 、 iOS 及其他行動裝置採用作為嵌入式資
料庫。• HTML5 整合性高• 缺點
• 需要原生碼相依性檔案• 因為是原生碼開發,因此效能佳。• 支援 Windows 、 Linux 、 OSX 及 UNIX-like 平台• JAVA 需要額外 JDBC驅動程式
24
NOSQL DB
• NoSQL 也是資料庫管理系統的範疇,在於不採用傳統關聯式架構與 SQL 的標準語句。
• 不是固定的 table schemas ,也沒有所謂的 table schemas 。因此沒有 SQL 中 join 的問題。
• 傳統 RDBMS遵循正規畫設計, NoSQL則是認為資料重複是好事,愈多愈好愈分散更好。
• 因為 RDBMS 在分散式有嚴重的先天架構問題,無法做到延展性,因而無法在雲端環境有效提供滿足的資料儲存需求。
• NoSQL 就是為了分散計算,高度的容錯性。• NoSQL 可以達到水平性橫向規模擴充。
25
NOSQL DB
• 缺點• 無法提供 RDBMS 的嚴格的完整性要求• 因為 NoSQL 是以分散式環境為主,資料是散佈在各地,因此無法保證
資料的完整性。• 無法保證資料的一致性,在交易機制下難以確保資料的一致性。• 沒有提供 SQL 的 join , group by , sum/average , sort
• 必須在應用系統中自行完成。• 難以處理高度複雜性的資料集合, SQL 已經很成熟且最佳化。因此不太適合在 OLAP 的 BI 用途。
• 沒有 SQL 完整的工具來提供匯出與匯入,但是以後會逐漸完善。• 資料儲存速度沒有 SQL 快
• 因為分散式環境• NoSQL 不是為了替代 OLTP 數據庫而生的,它的 key-value 存儲結構
更加適用於處理半結構化的數據。
26
NOSQL DB
• Map/Reduce based• Hadoop/Hbase• Google datastore• MongoDB/Apache CouchDB• Amazon SimpleDB
27
NOSQL DBHADOOP/HBASE
• http://hadoop.apache.org/• Google datastore
• http://code.google.com/intl/zh/appengine/docs/python/datastore/overview.html
• 採用 JPA 與 JDO 標準介面實作• 支援 Java 、 Python 與 Go 語言• 基於 Google 雲端平台
• reliable, scalable, distributed computing.
28
NOSQL DBMONGODB/APACHE COUCHDB
• http://www.mongodb.org/• http://couchdb.apache.org/
29
NOSQL DBMONGODB/APACHE COUCHDB
• Document-oriented storage• 採用 JSON 格式
• 支援全文檢索• 容易副本抄寫機制與快速擴充延展• 無 table schemas• 採用 Map/Reduce 演算法• Enterprise class support, training, and consulting
available.
30
NOSQL DBMONGODB/APACHE COUCHDB
31
NOSQL DBMONGODB/APACHE COUCHDB
MySQL term Mongo term
database database
table collection
index index
row BSON document
column BSON field
join embedding and linking
primary key _id field
32
NOSQL DBMONGODB/APACHE COUCHDB
SQL Statement Mongo Statement
CREATE TABLE USERS (a Number, b Number) implicit; can also be done explicitly withdb.createCollection("mycoll")
ALTER TABLE users ADD ... implicit
INSERT INTO USERS VALUES(3,5) db.users.insert({a:3,b:5})
SELECT a,b FROM users db.users.find({}, {a:1,b:1})
SELECT * FROM users db.users.find()
SELECT * FROM users WHERE age=33 db.users.find({age:33})
33
NOSQL DBAMAZON SIMPLEDB
• http://aws.amazon.com/simpledb/• Amazon SimpleDB is a highly available, flexible,
and scalable non-relational data store that offloads the work of database administration. Developers simply store and query data items via web services requests, and Amazon SimpleDB does the rest.
34
NOSQL DBAMAZON SIMPLEDB
• Use CreateDomain, DeleteDomain, ListDomains, DomainMetadata to create and manage query domains
• Use Put, Batch Put, & Delete to create and manage the data set within each query domain
• 與其他 Amazon服務容易整合• 按需取價
35
NOSQL DBAMAZON SIMPLEDB
• 免費版限制 每個月上限• 25 SimpleDB Machine Hours • 1 GB of Storage for free