Nativepluck
Nativepluck is a high-performance alternative to ActiveRecord's pluck when using PostgreSQL.
Via native PostgreSQL data type casting, we achieve significant memory and time savings.
Installation
Add this line to your application's Gemfile:
gem 'nativepluck'
And then execute:
$ bundle
Or install it yourself as:
$ gem install nativepluck
Usage
If you want to use
nativepluckas anActiveRecordmethod, addinclude Nativepluckinside your model.
In this usage mode (more examples intest/dummy/test/models/genericmodel_test.rb):<Model>.nativepluck(:id, order: {id: :asc} , limit: limit)
Internally, the method call will generate a SQL query based on your arguments and use native PostgreSQL typecasting on the query results.If you have more complex queries that the above mixin method doesn't currently support (such as
joins):
You can take an existing ActiveRecord query method call chain, for example:
<Model>.where('id >= 21').limit(100).joins(:some_association_to_another_model).pluck(:id)
Change thepluckcall toselectand use it as the argument to thenativepluckmodule method:Nativepluck.nativepluck(<Model>.where('id >= 21').limit(100).joins(:some_association_to_another_model).select(:id))
Internally, this method callsto_sqlon the suppliedActiveRecord::Relationinstance and submits the generated SQL query to the database. Again, native PostgreSQL typecasting is performed on the query results.You can also use a raw SQL string argument in the module method, e.g.,
Nativepluck.nativepluck('SELECT models.id FROM models JOIN some_other_models ON some_other_models.model_id = models.id WHERE models.id > 21 LIMIT 100').
Memory Benchmarks
To run the benchmarks use:
BenchMarks::Memory::benchmark(write_to_file: true|false, row_limit: nil|integer)
Memory allocation benchmark
| Method | Attribute Name | Total Allocated | Total Retained |
|---|---|---|---|
| pluck | id | 5125 | 3 |
| nativepluck | id | 20 | 1 |
| nativepluck_raw_to_sql | id | 68 | 5 |
| nativepluck_raw_string | id | 7 | 1 |
| pluck | integer_col | 5125 | 3 |
| nativepluck | integer_col | 20 | 1 |
| nativepluck_raw_to_sql | integer_col | 68 | 5 |
| nativepluck_raw_string | integer_col | 7 | 1 |
| pluck | string_col | 7125 | 1003 |
| nativepluck | string_col | 1020 | 1001 |
| nativepluck_raw_to_sql | string_col | 1068 | 1005 |
| nativepluck_raw_string | string_col | 1007 | 1001 |
| pluck | datetime_col | 22125 | 2003 |
| nativepluck | datetime_col | 1020 | 1001 |
| nativepluck_raw_to_sql | datetime_col | 1068 | 1005 |
| nativepluck_raw_string | datetime_col | 1007 | 1001 |
| pluck | float_col | 5125 | 3 |
| nativepluck | float_col | 20 | 1 |
| nativepluck_raw_to_sql | float_col | 68 | 5 |
| nativepluck_raw_string | float_col | 7 | 1 |
| pluck | json_col | 16125 | 3003 |
| nativepluck | json_col | 11020 | 3001 |
| nativepluck_raw_to_sql | json_col | 11068 | 3005 |
| nativepluck_raw_string | json_col | 11007 | 3001 |
| pluck | jsonb_col | 16125 | 3003 |
| nativepluck | jsonb_col | 11020 | 3001 |
| nativepluck_raw_to_sql | jsonb_col | 11068 | 3005 |
| nativepluck_raw_string | jsonb_col | 11007 | 3001 |
| pluck | created_at | 22125 | 2003 |
| nativepluck | created_at | 1020 | 1001 |
| nativepluck_raw_to_sql | created_at | 1068 | 1005 |
| nativepluck_raw_string | created_at | 1007 | 1001 |
| pluck | updated_at | 22125 | 2003 |
| nativepluck | updated_at | 1020 | 1001 |
| nativepluck_raw_to_sql | updated_at | 1068 | 1005 |
| nativepluck_raw_string | updated_at | 1007 | 1001 |
Allocated Memory by Class Benchmark
| Class | Attribute Name | pluck | nativepluck | nativepluck_raw_to_sql | nativepluck_raw_string |
|---|---|---|---|---|---|
| Array | id | 218568 | 8280 | 9680 | 8200 |
| Array | integer_col | 218568 | 8280 | 9680 | 8200 |
| Array | string_col | 218568 | 8280 | 9680 | 8200 |
| Array | datetime_col | 298568 | 8280 | 9680 | 8200 |
| Array | float_col | 218568 | 8280 | 9680 | 8200 |
| Array | json_col | 218568 | 8280 | 9680 | 8200 |
| Array | jsonb_col | 218568 | 8280 | 9680 | 8200 |
| Array | created_at | 298568 | 8280 | 9680 | 8200 |
| Array | updated_at | 298568 | 8280 | 9680 | 8200 |
| PG::Result | id | 30976 | 30976 | 30976 | 30976 |
| PG::Result | integer_col | 30976 | 30976 | 30976 | 30976 |
| PG::Result | string_col | 39168 | 39168 | 39168 | 39168 |
| PG::Result | datetime_col | 51456 | 51456 | 51456 | 51456 |
| PG::Result | float_col | 43264 | 43264 | 43264 | 43264 |
| PG::Result | json_col | 131328 | 131328 | 131328 | 131328 |
| PG::Result | jsonb_col | 139520 | 139520 | 139520 | 139520 |
| PG::Result | created_at | 51456 | 51456 | 51456 | 51456 |
| PG::Result | updated_at | 51456 | 51456 | 51456 | 51456 |
| String | id | 2258 | 576 | 256 | 0 |
| String | integer_col | 2306 | 576 | 304 | 0 |
| String | string_col | 82306 | 40576 | 40304 | 40000 |
| String | datetime_col | 389175 | 576 | 304 | 0 |
| String | float_col | 2306 | 576 | 304 | 0 |
| String | json_col | 418356 | 416626 | 416354 | 416050 |
| String | jsonb_col | 425356 | 423626 | 423354 | 423050 |
| String | created_at | 387306 | 576 | 304 | 0 |
| String | updated_at | 387306 | 576 | 304 | 0 |
| Hash | id | 1696 | 576 | 544 | 0 |
| Hash | integer_col | 1696 | 576 | 544 | 0 |
| Hash | string_col | 1696 | 576 | 544 | 0 |
| Hash | datetime_col | 1696 | 576 | 544 | 0 |
| Hash | float_col | 1696 | 576 | 544 | 0 |
| Hash | json_col | 577696 | 576576 | 576544 | 576000 |
| Hash | jsonb_col | 577696 | 576576 | 576544 | 576000 |
| Hash | created_at | 1696 | 576 | 544 | 0 |
| Hash | updated_at | 1696 | 576 | 544 | 0 |
| ActiveRecord::Relation | id | 352 | 0 | 352 | 0 |
| ActiveRecord::Relation | integer_col | 352 | 0 | 352 | 0 |
| ActiveRecord::Relation | string_col | 352 | 0 | 352 | 0 |
| ActiveRecord::Relation | datetime_col | 352 | 0 | 352 | 0 |
| ActiveRecord::Relation | float_col | 352 | 0 | 352 | 0 |
| ActiveRecord::Relation | json_col | 352 | 0 | 352 | 0 |
| ActiveRecord::Relation | jsonb_col | 352 | 0 | 352 | 0 |
| ActiveRecord::Relation | created_at | 352 | 0 | 352 | 0 |
| ActiveRecord::Relation | updated_at | 352 | 0 | 352 | 0 |
| MatchData | id | 280 | 0 | 0 | 0 |
| MatchData | integer_col | 280 | 0 | 0 | 0 |
| MatchData | string_col | 280 | 0 | 0 | 0 |
| MatchData | datetime_col | 280280 | 0 | 0 | 0 |
| MatchData | float_col | 280 | 0 | 0 | 0 |
| MatchData | json_col | 280 | 0 | 0 | 0 |
| MatchData | jsonb_col | 280 | 0 | 0 | 0 |
| MatchData | created_at | 280280 | 0 | 0 | 0 |
| MatchData | updated_at | 280280 | 0 | 0 | 0 |
| Time | id | 258 | 0 | 0 | 0 |
| Time | integer_col | 258 | 0 | 0 | 0 |
| Time | string_col | 258 | 0 | 0 | 0 |
| Time | datetime_col | 244258 | 86000 | 86000 | 86000 |
| Time | float_col | 258 | 0 | 0 | 0 |
| Time | json_col | 258 | 0 | 0 | 0 |
| Time | jsonb_col | 258 | 0 | 0 | 0 |
| Time | created_at | 244258 | 86000 | 86000 | 86000 |
| Time | updated_at | 244258 | 86000 | 86000 | 86000 |
| Arel::Nodes::SelectCore | id | 104 | 0 | 104 | 0 |
| Arel::Nodes::SelectCore | integer_col | 104 | 0 | 104 | 0 |
| Arel::Nodes::SelectCore | string_col | 104 | 0 | 104 | 0 |
| Arel::Nodes::SelectCore | datetime_col | 104 | 0 | 104 | 0 |
| Arel::Nodes::SelectCore | float_col | 104 | 0 | 104 | 0 |
| Arel::Nodes::SelectCore | json_col | 104 | 0 | 104 | 0 |
| Arel::Nodes::SelectCore | jsonb_col | 104 | 0 | 104 | 0 |
| Arel::Nodes::SelectCore | created_at | 104 | 0 | 104 | 0 |
| Arel::Nodes::SelectCore | updated_at | 104 | 0 | 104 | 0 |
| ActiveSupport::Notifications::Event | id | 96 | 0 | 0 | 0 |
| ActiveSupport::Notifications::Event | integer_col | 96 | 0 | 0 | 0 |
| ActiveSupport::Notifications::Event | string_col | 96 | 0 | 0 | 0 |
| ActiveSupport::Notifications::Event | datetime_col | 96 | 0 | 0 | 0 |
| ActiveSupport::Notifications::Event | float_col | 96 | 0 | 0 | 0 |
| ActiveSupport::Notifications::Event | json_col | 96 | 0 | 0 | 0 |
| ActiveSupport::Notifications::Event | jsonb_col | 96 | 0 | 0 | 0 |
| ActiveSupport::Notifications::Event | created_at | 96 | 0 | 0 | 0 |
| ActiveSupport::Notifications::Event | updated_at | 96 | 0 | 0 | 0 |
| Arel::Nodes::SelectStatement | id | 88 | 0 | 88 | 0 |
| Arel::Nodes::SelectStatement | integer_col | 88 | 0 | 88 | 0 |
| Arel::Nodes::SelectStatement | string_col | 88 | 0 | 88 | 0 |
| Arel::Nodes::SelectStatement | datetime_col | 88 | 0 | 88 | 0 |
| Arel::Nodes::SelectStatement | float_col | 88 | 0 | 88 | 0 |
| Arel::Nodes::SelectStatement | json_col | 88 | 0 | 88 | 0 |
| Arel::Nodes::SelectStatement | jsonb_col | 88 | 0 | 88 | 0 |
| Arel::Nodes::SelectStatement | created_at | 88 | 0 | 88 | 0 |
| Arel::Nodes::SelectStatement | updated_at | 88 | 0 | 88 | 0 |
| ActiveModel::Attribute::WithCastValue | id | 80 | 0 | 80 | 0 |
| ActiveModel::Attribute::WithCastValue | integer_col | 80 | 0 | 80 | 0 |
| ActiveModel::Attribute::WithCastValue | string_col | 80 | 0 | 80 | 0 |
| ActiveModel::Attribute::WithCastValue | datetime_col | 80 | 0 | 80 | 0 |
| ActiveModel::Attribute::WithCastValue | float_col | 80 | 0 | 80 | 0 |
| ActiveModel::Attribute::WithCastValue | json_col | 80 | 0 | 80 | 0 |
| ActiveModel::Attribute::WithCastValue | jsonb_col | 80 | 0 | 80 | 0 |
| ActiveModel::Attribute::WithCastValue | created_at | 80 | 0 | 80 | 0 |
| ActiveModel::Attribute::WithCastValue | updated_at | 80 | 0 | 80 | 0 |
| ActiveRecord::Result | id | 72 | 0 | 0 | 0 |
| ActiveRecord::Result | integer_col | 72 | 0 | 0 | 0 |
| ActiveRecord::Result | string_col | 72 | 0 | 0 | 0 |
| ActiveRecord::Result | datetime_col | 72 | 0 | 0 | 0 |
| ActiveRecord::Result | float_col | 72 | 0 | 0 | 0 |
| ActiveRecord::Result | json_col | 72 | 0 | 0 | 0 |
| ActiveRecord::Result | jsonb_col | 72 | 0 | 0 | 0 |
| ActiveRecord::Result | created_at | 72 | 0 | 0 | 0 |
| ActiveRecord::Result | updated_at | 72 | 0 | 0 | 0 |
| Arel::Attributes::Attribute | id | 40 | 0 | 40 | 0 |
| Arel::Attributes::Attribute | integer_col | 40 | 0 | 40 | 0 |
| Arel::Attributes::Attribute | string_col | 40 | 0 | 40 | 0 |
| Arel::Attributes::Attribute | datetime_col | 40 | 0 | 40 | 0 |
| Arel::Attributes::Attribute | float_col | 40 | 0 | 40 | 0 |
| Arel::Attributes::Attribute | json_col | 40 | 0 | 40 | 0 |
| Arel::Attributes::Attribute | jsonb_col | 40 | 0 | 40 | 0 |
| Arel::Attributes::Attribute | created_at | 40 | 0 | 40 | 0 |
| Arel::Attributes::Attribute | updated_at | 40 | 0 | 40 | 0 |
| Arel::Collectors::Bind | id | 40 | 0 | 0 | 0 |
| Arel::Collectors::Bind | integer_col | 40 | 0 | 0 | 0 |
| Arel::Collectors::Bind | string_col | 40 | 0 | 0 | 0 |
| Arel::Collectors::Bind | datetime_col | 40 | 0 | 0 | 0 |
| Arel::Collectors::Bind | float_col | 40 | 0 | 0 | 0 |
| Arel::Collectors::Bind | json_col | 40 | 0 | 0 | 0 |
| Arel::Collectors::Bind | jsonb_col | 40 | 0 | 0 | 0 |
| Arel::Collectors::Bind | created_at | 40 | 0 | 0 | 0 |
| Arel::Collectors::Bind | updated_at | 40 | 0 | 0 | 0 |
| Arel::Collectors::Composite | id | 40 | 0 | 0 | 0 |
| Arel::Collectors::Composite | integer_col | 40 | 0 | 0 | 0 |
| Arel::Collectors::Composite | string_col | 40 | 0 | 0 | 0 |
| Arel::Collectors::Composite | datetime_col | 40 | 0 | 0 | 0 |
| Arel::Collectors::Composite | float_col | 40 | 0 | 0 | 0 |
| Arel::Collectors::Composite | json_col | 40 | 0 | 0 | 0 |
| Arel::Collectors::Composite | jsonb_col | 40 | 0 | 0 | 0 |
| Arel::Collectors::Composite | created_at | 40 | 0 | 0 | 0 |
| Arel::Collectors::Composite | updated_at | 40 | 0 | 0 | 0 |
| Arel::Collectors::SQLString | id | 40 | 0 | 40 | 0 |
| Arel::Collectors::SQLString | integer_col | 40 | 0 | 40 | 0 |
| Arel::Collectors::SQLString | string_col | 40 | 0 | 40 | 0 |
| Arel::Collectors::SQLString | datetime_col | 40 | 0 | 40 | 0 |
| Arel::Collectors::SQLString | float_col | 40 | 0 | 40 | 0 |
| Arel::Collectors::SQLString | json_col | 40 | 0 | 40 | 0 |
| Arel::Collectors::SQLString | jsonb_col | 40 | 0 | 40 | 0 |
| Arel::Collectors::SQLString | created_at | 40 | 0 | 40 | 0 |
| Arel::Collectors::SQLString | updated_at | 40 | 0 | 40 | 0 |
| Arel::Nodes::BindParam | id | 40 | 0 | 40 | 0 |
| Arel::Nodes::BindParam | integer_col | 40 | 0 | 40 | 0 |
| Arel::Nodes::BindParam | string_col | 40 | 0 | 40 | 0 |
| Arel::Nodes::BindParam | datetime_col | 40 | 0 | 40 | 0 |
| Arel::Nodes::BindParam | float_col | 40 | 0 | 40 | 0 |
| Arel::Nodes::BindParam | json_col | 40 | 0 | 40 | 0 |
| Arel::Nodes::BindParam | jsonb_col | 40 | 0 | 40 | 0 |
| Arel::Nodes::BindParam | created_at | 40 | 0 | 40 | 0 |
| Arel::Nodes::BindParam | updated_at | 40 | 0 | 40 | 0 |
| Arel::Nodes::JoinSource | id | 40 | 0 | 40 | 0 |
| Arel::Nodes::JoinSource | integer_col | 40 | 0 | 40 | 0 |
| Arel::Nodes::JoinSource | string_col | 40 | 0 | 40 | 0 |
| Arel::Nodes::JoinSource | datetime_col | 40 | 0 | 40 | 0 |
| Arel::Nodes::JoinSource | float_col | 40 | 0 | 40 | 0 |
| Arel::Nodes::JoinSource | json_col | 40 | 0 | 40 | 0 |
| Arel::Nodes::JoinSource | jsonb_col | 40 | 0 | 40 | 0 |
| Arel::Nodes::JoinSource | created_at | 40 | 0 | 40 | 0 |
| Arel::Nodes::JoinSource | updated_at | 40 | 0 | 40 | 0 |
| Arel::Nodes::Limit | id | 40 | 0 | 40 | 0 |
| Arel::Nodes::Limit | integer_col | 40 | 0 | 40 | 0 |
| Arel::Nodes::Limit | string_col | 40 | 0 | 40 | 0 |
| Arel::Nodes::Limit | datetime_col | 40 | 0 | 40 | 0 |
| Arel::Nodes::Limit | float_col | 40 | 0 | 40 | 0 |
| Arel::Nodes::Limit | json_col | 40 | 0 | 40 | 0 |
| Arel::Nodes::Limit | jsonb_col | 40 | 0 | 40 | 0 |
| Arel::Nodes::Limit | created_at | 40 | 0 | 40 | 0 |
| Arel::Nodes::Limit | updated_at | 40 | 0 | 40 | 0 |
| Arel::Nodes::Top | id | 40 | 0 | 40 | 0 |
| Arel::Nodes::Top | integer_col | 40 | 0 | 40 | 0 |
| Arel::Nodes::Top | string_col | 40 | 0 | 40 | 0 |
| Arel::Nodes::Top | datetime_col | 40 | 0 | 40 | 0 |
| Arel::Nodes::Top | float_col | 40 | 0 | 40 | 0 |
| Arel::Nodes::Top | json_col | 40 | 0 | 40 | 0 |
| Arel::Nodes::Top | jsonb_col | 40 | 0 | 40 | 0 |
| Arel::Nodes::Top | created_at | 40 | 0 | 40 | 0 |
| Arel::Nodes::Top | updated_at | 40 | 0 | 40 | 0 |
| Arel::SelectManager | id | 40 | 0 | 40 | 0 |
| Arel::SelectManager | integer_col | 40 | 0 | 40 | 0 |
| Arel::SelectManager | string_col | 40 | 0 | 40 | 0 |
| Arel::SelectManager | datetime_col | 40 | 0 | 40 | 0 |
| Arel::SelectManager | float_col | 40 | 0 | 40 | 0 |
| Arel::SelectManager | json_col | 40 | 0 | 40 | 0 |
| Arel::SelectManager | jsonb_col | 40 | 0 | 40 | 0 |
| Arel::SelectManager | created_at | 40 | 0 | 40 | 0 |
| Arel::SelectManager | updated_at | 40 | 0 | 40 | 0 |
| PG::TypeMapByColumn | id | 40 | 40 | 40 | 40 |
| PG::TypeMapByColumn | integer_col | 40 | 40 | 40 | 40 |
| PG::TypeMapByColumn | string_col | 40 | 40 | 40 | 40 |
| PG::TypeMapByColumn | datetime_col | 40 | 40 | 40 | 40 |
| PG::TypeMapByColumn | float_col | 40 | 40 | 40 | 40 |
| PG::TypeMapByColumn | json_col | 40 | 40 | 40 | 40 |
| PG::TypeMapByColumn | jsonb_col | 40 | 40 | 40 | 40 |
| PG::TypeMapByColumn | created_at | 40 | 40 | 40 | 40 |
| PG::TypeMapByColumn | updated_at | 40 | 40 | 40 | 40 |
| Rational | datetime_col | 80000 | 0 | 0 | 0 |
| Rational | created_at | 80000 | 0 | 0 | 0 |
| Rational | updated_at | 80000 | 0 | 0 | 0 |
| JSON::Ext::Parser | json_col | 1168000 | 1168000 | 1168000 | 1168000 |
| JSON::Ext::Parser | jsonb_col | 1168000 | 1168000 | 1168000 | 1168000 |
| Arel::Collectors::SubstituteBinds | id | 0 | 0 | 40 | 0 |
| Arel::Collectors::SubstituteBinds | integer_col | 0 | 0 | 40 | 0 |
| Arel::Collectors::SubstituteBinds | string_col | 0 | 0 | 40 | 0 |
| Arel::Collectors::SubstituteBinds | datetime_col | 0 | 0 | 40 | 0 |
| Arel::Collectors::SubstituteBinds | float_col | 0 | 0 | 40 | 0 |
| Arel::Collectors::SubstituteBinds | json_col | 0 | 0 | 40 | 0 |
| Arel::Collectors::SubstituteBinds | jsonb_col | 0 | 0 | 40 | 0 |
| Arel::Collectors::SubstituteBinds | created_at | 0 | 0 | 40 | 0 |
| Arel::Collectors::SubstituteBinds | updated_at | 0 | 0 | 40 | 0 |
Allocated Objects by Class Benchmark
| Class | Attribute Name | pluck | nativepluck | nativepluck_raw_to_sql | nativepluck_raw_string |
|---|---|---|---|---|---|
| Array | id | 5063 | 7 | 42 | 5 |
| Array | integer_col | 5063 | 7 | 42 | 5 |
| Array | string_col | 5063 | 7 | 42 | 5 |
| Array | datetime_col | 7063 | 7 | 42 | 5 |
| Array | float_col | 5063 | 7 | 42 | 5 |
| Array | json_col | 5063 | 7 | 42 | 5 |
| Array | jsonb_col | 5063 | 7 | 42 | 5 |
| Array | created_at | 7063 | 7 | 42 | 5 |
| Array | updated_at | 7063 | 7 | 42 | 5 |
| String | id | 28 | 8 | 4 | 0 |
| String | integer_col | 28 | 8 | 4 | 0 |
| String | string_col | 2028 | 1008 | 1004 | 1000 |
| String | datetime_col | 9028 | 8 | 4 | 0 |
| String | float_col | 28 | 8 | 4 | 0 |
| String | json_col | 7028 | 7008 | 7004 | 7000 |
| String | jsonb_col | 7028 | 7008 | 7004 | 7000 |
| String | created_at | 9028 | 8 | 4 | 0 |
| String | updated_at | 9028 | 8 | 4 | 0 |
| Hash | id | 11 | 3 | 6 | 0 |
| Hash | integer_col | 11 | 3 | 6 | 0 |
| Hash | string_col | 11 | 3 | 6 | 0 |
| Hash | datetime_col | 11 | 3 | 6 | 0 |
| Hash | float_col | 11 | 3 | 6 | 0 |
| Hash | json_col | 3011 | 3003 | 3006 | 3000 |
| Hash | jsonb_col | 3011 | 3003 | 3006 | 3000 |
| Hash | created_at | 11 | 3 | 6 | 0 |
| Hash | updated_at | 11 | 3 | 6 | 0 |
| ActiveRecord::Relation | id | 3 | 0 | 3 | 0 |
| ActiveRecord::Relation | integer_col | 3 | 0 | 3 | 0 |
| ActiveRecord::Relation | string_col | 3 | 0 | 3 | 0 |
| ActiveRecord::Relation | datetime_col | 3 | 0 | 3 | 0 |
| ActiveRecord::Relation | float_col | 3 | 0 | 3 | 0 |
| ActiveRecord::Relation | json_col | 3 | 0 | 3 | 0 |
| ActiveRecord::Relation | jsonb_col | 3 | 0 | 3 | 0 |
| ActiveRecord::Relation | created_at | 3 | 0 | 3 | 0 |
| ActiveRecord::Relation | updated_at | 3 | 0 | 3 | 0 |
| Time | id | 3 | 0 | 0 | 0 |
| Time | integer_col | 3 | 0 | 0 | 0 |
| Time | string_col | 3 | 0 | 0 | 0 |
| Time | datetime_col | 3003 | 1000 | 1000 | 1000 |
| Time | float_col | 3 | 0 | 0 | 0 |
| Time | json_col | 3 | 0 | 0 | 0 |
| Time | jsonb_col | 3 | 0 | 0 | 0 |
| Time | created_at | 3003 | 1000 | 1000 | 1000 |
| Time | updated_at | 3003 | 1000 | 1000 | 1000 |
| ActiveModel::Attribute::WithCastValue | id | 1 | 0 | 1 | 0 |
| ActiveModel::Attribute::WithCastValue | integer_col | 1 | 0 | 1 | 0 |
| ActiveModel::Attribute::WithCastValue | string_col | 1 | 0 | 1 | 0 |
| ActiveModel::Attribute::WithCastValue | datetime_col | 1 | 0 | 1 | 0 |
| ActiveModel::Attribute::WithCastValue | float_col | 1 | 0 | 1 | 0 |
| ActiveModel::Attribute::WithCastValue | json_col | 1 | 0 | 1 | 0 |
| ActiveModel::Attribute::WithCastValue | jsonb_col | 1 | 0 | 1 | 0 |
| ActiveModel::Attribute::WithCastValue | created_at | 1 | 0 | 1 | 0 |
| ActiveModel::Attribute::WithCastValue | updated_at | 1 | 0 | 1 | 0 |
| ActiveRecord::Result | id | 1 | 0 | 0 | 0 |
| ActiveRecord::Result | integer_col | 1 | 0 | 0 | 0 |
| ActiveRecord::Result | string_col | 1 | 0 | 0 | 0 |
| ActiveRecord::Result | datetime_col | 1 | 0 | 0 | 0 |
| ActiveRecord::Result | float_col | 1 | 0 | 0 | 0 |
| ActiveRecord::Result | json_col | 1 | 0 | 0 | 0 |
| ActiveRecord::Result | jsonb_col | 1 | 0 | 0 | 0 |
| ActiveRecord::Result | created_at | 1 | 0 | 0 | 0 |
| ActiveRecord::Result | updated_at | 1 | 0 | 0 | 0 |
| ActiveSupport::Notifications::Event | id | 1 | 0 | 0 | 0 |
| ActiveSupport::Notifications::Event | integer_col | 1 | 0 | 0 | 0 |
| ActiveSupport::Notifications::Event | string_col | 1 | 0 | 0 | 0 |
| ActiveSupport::Notifications::Event | datetime_col | 1 | 0 | 0 | 0 |
| ActiveSupport::Notifications::Event | float_col | 1 | 0 | 0 | 0 |
| ActiveSupport::Notifications::Event | json_col | 1 | 0 | 0 | 0 |
| ActiveSupport::Notifications::Event | jsonb_col | 1 | 0 | 0 | 0 |
| ActiveSupport::Notifications::Event | created_at | 1 | 0 | 0 | 0 |
| ActiveSupport::Notifications::Event | updated_at | 1 | 0 | 0 | 0 |
| Arel::Attributes::Attribute | id | 1 | 0 | 1 | 0 |
| Arel::Attributes::Attribute | integer_col | 1 | 0 | 1 | 0 |
| Arel::Attributes::Attribute | string_col | 1 | 0 | 1 | 0 |
| Arel::Attributes::Attribute | datetime_col | 1 | 0 | 1 | 0 |
| Arel::Attributes::Attribute | float_col | 1 | 0 | 1 | 0 |
| Arel::Attributes::Attribute | json_col | 1 | 0 | 1 | 0 |
| Arel::Attributes::Attribute | jsonb_col | 1 | 0 | 1 | 0 |
| Arel::Attributes::Attribute | created_at | 1 | 0 | 1 | 0 |
| Arel::Attributes::Attribute | updated_at | 1 | 0 | 1 | 0 |
| Arel::Collectors::Bind | id | 1 | 0 | 0 | 0 |
| Arel::Collectors::Bind | integer_col | 1 | 0 | 0 | 0 |
| Arel::Collectors::Bind | string_col | 1 | 0 | 0 | 0 |
| Arel::Collectors::Bind | datetime_col | 1 | 0 | 0 | 0 |
| Arel::Collectors::Bind | float_col | 1 | 0 | 0 | 0 |
| Arel::Collectors::Bind | json_col | 1 | 0 | 0 | 0 |
| Arel::Collectors::Bind | jsonb_col | 1 | 0 | 0 | 0 |
| Arel::Collectors::Bind | created_at | 1 | 0 | 0 | 0 |
| Arel::Collectors::Bind | updated_at | 1 | 0 | 0 | 0 |
| Arel::Collectors::Composite | id | 1 | 0 | 0 | 0 |
| Arel::Collectors::Composite | integer_col | 1 | 0 | 0 | 0 |
| Arel::Collectors::Composite | string_col | 1 | 0 | 0 | 0 |
| Arel::Collectors::Composite | datetime_col | 1 | 0 | 0 | 0 |
| Arel::Collectors::Composite | float_col | 1 | 0 | 0 | 0 |
| Arel::Collectors::Composite | json_col | 1 | 0 | 0 | 0 |
| Arel::Collectors::Composite | jsonb_col | 1 | 0 | 0 | 0 |
| Arel::Collectors::Composite | created_at | 1 | 0 | 0 | 0 |
| Arel::Collectors::Composite | updated_at | 1 | 0 | 0 | 0 |
| Arel::Collectors::SQLString | id | 1 | 0 | 1 | 0 |
| Arel::Collectors::SQLString | integer_col | 1 | 0 | 1 | 0 |
| Arel::Collectors::SQLString | string_col | 1 | 0 | 1 | 0 |
| Arel::Collectors::SQLString | datetime_col | 1 | 0 | 1 | 0 |
| Arel::Collectors::SQLString | float_col | 1 | 0 | 1 | 0 |
| Arel::Collectors::SQLString | json_col | 1 | 0 | 1 | 0 |
| Arel::Collectors::SQLString | jsonb_col | 1 | 0 | 1 | 0 |
| Arel::Collectors::SQLString | created_at | 1 | 0 | 1 | 0 |
| Arel::Collectors::SQLString | updated_at | 1 | 0 | 1 | 0 |
| Arel::Nodes::BindParam | id | 1 | 0 | 1 | 0 |
| Arel::Nodes::BindParam | integer_col | 1 | 0 | 1 | 0 |
| Arel::Nodes::BindParam | string_col | 1 | 0 | 1 | 0 |
| Arel::Nodes::BindParam | datetime_col | 1 | 0 | 1 | 0 |
| Arel::Nodes::BindParam | float_col | 1 | 0 | 1 | 0 |
| Arel::Nodes::BindParam | json_col | 1 | 0 | 1 | 0 |
| Arel::Nodes::BindParam | jsonb_col | 1 | 0 | 1 | 0 |
| Arel::Nodes::BindParam | created_at | 1 | 0 | 1 | 0 |
| Arel::Nodes::BindParam | updated_at | 1 | 0 | 1 | 0 |
| Arel::Nodes::JoinSource | id | 1 | 0 | 1 | 0 |
| Arel::Nodes::JoinSource | integer_col | 1 | 0 | 1 | 0 |
| Arel::Nodes::JoinSource | string_col | 1 | 0 | 1 | 0 |
| Arel::Nodes::JoinSource | datetime_col | 1 | 0 | 1 | 0 |
| Arel::Nodes::JoinSource | float_col | 1 | 0 | 1 | 0 |
| Arel::Nodes::JoinSource | json_col | 1 | 0 | 1 | 0 |
| Arel::Nodes::JoinSource | jsonb_col | 1 | 0 | 1 | 0 |
| Arel::Nodes::JoinSource | created_at | 1 | 0 | 1 | 0 |
| Arel::Nodes::JoinSource | updated_at | 1 | 0 | 1 | 0 |
| Arel::Nodes::Limit | id | 1 | 0 | 1 | 0 |
| Arel::Nodes::Limit | integer_col | 1 | 0 | 1 | 0 |
| Arel::Nodes::Limit | string_col | 1 | 0 | 1 | 0 |
| Arel::Nodes::Limit | datetime_col | 1 | 0 | 1 | 0 |
| Arel::Nodes::Limit | float_col | 1 | 0 | 1 | 0 |
| Arel::Nodes::Limit | json_col | 1 | 0 | 1 | 0 |
| Arel::Nodes::Limit | jsonb_col | 1 | 0 | 1 | 0 |
| Arel::Nodes::Limit | created_at | 1 | 0 | 1 | 0 |
| Arel::Nodes::Limit | updated_at | 1 | 0 | 1 | 0 |
| Arel::Nodes::SelectCore | id | 1 | 0 | 1 | 0 |
| Arel::Nodes::SelectCore | integer_col | 1 | 0 | 1 | 0 |
| Arel::Nodes::SelectCore | string_col | 1 | 0 | 1 | 0 |
| Arel::Nodes::SelectCore | datetime_col | 1 | 0 | 1 | 0 |
| Arel::Nodes::SelectCore | float_col | 1 | 0 | 1 | 0 |
| Arel::Nodes::SelectCore | json_col | 1 | 0 | 1 | 0 |
| Arel::Nodes::SelectCore | jsonb_col | 1 | 0 | 1 | 0 |
| Arel::Nodes::SelectCore | created_at | 1 | 0 | 1 | 0 |
| Arel::Nodes::SelectCore | updated_at | 1 | 0 | 1 | 0 |
| Arel::Nodes::SelectStatement | id | 1 | 0 | 1 | 0 |
| Arel::Nodes::SelectStatement | integer_col | 1 | 0 | 1 | 0 |
| Arel::Nodes::SelectStatement | string_col | 1 | 0 | 1 | 0 |
| Arel::Nodes::SelectStatement | datetime_col | 1 | 0 | 1 | 0 |
| Arel::Nodes::SelectStatement | float_col | 1 | 0 | 1 | 0 |
| Arel::Nodes::SelectStatement | json_col | 1 | 0 | 1 | 0 |
| Arel::Nodes::SelectStatement | jsonb_col | 1 | 0 | 1 | 0 |
| Arel::Nodes::SelectStatement | created_at | 1 | 0 | 1 | 0 |
| Arel::Nodes::SelectStatement | updated_at | 1 | 0 | 1 | 0 |
| Arel::Nodes::Top | id | 1 | 0 | 1 | 0 |
| Arel::Nodes::Top | integer_col | 1 | 0 | 1 | 0 |
| Arel::Nodes::Top | string_col | 1 | 0 | 1 | 0 |
| Arel::Nodes::Top | datetime_col | 1 | 0 | 1 | 0 |
| Arel::Nodes::Top | float_col | 1 | 0 | 1 | 0 |
| Arel::Nodes::Top | json_col | 1 | 0 | 1 | 0 |
| Arel::Nodes::Top | jsonb_col | 1 | 0 | 1 | 0 |
| Arel::Nodes::Top | created_at | 1 | 0 | 1 | 0 |
| Arel::Nodes::Top | updated_at | 1 | 0 | 1 | 0 |
| Arel::SelectManager | id | 1 | 0 | 1 | 0 |
| Arel::SelectManager | integer_col | 1 | 0 | 1 | 0 |
| Arel::SelectManager | string_col | 1 | 0 | 1 | 0 |
| Arel::SelectManager | datetime_col | 1 | 0 | 1 | 0 |
| Arel::SelectManager | float_col | 1 | 0 | 1 | 0 |
| Arel::SelectManager | json_col | 1 | 0 | 1 | 0 |
| Arel::SelectManager | jsonb_col | 1 | 0 | 1 | 0 |
| Arel::SelectManager | created_at | 1 | 0 | 1 | 0 |
| Arel::SelectManager | updated_at | 1 | 0 | 1 | 0 |
| MatchData | id | 1 | 0 | 0 | 0 |
| MatchData | integer_col | 1 | 0 | 0 | 0 |
| MatchData | string_col | 1 | 0 | 0 | 0 |
| MatchData | datetime_col | 1001 | 0 | 0 | 0 |
| MatchData | float_col | 1 | 0 | 0 | 0 |
| MatchData | json_col | 1 | 0 | 0 | 0 |
| MatchData | jsonb_col | 1 | 0 | 0 | 0 |
| MatchData | created_at | 1001 | 0 | 0 | 0 |
| MatchData | updated_at | 1001 | 0 | 0 | 0 |
| PG::Result | id | 1 | 1 | 1 | 1 |
| PG::Result | integer_col | 1 | 1 | 1 | 1 |
| PG::Result | string_col | 1 | 1 | 1 | 1 |
| PG::Result | datetime_col | 1 | 1 | 1 | 1 |
| PG::Result | float_col | 1 | 1 | 1 | 1 |
| PG::Result | json_col | 1 | 1 | 1 | 1 |
| PG::Result | jsonb_col | 1 | 1 | 1 | 1 |
| PG::Result | created_at | 1 | 1 | 1 | 1 |
| PG::Result | updated_at | 1 | 1 | 1 | 1 |
| PG::TypeMapByColumn | id | 1 | 1 | 1 | 1 |
| PG::TypeMapByColumn | integer_col | 1 | 1 | 1 | 1 |
| PG::TypeMapByColumn | string_col | 1 | 1 | 1 | 1 |
| PG::TypeMapByColumn | datetime_col | 1 | 1 | 1 | 1 |
| PG::TypeMapByColumn | float_col | 1 | 1 | 1 | 1 |
| PG::TypeMapByColumn | json_col | 1 | 1 | 1 | 1 |
| PG::TypeMapByColumn | jsonb_col | 1 | 1 | 1 | 1 |
| PG::TypeMapByColumn | created_at | 1 | 1 | 1 | 1 |
| PG::TypeMapByColumn | updated_at | 1 | 1 | 1 | 1 |
| Rational | datetime_col | 2000 | 0 | 0 | 0 |
| Rational | created_at | 2000 | 0 | 0 | 0 |
| Rational | updated_at | 2000 | 0 | 0 | 0 |
| JSON::Ext::Parser | json_col | 1000 | 1000 | 1000 | 1000 |
| JSON::Ext::Parser | jsonb_col | 1000 | 1000 | 1000 | 1000 |
| Arel::Collectors::SubstituteBinds | id | 0 | 0 | 1 | 0 |
| Arel::Collectors::SubstituteBinds | integer_col | 0 | 0 | 1 | 0 |
| Arel::Collectors::SubstituteBinds | string_col | 0 | 0 | 1 | 0 |
| Arel::Collectors::SubstituteBinds | datetime_col | 0 | 0 | 1 | 0 |
| Arel::Collectors::SubstituteBinds | float_col | 0 | 0 | 1 | 0 |
| Arel::Collectors::SubstituteBinds | json_col | 0 | 0 | 1 | 0 |
| Arel::Collectors::SubstituteBinds | jsonb_col | 0 | 0 | 1 | 0 |
| Arel::Collectors::SubstituteBinds | created_at | 0 | 0 | 1 | 0 |
| Arel::Collectors::SubstituteBinds | updated_at | 0 | 0 | 1 | 0 |
RunTime Benchmarks
To run the benchmarks use:
BenchMarks::RunTime::benchmark
| Method | Row Number | Column Name | Results |
|---|---|---|---|
| nativepluck | 1000 | id | 1660.5 i/s |
| nativepluck_raw SQL_RAW | 1000 | id | 1516.2 i/s - same-ish: difference falls within error |
| nativepluck_raw :to_sql | 1000 | id | 1139.7 i/s - same-ish: difference falls within error |
| pluck | 1000 | id | 734.2 i/s - 2.26x slower |
| nativepluck_raw SQL_RAW | 1000 | integer_col | 1515.4 i/s |
| nativepluck | 1000 | integer_col | 1388.6 i/s - same-ish: difference falls within error |
| nativepluck_raw :to_sql | 1000 | integer_col | 1152.5 i/s - same-ish: difference falls within error |
| pluck | 1000 | integer_col | 594.9 i/s - 2.55x slower |
| nativepluck | 1000 | string_col | 1317.6 i/s |
| nativepluck_raw SQL_RAW | 1000 | string_col | 1103.6 i/s - same-ish: difference falls within error |
| nativepluck_raw :to_sql | 1000 | string_col | 980.7 i/s - same-ish: difference falls within error |
| pluck | 1000 | string_col | 454.9 i/s - 2.90x slower |
| nativepluck_raw SQL_RAW | 1000 | datetime_col | 217.4 i/s |
| nativepluck_raw :to_sql | 1000 | datetime_col | 210.5 i/s - same-ish: difference falls within error |
| nativepluck | 1000 | datetime_col | 168.6 i/s - same-ish: difference falls within error |
| pluck | 1000 | datetime_col | 42.6 i/s - 5.10x slower |
| nativepluck | 1000 | float_col | 666.5 i/s |
| nativepluck_raw :to_sql | 1000 | float_col | 524.6 i/s - 1.27x slower |
| nativepluck_raw SQL_RAW | 1000 | float_col | 420.4 i/s - 1.59x slower |
| pluck | 1000 | float_col | 374.3 i/s - 1.78x slower |
| nativepluck_raw SQL_RAW | 1000 | json_col | 111.5 i/s |
| nativepluck | 1000 | json_col | 108.7 i/s - same-ish: difference falls within error |
| nativepluck_raw :to_sql | 1000 | json_col | 107.0 i/s - same-ish: difference falls within error |
| pluck | 1000 | json_col | 80.6 i/s - 1.38x slower |
| nativepluck | 1000 | jsonb_col | 102.8 i/s |
| nativepluck_raw SQL_RAW | 1000 | jsonb_col | 102.1 i/s - same-ish: difference falls within error |
| nativepluck_raw :to_sql | 1000 | jsonb_col | 100.0 i/s - same-ish: difference falls within error |
| pluck | 1000 | jsonb_col | 90.9 i/s - 1.13x slower |
| nativepluck_raw SQL_RAW | 1000 | created_at | 199.4 i/s |
| nativepluck | 1000 | created_at | 196.4 i/s - same-ish: difference falls within error |
| nativepluck_raw :to_sql | 1000 | created_at | 187.6 i/s - same-ish: difference falls within error |
| pluck | 1000 | created_at | 45.9 i/s - 4.34x slower |
| nativepluck_raw SQL_RAW | 1000 | updated_at | 204.4 i/s |
| nativepluck_raw :to_sql | 1000 | updated_at | 197.2 i/s - same-ish: difference falls within error |
| nativepluck | 1000 | updated_at | 193.4 i/s - same-ish: difference falls within error |
| pluck | 1000 | updated_at | 40.9 i/s - 5.00x slower |
License
The gem is available as open source under the terms of the Apache 2.0 License.
Development
After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.
Contributing
Bug reports and pull requests are welcome on GitLab at https://gitlab.com/nativepluck/nativepluck. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
Code of Conduct
Everyone interacting in the Nativepluck project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.