12. Document-oriented
Documents (objects) map nicely to
programming language data types
Embedded documents and arrays reduce
need for joins
http://www.mongodb.org/display/DOCS/Introduction
13. Document-oriented
Documents (objects) map nicely to
programming language data types
Embedded documents and arrays reduce
need for joins
Dynamically-typed (schemaless) for easy
schema evolution
http://www.mongodb.org/display/DOCS/Introduction
14. Document-oriented
Documents (objects) map nicely to
programming language data types
Embedded documents and arrays reduce
need for joins
Dynamically-typed (schemaless) for easy
schema evolution
No joins and no multi-document
transactions for high performance and
easy scalability
http://www.mongodb.org/display/DOCS/Introduction
16. High performance
http://www.mongodb.org/display/DOCS/Introduction
17. High performance
No joins and embedding makes reads
and writes fast
http://www.mongodb.org/display/DOCS/Introduction
18. High performance
No joins and embedding makes reads
and writes fast
Indexes including indexing of keys from
embedded documents and arrays
http://www.mongodb.org/display/DOCS/Introduction
19. High performance
No joins and embedding makes reads
and writes fast
Indexes including indexing of keys from
embedded documents and arrays
Optional asynchronous writes
http://www.mongodb.org/display/DOCS/Introduction
29. No Join!
> use blog
switched to db blog
> db.post.insert({
title: " 4 Sugamo.vim ..."
,postDate: new Date(2011, 6, 19)
,tag: [" ", "vim"]
,body: "Sugamo.vim 7/19 ..."
})
30. No Join!
> use blog
switched to db blog
> db.post.insert({
title: " 4 Sugamo.vim ..."
It’s embedded!!
,postDate: new Date(2011, 6, 19)
,tag: [" ", "vim"]
,body: "Sugamo.vim 7/19 ..."
})
39. Embedded
Reduce join
Better performance
Join itself (executer)
Query plan (optimizer)
Reduce impedance mismatch between db
and apps
40. Embedded
Reduce join
Better performance
Join itself (executer)
Query plan (optimizer)
Reduce impedance mismatch between db
and apps
Also easy to understand :)
41. Embedded
Reduce join
Better performance
Join itself (executer)
Query plan (optimizer)
Reduce impedance mismatch between db
and apps
Also easy to understand :)
but, still have to consider a lot ...
73. Indexing
blog=# set enable_seqscan = off;
blog=# EXPLAIN SELECT * FROM post WHERE tag @> ARRAY['vim']
QUERY PLAN
---------------------------------------------------------------------------
Bitmap Heap Scan on post (cost=4.26..8.27 rows=1 width=104)
Recheck Cond: (tag @> '{vim}'::text[])
-> Bitmap Index Scan on post_tag_idx (cost=0.00..4.26 rows=1 width=0)
Index Cond: (tag @> '{vim}'::text[])
(4 rows)
75. Inverted Index
Data Index
T0 = "it is what it is", "a": {2}
T1 = "what is it", "banana": {2}
T2 = "it is a banana" "is": {0, 1, 2}
"it": {0, 1, 2}
"what": {0, 1}
http://ja.wikipedia.org/wiki/%E8%BB%A2%E7%BD%AE
%E3%82%A4%E3%83%B3%E3%83%87%E3%83%83%E3%82%AF%E3%82%B9
76. Inverted Index
Data Index
T0 = "it is what it is", "a": {2}
T1 = "what is it", "banana": {2}
T2 = "it is a banana" "is": {0, 1, 2}
"it": {0, 1, 2}
"what": {0, 1}
key
http://ja.wikipedia.org/wiki/%E8%BB%A2%E7%BD%AE
%E3%82%A4%E3%83%B3%E3%83%87%E3%83%83%E3%82%AF%E3%82%B9
77. Inverted Index
Data Index
T0 = "it is what it is", "a": {2}
T1 = "what is it", "banana": {2}
T2 = "it is a banana" "is": {0, 1, 2}
"it": {0, 1, 2}
"what": {0, 1}
posting list
key
/bucket
http://ja.wikipedia.org/wiki/%E8%BB%A2%E7%BD%AE
%E3%82%A4%E3%83%B3%E3%83%87%E3%83%83%E3%82%AF%E3%82%B9
85. Group By
blog=# SELECT tag, count(tag) FROM (
SELECT unnest(tag, ' ') tag FROM post
)t
GROUP BY tag;
tag | count
--------+-------
| 1
vim | 1
(2 rows)
89. contrib/hstore
# SELECT ‘a => 1, b => 2’::hstore
"a"=>"1", "b"=>"2"
Type for group of (key => value)
Can be indexed with Gin/GiST
Can’t be nested ....
90. XML Type
<book>
<title> </title>
<author> </author>
<author> </author>
<publisher> </publisher>
</book>
http://lets.postgresql.jp/documents/tutorial/xml/1/
91. XML Type
testdb=# CREATE TABLE t_books(books xml);
testdb=# INSERT INTO t_books(books) VALUES('
testdb'# <book>
testdb'# <title> </title>
testdb'# <author> </author><author> </author>
testdb'# <publisher> </publisher>
testdb'# </book>
testdb'# ');
http://lets.postgresql.jp/documents/tutorial/xml/1/
92. XML Type
testdb=# SELECT
xpath('/book[author/text()=" "/title', books)
FROM
t_books;
xpath
---------------------------------------------
{<title> </title>}
(1 rows)
http://lets.postgresql.jp/documents/tutorial/xml/1/
93. XML Type
Access element with xpath()
Can be indexed with xpath/Functional Index
http://lets.postgresql.jp/documents/tutorial/xml/1/
97. The Scripting Language
of Databases
$m = new Mongo();
$m->test->formResults->insert($_POST);
print_r($m->test->formResults->findOne());
http://www.snailinaturtleneck.com/blog/2011/04/06/the-scripting-language-of-databases/