Path: | doc/release_notes/4.42.0.txt |
Last Update: | Sat Jun 02 02:04:22 +0000 2018 |
When using ruby 2.4, Sequel uses the new support for clone(:freeze=>false) to actually freeze datasets while allowing them to copy singleton classes/extended modules from the dataset calling clone. On earlier versions of ruby, the dataset opts are now frozen, preventing more types of accidental modification.
The dataset internals were refactored to reduce the number of instance variables. Now, datasets store all of their state in opts. Additionally, all datasets now use a thread-safe cache for storing cached state such as the dataset‘s columns. Previously, accessing/setting the columns was not thread-safe, unless the ruby interpreter used thread-safe methods for instance variable getting/setting.
Frozen datasets use this new cache to optimize repeated method calls, resulting in substantial performance speedups. This can include caching returned and/or intermediate datasets, SELECT and DELETE SQL generated, as well as internal objects designed to optimize the building of SQL strings with different arguments.
Even for fairly simple datasets, this can result in up to 10x performance improvements for dataset methods that don‘t require database access, and up to 3x performance improvements for dataset methods that do require database access.
DB[:foo].for_update.first
To run much faster by avoiding any dataset creation or SQL string building after the first call.
The freeze_datasets extension makes dup an alias of clone, ensuring that all cloned datasets that were originally created by the Database instance are frozen.
It is highly recommended that you start using the freeze_datasets extension in your applications using Sequel, as this extension will become the default and only behavior in Sequel 5. Unfrozen datasets and dataset mutation will not be supported in Sequel 5.
ModelClass.subset1.subset2.subset3.first
class ModelClass < Sequel::Model dataset_module do select :with_id_and_name, :id, :name where :active, :active order :by_name, :name end end ModelClass.active.by_name.with_id_and_name.all # SELECT id, name FROM model_classes WHERE active ORDER BY name # Equivalent to: ModelClass. where(:active). order(:name). select(:id, :name). all
In addition to being easier than defining the methods manually, this also enables caching of the datasets in most cases, so that the above method chain does not create any additional datasets after the first call.
DB[:table].with_extend{def foo; 1 end}.foo => 1
Sequel‘s default remains the same as before, to convert identifiers to uppercase on input and lowercase on output on databases that fold unquoted identifiers to uppercase (per the SQL standard), and to not mangle identifiers at all on databases that fold unquoted identifiers to lowercase (MySQL, PostgreSQL, SQLite). The identifier_mangling extension just allows you to change the default behavior.