A few minor modifications to the paper.
This commit is contained in:
parent
6beccbb96b
commit
d275dc10bd
@ -290,13 +290,23 @@ attribute can be used to speed-up searches.
|
|||||||
cars_by_name = cars.new_index "name", do |car|
|
cars_by_name = cars.new_index "name", do |car|
|
||||||
car.name
|
car.name
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Two other ways to say the same thing, thanks to the Crystal syntax:
|
||||||
|
cars_by_name = cars.new_index "name", { |car| car.name }
|
||||||
|
cars_by_name = cars.new_index "name", &.name
|
||||||
.SOURCE
|
.SOURCE
|
||||||
Once the index has been created, every added or modified entry in the database will be indexed.
|
Once the index has been created, every added or modified entry in the database will be indexed.
|
||||||
Adding an index (basic index, partition or tag) provides an object used to manipulate the database based on this index.
|
Adding an index (basic index, partition or tag) provides an
|
||||||
|
.I object
|
||||||
|
used to manipulate the database based on this index.
|
||||||
Let's call it an
|
Let's call it an
|
||||||
.I "index object" .
|
.I "index object" .
|
||||||
|
In the code above, the
|
||||||
|
.I "index object"
|
||||||
|
is named
|
||||||
|
.I "cars_by_name" .
|
||||||
.QE
|
.QE
|
||||||
.
|
|
||||||
The
|
The
|
||||||
.I "index object"
|
.I "index object"
|
||||||
has several useful functions.
|
has several useful functions.
|
||||||
@ -311,7 +321,6 @@ cars_by_name.update "Corvet", new_car
|
|||||||
|
|
||||||
# In case the index hasn't changed (the name attribute in this example),
|
# In case the index hasn't changed (the name attribute in this example),
|
||||||
# the update can be even simpler.
|
# the update can be even simpler.
|
||||||
new_car = Car.new "Corvet", "green", ["eco-friendly"]
|
|
||||||
cars_by_name.update new_car
|
cars_by_name.update new_car
|
||||||
|
|
||||||
# Delete the car named "Corvet".
|
# Delete the car named "Corvet".
|
||||||
@ -354,6 +363,9 @@ attribute of our cars.
|
|||||||
cars_by_color = database.new_partition "color", do |car|
|
cars_by_color = database.new_partition "color", do |car|
|
||||||
car.color
|
car.color
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Shortcut:
|
||||||
|
cars_by_color = database.new_partition "color", &.color
|
||||||
.SOURCE
|
.SOURCE
|
||||||
.QE
|
.QE
|
||||||
As with basic indexes, once the partition is asked to the database, every new or modified entry will be indexed.
|
As with basic indexes, once the partition is asked to the database, every new or modified entry will be indexed.
|
||||||
@ -396,6 +408,9 @@ Tags are basically partitions but the indexed attribute can have multiple values
|
|||||||
cars_by_keywords = database.new_tags "keywords", do |car|
|
cars_by_keywords = database.new_tags "keywords", do |car|
|
||||||
car.keywords
|
car.keywords
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Shortcut:
|
||||||
|
cars_by_keywords = database.new_tags "keywords", &.keywords
|
||||||
.SOURCE
|
.SOURCE
|
||||||
As with other indexes, once the tag is requested to the database, every new or modified entry will be indexed.
|
As with other indexes, once the tag is requested to the database, every new or modified entry will be indexed.
|
||||||
.QE
|
.QE
|
||||||
@ -464,9 +479,9 @@ A cached database has the same API as the other DODB databases.
|
|||||||
database = DODB::Storage::Cached(Car).new "path/to/db-cars"
|
database = DODB::Storage::Cached(Car).new "path/to/db-cars"
|
||||||
.SOURCE
|
.SOURCE
|
||||||
All operations of the
|
All operations of the
|
||||||
.CLASS DODB::Storage::Basic
|
.CLASS Storage::Basic
|
||||||
class are available for
|
class are available for
|
||||||
.CLASS DODB::Storage::Cached .
|
.CLASS Storage::Cached .
|
||||||
.QE
|
.QE
|
||||||
.
|
.
|
||||||
.SS Cached indexes
|
.SS Cached indexes
|
||||||
@ -844,7 +859,9 @@ In our example, each \f[CW]car\f[] has an unique \fIname\f[] which is used as an
|
|||||||
The following graph represents the result of 100 queries of a car based on its name.
|
The following graph represents the result of 100 queries of a car based on its name.
|
||||||
The experiment starts with a database containing 1,000 cars and goes up to 250,000 cars.
|
The experiment starts with a database containing 1,000 cars and goes up to 250,000 cars.
|
||||||
|
|
||||||
|
.ps -2
|
||||||
.so graph_query_index.grap
|
.so graph_query_index.grap
|
||||||
|
.ps \n[PS]
|
||||||
|
|
||||||
Since there is only one value to retrieve, the request is quick and time is almost constant.
|
Since there is only one value to retrieve, the request is quick and time is almost constant.
|
||||||
When the value and the index are kept in memory (see \f[CW]RAM only\f[] and \f[CW]Cached db\f[]), the retrieval is almost instantaneous (about 50 to 120 ns).
|
When the value and the index are kept in memory (see \f[CW]RAM only\f[] and \f[CW]Cached db\f[]), the retrieval is almost instantaneous (about 50 to 120 ns).
|
||||||
@ -879,11 +896,15 @@ Caching the value enables a massive performance gain, data can be retrieved seve
|
|||||||
.SS Partitions (1 to n relations)
|
.SS Partitions (1 to n relations)
|
||||||
.LP
|
.LP
|
||||||
|
|
||||||
|
.ps -2
|
||||||
.so graph_query_partition.grap
|
.so graph_query_partition.grap
|
||||||
|
.ps \n[PS]
|
||||||
|
|
||||||
.SS Tags (n to n relations)
|
.SS Tags (n to n relations)
|
||||||
.LP
|
.LP
|
||||||
|
.ps -2
|
||||||
.so graph_query_tag.grap
|
.so graph_query_tag.grap
|
||||||
|
.ps \n[PS]
|
||||||
.
|
.
|
||||||
.
|
.
|
||||||
.
|
.
|
||||||
|
Loading…
Reference in New Issue
Block a user