com presentations: Final slides for the MongoDB tutorial.: mongo-tut-summercamp14.xml slides/mongodb/excercise05-indexes.xml slides/mongodb/idx-cities-by-name-and-pop2.xml slides/mongodb/idx-cities-by-name-and-pop3.xml slides/mongodb/idx-cities-by-pop-and-dem.xml slides/mongodb/idx-cities-by-pop-and-dem2.xml slides/mongodb/idx-cities-by-pop-and-dem4.xml slides/mongodb/idx-cities-by-pop-and-dem5.xml slides/mongodb/idx-cities-by-pop-and-dem6.xml sl
[email protected] (Derick Rethans)
| Newsgroups | php.pres |
|---|---|
| Message-ID | <[email protected]> |
Commit: 562c8c83161a8986677dde18738be1805e3fc7bb Author: Derick Rethans <[email protected]> Tue, 2 Sep 2014 16:50:16 +0100 Parents: 66295908554b148c04fe0420ceecfbafcaee2c5b Branches: master Link: http://git.php.net/?p=presentations.git;a=commitdiff;h=562c8c83161a8986677dde18738be1805e3fc7bb Log: Final slides for the MongoDB tutorial. Changed paths: M mongo-tut-summercamp14.xml A slides/mongodb/excercise05-indexes.xml M slides/mongodb/idx-cities-by-name-and-pop2.xml M slides/mongodb/idx-cities-by-name-and-pop3.xml M slides/mongodb/idx-cities-by-pop-and-dem.xml M slides/mongodb/idx-cities-by-pop-and-dem2.xml M slides/mongodb/idx-cities-by-pop-and-dem4.xml M slides/mongodb/idx-cities-by-pop-and-dem5.xml M slides/mongodb/idx-cities-by-pop-and-dem6.xml M slides/mongodb/idx-create-php.xml M slides/mongodb/idx-recap3.xml M slides/mongodb/idx-stored2.xml M slides/mongodb/idx-which-one-is-picked.xml
diff_562c8c83161a8986677dde18738be1805e3fc7bb.txt
(text/plain, 12 KB)
diff --git a/mongo-tut-summercamp14.xml b/mongo-tut-summercamp14.xml index c3083cc..ac33513 100644 --- a/mongo-tut-summercamp14.xml +++ b/mongo-tut-summercamp14.xml @@ -6,7 +6,7 @@ <location>Rovinj, Croatia</location> <date>September 5th, 2014</date> <speaker>Derick Rethans</speaker> -<email>[email protected]</email> +<email>[email protected]</email> <twitter>derickr</twitter> <url>http://derickrethans.nl/talks.html</url> <joindin></joindin> @@ -140,6 +140,10 @@ Common Patterns <slide>slides/mongodb/idx-cities-by-name-and-pop.xml</slide> <slide>slides/mongodb/idx-cities-by-name-and-pop2.xml</slide> <slide>slides/mongodb/idx-cities-by-name-and-pop3.xml</slide> + +<slide>slides/mongodb/excercise.xml</slide> +<slide>slides/mongodb/excercise05-indexes.xml</slide> + <slide>slides/mongodb/idx-cities-by-pop-and-dem.xml</slide> <slide>slides/mongodb/idx-cities-by-pop-and-dem2.xml</slide> <slide>slides/mongodb/idx-stored2.xml</slide> diff --git a/slides/mongodb/excercise05-indexes.xml b/slides/mongodb/excercise05-indexes.xml new file mode 100644 index 0000000..580974a --- /dev/null +++ b/slides/mongodb/excercise05-indexes.xml @@ -0,0 +1,13 @@ +<slide> +<title>Excercise: Indexes</title> + +<blurb>A common query is to find the ten highest rated beers ordered by %rating_score% first, and %created_at% second.<br/>Write a script to:</blurb> + +<list> +<bullet>Run the query</bullet> +<bullet>Run the query with explain</bullet> +<bullet>Add the index</bullet> +<bullet>Run the query again with explain</bullet> +<bullet>Delete the index that you've created</bullet> +</list> +</slide> diff --git a/slides/mongodb/idx-cities-by-name-and-pop2.xml b/slides/mongodb/idx-cities-by-name-and-pop2.xml index 51f4ade..4f4887a 100644 --- a/slides/mongodb/idx-cities-by-name-and-pop2.xml +++ b/slides/mongodb/idx-cities-by-name-and-pop2.xml @@ -10,6 +10,8 @@ db.cities.find( { country_code: 'GB', population: { $gte: 500000 } } ).*explain( |00aa00|"nscanned" : 4,| |00aa00|"nscannedObjects" : 4,| |00aa00|"n" : 4,| + "nscannedObjectsAllPlans" : 9, + "nscannedAllPlans" : 10, "millis" : 0, "nYields" : 0, "nChunkSkips" : 0, @@ -17,7 +19,7 @@ db.cities.find( { country_code: 'GB', population: { $gte: 500000 } } ).*explain( "indexOnly" : false, "indexBounds" : { "country_code" : [ [ "GB", "GB" ] ], - "population" : [ [ 500000, 1.7976931348623157e+308 ] ] + "population" : [ [ 500000, Infinity ] ] } } </example> diff --git a/slides/mongodb/idx-cities-by-name-and-pop3.xml b/slides/mongodb/idx-cities-by-name-and-pop3.xml index 6c9404e..f65b11a 100644 --- a/slides/mongodb/idx-cities-by-name-and-pop3.xml +++ b/slides/mongodb/idx-cities-by-name-and-pop3.xml @@ -11,14 +11,14 @@ db.cities.find( { country_code: 'GB', population: { $gte: 500000 } } ) "nscanned" : 4, "nscannedObjects" : 4, "n" : 4, + "nscannedObjectsAllPlans" : 9, + "nscannedAllPlans" : 10, "millis" : 0, - "nYields" : 0, - "nChunkSkips" : 0, "isMultiKey" : false, "indexOnly" : false, "indexBounds" : { "country_code" : [ [ "GB", "GB" ] ], - "population" : [ [ ~*1.7976931348623157e+308, 500000*~ ] ] + "population" : [ [ ~*Infinity, 500000*~ ] ] } } </example> diff --git a/slides/mongodb/idx-cities-by-pop-and-dem.xml b/slides/mongodb/idx-cities-by-pop-and-dem.xml index c8b144a..3b4178c 100644 --- a/slides/mongodb/idx-cities-by-pop-and-dem.xml +++ b/slides/mongodb/idx-cities-by-pop-and-dem.xml @@ -2,7 +2,7 @@ <title>Let's imagine another compound index</title> <table> -<tr><th>Country</th><th>Name</th><th>_Population_</th><th>_DEM_</th></tr> +<tr><th>Country</th><th>Name</th><th>_Population_</th><th>_Elevation_</th></tr> <tr><td>AD</td><td>les Escaldes</td><td>15853</td><td>1033</td></tr> <tr><td>AD</td><td>Andorra la Vella</td><td>20430</td><td>1037</td></tr> <tr><td>...</td><td>...</td><td>...</td><td>...</td></tr> @@ -12,5 +12,5 @@ <tr><td>MX</td><td>Mexico City</td><td>12294193</td><td>2240</td></tr> <tr><td>...</td><td>...</td><td>...</td><td>...</td></tr> </table> -<example>db.cities.ensureIndex( { population: 1, dem: 1 } );</example> +<example>db.cities.ensureIndex( { population: 1, elevation: 1 } );</example> </slide> diff --git a/slides/mongodb/idx-cities-by-pop-and-dem2.xml b/slides/mongodb/idx-cities-by-pop-and-dem2.xml index eb26e97..7bfe140 100644 --- a/slides/mongodb/idx-cities-by-pop-and-dem2.xml +++ b/slides/mongodb/idx-cities-by-pop-and-dem2.xml @@ -2,32 +2,32 @@ <title>Let's look at the query plan</title> <example inline="1"> -db.cities.find( { population: { $gte: 2000000 }, dem: { $gte: 1654 } } ).explain(); +db.cities.find( { population: { $gte: 2000000 }, elevation: { $gte: 1654 } } ).explain(); </example> <example inline="1"> { - "cursor" : "BtreeCursor population_1_dem_1", - |ff8000|"nscanned" : 127,| + "cursor" : "BtreeCursor population_1_elevation_1", + |ff8000|"nscanned" : 131,| |00cc00|"nscannedObjects" : 6,| |00cc00|"n" : 6,| + "nscannedObjectsAllPlans" : 6, + "nscannedAllPlans" : 131, "millis" : 3, - "nYields" : 0, - "nChunkSkips" : 0, "isMultiKey" : false, "indexOnly" : false, "indexBounds" : { - "population" : [ [ 2000000, 1.7976931348623157e+308 ] ], - "dem" : [ [ 1654, 1.7976931348623157e+308 ] ] + "population" : [ [ 2000000, Infinity ] ], + "elevation" : [ [ 1654, Infinity ] ] } } </example> <example> -{ "name" : "Johannesburg", "population" : 2026469, "dem" : 1767 } -{ "name" : "Nairobi", "population" : 2750547, "dem" : 1684 } -{ "name" : "Addis Ababa", "population" : 2757729, "dem" : 2405 } -{ "name" : "Kabul", "population" : 3043532, "dem" : 1798 } -{ "name" : "Bogotá", "population" : 7102602, "dem" : 2582 } -{ "name" : "Mexico City", "population" : 12294193, "dem" : 2240 } +{ "name" : "Johannesburg", "population" : 2026469, "elevation" : 1767 } +{ "name" : "Nairobi", "population" : 2750547, "elevation" : 1684 } +{ "name" : "Addis Ababa", "population" : 2757729, "elevation" : 2405 } +{ "name" : "Kabul", "population" : 3043532, "elevation" : 1798 } +{ "name" : "Bogotá", "population" : 7102602, "elevation" : 2582 } +{ "name" : "Mexico City", "population" : 12294193, "elevation" : 2240 } </example> </slide> diff --git a/slides/mongodb/idx-cities-by-pop-and-dem4.xml b/slides/mongodb/idx-cities-by-pop-and-dem4.xml index 9b9ed23..0d8ada8 100644 --- a/slides/mongodb/idx-cities-by-pop-and-dem4.xml +++ b/slides/mongodb/idx-cities-by-pop-and-dem4.xml @@ -2,12 +2,12 @@ <title>Sorting by descending elevation</title> <example inline="1"> -db.cities.find( { population: { $gte: 2000000 }, dem: { $gte : 1654 } } ) - .sort( { dem: -1 } ).explain(); +db.cities.find( { population: { $gte: 2000000 }, elevation: { $gte : 1654 } } ) + .sort( { elevation: -1 } ).explain(); </example> <example inline="1"> { - "cursor" : "BtreeCursor population_1_dem_1", + "cursor" : "BtreeCursor population_1_elevation_1", "nscanned" : 127, "nscannedObjects" : 6, "n" : 6, @@ -19,7 +19,7 @@ db.cities.find( { population: { $gte: 2000000 }, dem: { $gte : 1654 } } ) <list> <bullet>Batch and sort results in memory</bullet> <bullet>No streaming (with getMore) of results</bullet> - <bullet>32 MB data limit for sorting</bullet> + <bullet>Data limit for sorting</bullet> </list> </slide> diff --git a/slides/mongodb/idx-cities-by-pop-and-dem5.xml b/slides/mongodb/idx-cities-by-pop-and-dem5.xml index 704ee95..23b82bb 100644 --- a/slides/mongodb/idx-cities-by-pop-and-dem5.xml +++ b/slides/mongodb/idx-cities-by-pop-and-dem5.xml @@ -2,13 +2,13 @@ <title>Sorting by descending elevation - take 2</title> <example inline="1"> -db.cities.ensureIndex( { dem: -1 } ); -db.cities.find( { population: { $gte: 2000000 }, dem: { $gte : 1654 } } ) - .sort( { dem: -1 } ).explain(); +db.cities.ensureIndex( { elevation: -1 } ); +db.cities.find( { population: { $gte: 2000000 }, elevation: { $gte : 1654 } } ) + .sort( { elevation: -1 } ).explain(); </example> <example inline="1"> { - *|f10000|"cursor" : "BtreeCursor population_1_dem_1",|* + *|f10000|"cursor" : "BtreeCursor population_1_elevation_1",|* "nscanned" : 127, "nscannedObjects" : 6, "n" : 6, diff --git a/slides/mongodb/idx-cities-by-pop-and-dem6.xml b/slides/mongodb/idx-cities-by-pop-and-dem6.xml index 7130f2d..7f66f93 100644 --- a/slides/mongodb/idx-cities-by-pop-and-dem6.xml +++ b/slides/mongodb/idx-cities-by-pop-and-dem6.xml @@ -1,8 +1,8 @@ <slide> -<title>Querying by just the DEM</title> +<title>Querying by just the elevation</title> <example inline="1"> -db.cities.find( { dem: { $gte : 1654 } } ).explain(); +db.cities.find( { elevation: { $gte : 1654 } } ).explain(); </example> <example inline="1"> { diff --git a/slides/mongodb/idx-create-php.xml b/slides/mongodb/idx-create-php.xml index e7ca249..da02b0f 100644 --- a/slides/mongodb/idx-create-php.xml +++ b/slides/mongodb/idx-create-php.xml @@ -6,16 +6,17 @@ <example><![CDATA[ <?php $m = new MongoClient; -$c = $m->demo->cities; +$c = $m->tutorial->beer; -// Create an index on the name attribute -$c->ensureIndex( array( 'name' => 1 ) ); +// Create an index on the beer name attribute +$c->ensureIndex( [ 'beer_name' => 1 ] ); -// Create a compound index on country code and feature code -$c->ensureIndex( array( 'country_code' => 1, 'feature_code' => 1 ) ); +// Create a compound index on beer name and brewery name +$c->ensureIndex( [ 'beer_name' => 1, 'brewery_name' => 1 ] ); -// Create a unique index on the area field of timezone: -$c->ensureIndex( array( 'timezone.area' => 1 ) ); +// Create a unique index on the name field of the venue attribute +$c->ensureIndex( [ 'venue.name' => 1 ] ); +?> ]]> </example> </slide> diff --git a/slides/mongodb/idx-recap3.xml b/slides/mongodb/idx-recap3.xml index 9a6fc9c..2b5ef7e 100644 --- a/slides/mongodb/idx-recap3.xml +++ b/slides/mongodb/idx-recap3.xml @@ -5,7 +5,7 @@ <bullet>Many sorts of negations (%$ne%, %$not%, %$nin%).</bullet> <bullet>Tricky aritmethic (%$mod%).</bullet> <bullet>Most regular expressions (%/ondo/%), unless anchored to the start of the string (%/^Lon/%).</bullet> - <bullet>JavaScript expressions in %$where% clauses, such as %where dem > population%. In that case, try to pre-compute.</bullet> + <bullet>JavaScript expressions in %$where% clauses, such as %where elevation > population%. In that case, try to pre-compute.</bullet> <bullet>map/reduce</bullet> </list> </slide> diff --git a/slides/mongodb/idx-stored2.xml b/slides/mongodb/idx-stored2.xml index 0e9fe79..22bcada 100644 --- a/slides/mongodb/idx-stored2.xml +++ b/slides/mongodb/idx-stored2.xml @@ -1,7 +1,7 @@ <slide> -<title>Let's have a quick look on how index look-ups work</title> +<title>A quick look on how index look-ups work</title> -<example>db.cities.find( { population: { $gte: 2000000 }, dem: { $gte: 1654 } } );</example> +<example>db.cities.find( { population: { $gte: 2000000 }, elevation: { $gte: 1654 } } );</example> <div effect="fade-out"> <table> diff --git a/slides/mongodb/idx-which-one-is-picked.xml b/slides/mongodb/idx-which-one-is-picked.xml index eac29c7..8e1bafb 100644 --- a/slides/mongodb/idx-which-one-is-picked.xml +++ b/slides/mongodb/idx-which-one-is-picked.xml @@ -3,19 +3,19 @@ <list> <bullet>MongoDB does not keep statistics</bullet> - <bullet>MongoDB just tries all the possible indexes</bullet> + <bullet>MongoDB tries all the possible indexes</bullet> <bullet>When it has found the fastest one, it remembers it</bullet> - <bullet>MongoDB will re-try all possible plans once in a while</bullet> + <bullet>MongoDB will re-try plans once in a while</bullet> <bullet>Indexes can be "hinted": <example> -db.cities.ensureIndex( { population: 1, dem: 1 } ); -db.cities.ensureIndex( { dem: -1 } ); -db.cities.find( { population: { $gte: 2000000 }, dem: { $gte : 1654 } }) - .sort( { dem: -1 } ) - .hint( { dem: -1 } );</example> +db.cities.ensureIndex( { population: 1, elevation: 1 } ); +db.cities.ensureIndex( { elevation: -1 } ); +db.cities.find( { population: { $gte: 2000000 }, elevation: { $gte : 1654 } }) + .sort( { elevation: -1 } ) + .hint( { elevation: -1 } );</example> <example inline="1"> { - *"cursor" : "BtreeCursor dem_-1",* + *"cursor" : "BtreeCursor elevation_-1",* *|ff8000|"nscanned" : 614,|* "nscannedObjects" : 614, "n" : 6,