nativepluck 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d69a748d0dc24a02610d0fc53ec3176beb2781b4489d01649c72f40a7c40c987
4
- data.tar.gz: 9d223d5d38ec4cc7df08883465ca26804c75ad5173c1fc90ea275bbf1261271d
3
+ metadata.gz: 28c0929dab54d09b3ab187f5261ceda8a776e582aad1891bdc88b8c83ee04fd8
4
+ data.tar.gz: 076d940e6ad7541b07339e0696588485d2e1a827f1a273b4c9be175480ebdfcc
5
5
  SHA512:
6
- metadata.gz: e7117167ab64168656421f0622eed654e6fedd5e261b9e7a3d44cbb7501f17dc9b670c7bf744449ac8b521416d077f8b5c76c66d589ddd68cae7cf67b48f0ac2
7
- data.tar.gz: 74c28e3ffcdc7d0705e73e6da144cbcbd1eed77d713054150f479d14d8b19936b11a36e716fd0b9a5f0e9bf40bfac43dc4000c5a5993db6cde8ccb9592b32ba9
6
+ metadata.gz: b28f3a9330b9c04ca62f2b388af6cd6a103d1e2285c1b4cfa0e5b4fc65fd4cf333fe03568a360bbfa71f1bdc4c0f0148e562c091e729ae56033318a0664f3457
7
+ data.tar.gz: 6069803e2f09b53f6f94401a10f0dabf0036e3d456d47ade1b441be3ec8daf27535bb474d524d7935b93f3ce2d735a46a2a0bcd7bde5a333a7bc8bc05b65954e
data/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
data/README.md CHANGED
@@ -1,8 +1,7 @@
1
1
  # Nativepluck
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/nativepluck`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ Nativepluck is a high-performance alternative to ActiveRecord's `pluck` when using PostgreSQL.
4
+ Via native PostgreSQL data type casting, we achieve significant memory and time savings.
6
5
 
7
6
  ## Installation
8
7
 
@@ -11,33 +10,608 @@ Add this line to your application's Gemfile:
11
10
  ```ruby
12
11
  gem 'nativepluck'
13
12
  ```
14
-
15
13
  And then execute:
16
-
14
+ ```
17
15
  $ bundle
16
+ ```
18
17
 
19
18
  Or install it yourself as:
20
-
19
+ ```
21
20
  $ gem install nativepluck
21
+ ```
22
22
 
23
23
  ## Usage
24
24
 
25
- TODO: Write usage instructions here
25
+ * If you want to use `nativepluck` as an `ActiveRecord` method, add `include Nativepluck` inside your model.<br>
26
+ In this usage mode (more examples in `test/dummy/test/models/genericmodel_test.rb`):
27
+ `<Model>.nativepluck(:id, order: {id: :asc} , limit: limit)`<br>
28
+ Internally, the method call will generate a SQL query based on your arguments and use native PostgreSQL typecasting on the query results.
26
29
 
27
- ## Development
30
+ * If you have more complex queries that the above mixin method doesn't currently support (such as `joins`):<br>
31
+ You can take an existing ActiveRecord query method call chain, for example:<br>
32
+ `<Model>.where('id >= 21').limit(100).joins(:some_association_to_another_model).pluck(:id)`<br>
33
+ Change the `pluck` call to `select` and use it as the argument to the `nativepluck` module method: `Nativepluck.nativepluck(<Model>.where('id >= 21').limit(100).joins(:some_association_to_another_model).select(:id))`<br>
34
+ Internally, this method calls `to_sql` on the supplied `ActiveRecord::Relation` instance and submits the generated SQL query to the database. Again, native PostgreSQL typecasting is performed on the query results.<br>
35
+ * You can also use a raw SQL string argument in the module method, e.g.,<br>
36
+ `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')`.
37
+
38
+ ## Memory Benchmarks
39
+
40
+ To run the benchmarks use:
41
+ `BenchMarks::Memory::benchmark(write_to_file: true|false, row_limit: nil|integer)`<br>
28
42
 
29
- 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.
43
+ ### Memory allocation benchmark
30
44
 
31
- 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](https://rubygems.org).
45
+ Method | Attribute Name | Total Allocated | Total Retained
46
+ -------|-----------------|------------------|-----------------
47
+ pluck | id | 5125 | 3
48
+ nativepluck | id | 20 | 1
49
+ nativepluck_raw_to_sql | id | 68 | 5
50
+ nativepluck_raw_string | id | 7 | 1
51
+ pluck | integer_col | 5125 | 3
52
+ nativepluck | integer_col | 20 | 1
53
+ nativepluck_raw_to_sql | integer_col | 68 | 5
54
+ nativepluck_raw_string | integer_col | 7 | 1
55
+ pluck | string_col | 7125 | 1003
56
+ nativepluck | string_col | 1020 | 1001
57
+ nativepluck_raw_to_sql | string_col | 1068 | 1005
58
+ nativepluck_raw_string | string_col | 1007 | 1001
59
+ pluck | datetime_col | 22125 | 2003
60
+ nativepluck | datetime_col | 1020 | 1001
61
+ nativepluck_raw_to_sql | datetime_col | 1068 | 1005
62
+ nativepluck_raw_string | datetime_col | 1007 | 1001
63
+ pluck | float_col | 5125 | 3
64
+ nativepluck | float_col | 20 | 1
65
+ nativepluck_raw_to_sql | float_col | 68 | 5
66
+ nativepluck_raw_string | float_col | 7 | 1
67
+ pluck | json_col | 16125 | 3003
68
+ nativepluck | json_col | 11020 | 3001
69
+ nativepluck_raw_to_sql | json_col | 11068 | 3005
70
+ nativepluck_raw_string | json_col | 11007 | 3001
71
+ pluck | jsonb_col | 16125 | 3003
72
+ nativepluck | jsonb_col | 11020 | 3001
73
+ nativepluck_raw_to_sql | jsonb_col | 11068 | 3005
74
+ nativepluck_raw_string | jsonb_col | 11007 | 3001
75
+ pluck | created_at | 22125 | 2003
76
+ nativepluck | created_at | 1020 | 1001
77
+ nativepluck_raw_to_sql | created_at | 1068 | 1005
78
+ nativepluck_raw_string | created_at | 1007 | 1001
79
+ pluck | updated_at | 22125 | 2003
80
+ nativepluck | updated_at | 1020 | 1001
81
+ nativepluck_raw_to_sql | updated_at | 1068 | 1005
82
+ nativepluck_raw_string | updated_at | 1007 | 1001
32
83
 
33
- ## Contributing
84
+ ### Allocated Objects by Class Benchmark
85
+
86
+ Class| Attribute Name| pluck| nativepluck| nativepluck_raw_to_sql| nativepluck_raw_string
87
+ -----|---------------|------|------------|-----------------------|-----------------------
88
+ Array| id|218568|8280|9680|8200
89
+ Array| integer_col|218568|8280|9680|8200
90
+ Array| string_col|218568|8280|9680|8200
91
+ Array| datetime_col|298568|8280|9680|8200
92
+ Array| float_col|218568|8280|9680|8200
93
+ Array| json_col|218568|8280|9680|8200
94
+ Array| jsonb_col|218568|8280|9680|8200
95
+ Array| created_at|298568|8280|9680|8200
96
+ Array| updated_at|298568|8280|9680|8200
97
+ PG::Result| id|30976|30976|30976|30976
98
+ PG::Result| integer_col|30976|30976|30976|30976
99
+ PG::Result| string_col|39168|39168|39168|39168
100
+ PG::Result| datetime_col|51456|51456|51456|51456
101
+ PG::Result| float_col|43264|43264|43264|43264
102
+ PG::Result| json_col|131328|131328|131328|131328
103
+ PG::Result| jsonb_col|139520|139520|139520|139520
104
+ PG::Result| created_at|51456|51456|51456|51456
105
+ PG::Result| updated_at|51456|51456|51456|51456
106
+ String| id|2258|576|256|0
107
+ String| integer_col|2306|576|304|0
108
+ String| string_col|82306|40576|40304|40000
109
+ String| datetime_col|389175|576|304|0
110
+ String| float_col|2306|576|304|0
111
+ String| json_col|418356|416626|416354|416050
112
+ String| jsonb_col|425356|423626|423354|423050
113
+ String| created_at|387306|576|304|0
114
+ String| updated_at|387306|576|304|0
115
+ Hash| id|1696|576|544|0
116
+ Hash| integer_col|1696|576|544|0
117
+ Hash| string_col|1696|576|544|0
118
+ Hash| datetime_col|1696|576|544|0
119
+ Hash| float_col|1696|576|544|0
120
+ Hash| json_col|577696|576576|576544|576000
121
+ Hash| jsonb_col|577696|576576|576544|576000
122
+ Hash| created_at|1696|576|544|0
123
+ Hash| updated_at|1696|576|544|0
124
+ ActiveRecord::Relation| id|352|0|352|0
125
+ ActiveRecord::Relation| integer_col|352|0|352|0
126
+ ActiveRecord::Relation| string_col|352|0|352|0
127
+ ActiveRecord::Relation| datetime_col|352|0|352|0
128
+ ActiveRecord::Relation| float_col|352|0|352|0
129
+ ActiveRecord::Relation| json_col|352|0|352|0
130
+ ActiveRecord::Relation| jsonb_col|352|0|352|0
131
+ ActiveRecord::Relation| created_at|352|0|352|0
132
+ ActiveRecord::Relation| updated_at|352|0|352|0
133
+ MatchData| id|280|0|0|0
134
+ MatchData| integer_col|280|0|0|0
135
+ MatchData| string_col|280|0|0|0
136
+ MatchData| datetime_col|280280|0|0|0
137
+ MatchData| float_col|280|0|0|0
138
+ MatchData| json_col|280|0|0|0
139
+ MatchData| jsonb_col|280|0|0|0
140
+ MatchData| created_at|280280|0|0|0
141
+ MatchData| updated_at|280280|0|0|0
142
+ Time| id|258|0|0|0
143
+ Time| integer_col|258|0|0|0
144
+ Time| string_col|258|0|0|0
145
+ Time| datetime_col|244258|86000|86000|86000
146
+ Time| float_col|258|0|0|0
147
+ Time| json_col|258|0|0|0
148
+ Time| jsonb_col|258|0|0|0
149
+ Time| created_at|244258|86000|86000|86000
150
+ Time| updated_at|244258|86000|86000|86000
151
+ Arel::Nodes::SelectCore| id|104|0|104|0
152
+ Arel::Nodes::SelectCore| integer_col|104|0|104|0
153
+ Arel::Nodes::SelectCore| string_col|104|0|104|0
154
+ Arel::Nodes::SelectCore| datetime_col|104|0|104|0
155
+ Arel::Nodes::SelectCore| float_col|104|0|104|0
156
+ Arel::Nodes::SelectCore| json_col|104|0|104|0
157
+ Arel::Nodes::SelectCore| jsonb_col|104|0|104|0
158
+ Arel::Nodes::SelectCore| created_at|104|0|104|0
159
+ Arel::Nodes::SelectCore| updated_at|104|0|104|0
160
+ ActiveSupport::Notifications::Event| id|96|0|0|0
161
+ ActiveSupport::Notifications::Event| integer_col|96|0|0|0
162
+ ActiveSupport::Notifications::Event| string_col|96|0|0|0
163
+ ActiveSupport::Notifications::Event| datetime_col|96|0|0|0
164
+ ActiveSupport::Notifications::Event| float_col|96|0|0|0
165
+ ActiveSupport::Notifications::Event| json_col|96|0|0|0
166
+ ActiveSupport::Notifications::Event| jsonb_col|96|0|0|0
167
+ ActiveSupport::Notifications::Event| created_at|96|0|0|0
168
+ ActiveSupport::Notifications::Event| updated_at|96|0|0|0
169
+ Arel::Nodes::SelectStatement| id|88|0|88|0
170
+ Arel::Nodes::SelectStatement| integer_col|88|0|88|0
171
+ Arel::Nodes::SelectStatement| string_col|88|0|88|0
172
+ Arel::Nodes::SelectStatement| datetime_col|88|0|88|0
173
+ Arel::Nodes::SelectStatement| float_col|88|0|88|0
174
+ Arel::Nodes::SelectStatement| json_col|88|0|88|0
175
+ Arel::Nodes::SelectStatement| jsonb_col|88|0|88|0
176
+ Arel::Nodes::SelectStatement| created_at|88|0|88|0
177
+ Arel::Nodes::SelectStatement| updated_at|88|0|88|0
178
+ ActiveModel::Attribute::WithCastValue| id|80|0|80|0
179
+ ActiveModel::Attribute::WithCastValue| integer_col|80|0|80|0
180
+ ActiveModel::Attribute::WithCastValue| string_col|80|0|80|0
181
+ ActiveModel::Attribute::WithCastValue| datetime_col|80|0|80|0
182
+ ActiveModel::Attribute::WithCastValue| float_col|80|0|80|0
183
+ ActiveModel::Attribute::WithCastValue| json_col|80|0|80|0
184
+ ActiveModel::Attribute::WithCastValue| jsonb_col|80|0|80|0
185
+ ActiveModel::Attribute::WithCastValue| created_at|80|0|80|0
186
+ ActiveModel::Attribute::WithCastValue| updated_at|80|0|80|0
187
+ ActiveRecord::Result| id|72|0|0|0
188
+ ActiveRecord::Result| integer_col|72|0|0|0
189
+ ActiveRecord::Result| string_col|72|0|0|0
190
+ ActiveRecord::Result| datetime_col|72|0|0|0
191
+ ActiveRecord::Result| float_col|72|0|0|0
192
+ ActiveRecord::Result| json_col|72|0|0|0
193
+ ActiveRecord::Result| jsonb_col|72|0|0|0
194
+ ActiveRecord::Result| created_at|72|0|0|0
195
+ ActiveRecord::Result| updated_at|72|0|0|0
196
+ Arel::Attributes::Attribute| id|40|0|40|0
197
+ Arel::Attributes::Attribute| integer_col|40|0|40|0
198
+ Arel::Attributes::Attribute| string_col|40|0|40|0
199
+ Arel::Attributes::Attribute| datetime_col|40|0|40|0
200
+ Arel::Attributes::Attribute| float_col|40|0|40|0
201
+ Arel::Attributes::Attribute| json_col|40|0|40|0
202
+ Arel::Attributes::Attribute| jsonb_col|40|0|40|0
203
+ Arel::Attributes::Attribute| created_at|40|0|40|0
204
+ Arel::Attributes::Attribute| updated_at|40|0|40|0
205
+ Arel::Collectors::Bind| id|40|0|0|0
206
+ Arel::Collectors::Bind| integer_col|40|0|0|0
207
+ Arel::Collectors::Bind| string_col|40|0|0|0
208
+ Arel::Collectors::Bind| datetime_col|40|0|0|0
209
+ Arel::Collectors::Bind| float_col|40|0|0|0
210
+ Arel::Collectors::Bind| json_col|40|0|0|0
211
+ Arel::Collectors::Bind| jsonb_col|40|0|0|0
212
+ Arel::Collectors::Bind| created_at|40|0|0|0
213
+ Arel::Collectors::Bind| updated_at|40|0|0|0
214
+ Arel::Collectors::Composite| id|40|0|0|0
215
+ Arel::Collectors::Composite| integer_col|40|0|0|0
216
+ Arel::Collectors::Composite| string_col|40|0|0|0
217
+ Arel::Collectors::Composite| datetime_col|40|0|0|0
218
+ Arel::Collectors::Composite| float_col|40|0|0|0
219
+ Arel::Collectors::Composite| json_col|40|0|0|0
220
+ Arel::Collectors::Composite| jsonb_col|40|0|0|0
221
+ Arel::Collectors::Composite| created_at|40|0|0|0
222
+ Arel::Collectors::Composite| updated_at|40|0|0|0
223
+ Arel::Collectors::SQLString| id|40|0|40|0
224
+ Arel::Collectors::SQLString| integer_col|40|0|40|0
225
+ Arel::Collectors::SQLString| string_col|40|0|40|0
226
+ Arel::Collectors::SQLString| datetime_col|40|0|40|0
227
+ Arel::Collectors::SQLString| float_col|40|0|40|0
228
+ Arel::Collectors::SQLString| json_col|40|0|40|0
229
+ Arel::Collectors::SQLString| jsonb_col|40|0|40|0
230
+ Arel::Collectors::SQLString| created_at|40|0|40|0
231
+ Arel::Collectors::SQLString| updated_at|40|0|40|0
232
+ Arel::Nodes::BindParam| id|40|0|40|0
233
+ Arel::Nodes::BindParam| integer_col|40|0|40|0
234
+ Arel::Nodes::BindParam| string_col|40|0|40|0
235
+ Arel::Nodes::BindParam| datetime_col|40|0|40|0
236
+ Arel::Nodes::BindParam| float_col|40|0|40|0
237
+ Arel::Nodes::BindParam| json_col|40|0|40|0
238
+ Arel::Nodes::BindParam| jsonb_col|40|0|40|0
239
+ Arel::Nodes::BindParam| created_at|40|0|40|0
240
+ Arel::Nodes::BindParam| updated_at|40|0|40|0
241
+ Arel::Nodes::JoinSource| id|40|0|40|0
242
+ Arel::Nodes::JoinSource| integer_col|40|0|40|0
243
+ Arel::Nodes::JoinSource| string_col|40|0|40|0
244
+ Arel::Nodes::JoinSource| datetime_col|40|0|40|0
245
+ Arel::Nodes::JoinSource| float_col|40|0|40|0
246
+ Arel::Nodes::JoinSource| json_col|40|0|40|0
247
+ Arel::Nodes::JoinSource| jsonb_col|40|0|40|0
248
+ Arel::Nodes::JoinSource| created_at|40|0|40|0
249
+ Arel::Nodes::JoinSource| updated_at|40|0|40|0
250
+ Arel::Nodes::Limit| id|40|0|40|0
251
+ Arel::Nodes::Limit| integer_col|40|0|40|0
252
+ Arel::Nodes::Limit| string_col|40|0|40|0
253
+ Arel::Nodes::Limit| datetime_col|40|0|40|0
254
+ Arel::Nodes::Limit| float_col|40|0|40|0
255
+ Arel::Nodes::Limit| json_col|40|0|40|0
256
+ Arel::Nodes::Limit| jsonb_col|40|0|40|0
257
+ Arel::Nodes::Limit| created_at|40|0|40|0
258
+ Arel::Nodes::Limit| updated_at|40|0|40|0
259
+ Arel::Nodes::Top| id|40|0|40|0
260
+ Arel::Nodes::Top| integer_col|40|0|40|0
261
+ Arel::Nodes::Top| string_col|40|0|40|0
262
+ Arel::Nodes::Top| datetime_col|40|0|40|0
263
+ Arel::Nodes::Top| float_col|40|0|40|0
264
+ Arel::Nodes::Top| json_col|40|0|40|0
265
+ Arel::Nodes::Top| jsonb_col|40|0|40|0
266
+ Arel::Nodes::Top| created_at|40|0|40|0
267
+ Arel::Nodes::Top| updated_at|40|0|40|0
268
+ Arel::SelectManager| id|40|0|40|0
269
+ Arel::SelectManager| integer_col|40|0|40|0
270
+ Arel::SelectManager| string_col|40|0|40|0
271
+ Arel::SelectManager| datetime_col|40|0|40|0
272
+ Arel::SelectManager| float_col|40|0|40|0
273
+ Arel::SelectManager| json_col|40|0|40|0
274
+ Arel::SelectManager| jsonb_col|40|0|40|0
275
+ Arel::SelectManager| created_at|40|0|40|0
276
+ Arel::SelectManager| updated_at|40|0|40|0
277
+ PG::TypeMapByColumn| id|40|40|40|40
278
+ PG::TypeMapByColumn| integer_col|40|40|40|40
279
+ PG::TypeMapByColumn| string_col|40|40|40|40
280
+ PG::TypeMapByColumn| datetime_col|40|40|40|40
281
+ PG::TypeMapByColumn| float_col|40|40|40|40
282
+ PG::TypeMapByColumn| json_col|40|40|40|40
283
+ PG::TypeMapByColumn| jsonb_col|40|40|40|40
284
+ PG::TypeMapByColumn| created_at|40|40|40|40
285
+ PG::TypeMapByColumn| updated_at|40|40|40|40
286
+ Rational| datetime_col|80000|0|0|0
287
+ Rational| created_at|80000|0|0|0
288
+ Rational| updated_at|80000|0|0|0
289
+ JSON::Ext::Parser| json_col|1168000|1168000|1168000|1168000
290
+ JSON::Ext::Parser| jsonb_col|1168000|1168000|1168000|1168000
291
+ Arel::Collectors::SubstituteBinds| id|0|0|40|0
292
+ Arel::Collectors::SubstituteBinds| integer_col|0|0|40|0
293
+ Arel::Collectors::SubstituteBinds| string_col|0|0|40|0
294
+ Arel::Collectors::SubstituteBinds| datetime_col|0|0|40|0
295
+ Arel::Collectors::SubstituteBinds| float_col|0|0|40|0
296
+ Arel::Collectors::SubstituteBinds| json_col|0|0|40|0
297
+ Arel::Collectors::SubstituteBinds| jsonb_col|0|0|40|0
298
+ Arel::Collectors::SubstituteBinds| created_at|0|0|40|0
299
+ Arel::Collectors::SubstituteBinds| updated_at|0|0|40|0
300
+
301
+ ### Allocated Objects by Memory Benchmark
302
+
303
+ Class| Attribute Name| pluck| nativepluck| nativepluck_raw_to_sql| nativepluck_raw_string
304
+ -----|---------------|------|------------|-----------------------|-----------------------
305
+ Array| id|5063|7|42|5
306
+ Array| integer_col|5063|7|42|5
307
+ Array| string_col|5063|7|42|5
308
+ Array| datetime_col|7063|7|42|5
309
+ Array| float_col|5063|7|42|5
310
+ Array| json_col|5063|7|42|5
311
+ Array| jsonb_col|5063|7|42|5
312
+ Array| created_at|7063|7|42|5
313
+ Array| updated_at|7063|7|42|5
314
+ String| id|28|8|4|0
315
+ String| integer_col|28|8|4|0
316
+ String| string_col|2028|1008|1004|1000
317
+ String| datetime_col|9028|8|4|0
318
+ String| float_col|28|8|4|0
319
+ String| json_col|7028|7008|7004|7000
320
+ String| jsonb_col|7028|7008|7004|7000
321
+ String| created_at|9028|8|4|0
322
+ String| updated_at|9028|8|4|0
323
+ Hash| id|11|3|6|0
324
+ Hash| integer_col|11|3|6|0
325
+ Hash| string_col|11|3|6|0
326
+ Hash| datetime_col|11|3|6|0
327
+ Hash| float_col|11|3|6|0
328
+ Hash| json_col|3011|3003|3006|3000
329
+ Hash| jsonb_col|3011|3003|3006|3000
330
+ Hash| created_at|11|3|6|0
331
+ Hash| updated_at|11|3|6|0
332
+ ActiveRecord::Relation| id|3|0|3|0
333
+ ActiveRecord::Relation| integer_col|3|0|3|0
334
+ ActiveRecord::Relation| string_col|3|0|3|0
335
+ ActiveRecord::Relation| datetime_col|3|0|3|0
336
+ ActiveRecord::Relation| float_col|3|0|3|0
337
+ ActiveRecord::Relation| json_col|3|0|3|0
338
+ ActiveRecord::Relation| jsonb_col|3|0|3|0
339
+ ActiveRecord::Relation| created_at|3|0|3|0
340
+ ActiveRecord::Relation| updated_at|3|0|3|0
341
+ Time| id|3|0|0|0
342
+ Time| integer_col|3|0|0|0
343
+ Time| string_col|3|0|0|0
344
+ Time| datetime_col|3003|1000|1000|1000
345
+ Time| float_col|3|0|0|0
346
+ Time| json_col|3|0|0|0
347
+ Time| jsonb_col|3|0|0|0
348
+ Time| created_at|3003|1000|1000|1000
349
+ Time| updated_at|3003|1000|1000|1000
350
+ ActiveModel::Attribute::WithCastValue| id|1|0|1|0
351
+ ActiveModel::Attribute::WithCastValue| integer_col|1|0|1|0
352
+ ActiveModel::Attribute::WithCastValue| string_col|1|0|1|0
353
+ ActiveModel::Attribute::WithCastValue| datetime_col|1|0|1|0
354
+ ActiveModel::Attribute::WithCastValue| float_col|1|0|1|0
355
+ ActiveModel::Attribute::WithCastValue| json_col|1|0|1|0
356
+ ActiveModel::Attribute::WithCastValue| jsonb_col|1|0|1|0
357
+ ActiveModel::Attribute::WithCastValue| created_at|1|0|1|0
358
+ ActiveModel::Attribute::WithCastValue| updated_at|1|0|1|0
359
+ ActiveRecord::Result| id|1|0|0|0
360
+ ActiveRecord::Result| integer_col|1|0|0|0
361
+ ActiveRecord::Result| string_col|1|0|0|0
362
+ ActiveRecord::Result| datetime_col|1|0|0|0
363
+ ActiveRecord::Result| float_col|1|0|0|0
364
+ ActiveRecord::Result| json_col|1|0|0|0
365
+ ActiveRecord::Result| jsonb_col|1|0|0|0
366
+ ActiveRecord::Result| created_at|1|0|0|0
367
+ ActiveRecord::Result| updated_at|1|0|0|0
368
+ ActiveSupport::Notifications::Event| id|1|0|0|0
369
+ ActiveSupport::Notifications::Event| integer_col|1|0|0|0
370
+ ActiveSupport::Notifications::Event| string_col|1|0|0|0
371
+ ActiveSupport::Notifications::Event| datetime_col|1|0|0|0
372
+ ActiveSupport::Notifications::Event| float_col|1|0|0|0
373
+ ActiveSupport::Notifications::Event| json_col|1|0|0|0
374
+ ActiveSupport::Notifications::Event| jsonb_col|1|0|0|0
375
+ ActiveSupport::Notifications::Event| created_at|1|0|0|0
376
+ ActiveSupport::Notifications::Event| updated_at|1|0|0|0
377
+ Arel::Attributes::Attribute| id|1|0|1|0
378
+ Arel::Attributes::Attribute| integer_col|1|0|1|0
379
+ Arel::Attributes::Attribute| string_col|1|0|1|0
380
+ Arel::Attributes::Attribute| datetime_col|1|0|1|0
381
+ Arel::Attributes::Attribute| float_col|1|0|1|0
382
+ Arel::Attributes::Attribute| json_col|1|0|1|0
383
+ Arel::Attributes::Attribute| jsonb_col|1|0|1|0
384
+ Arel::Attributes::Attribute| created_at|1|0|1|0
385
+ Arel::Attributes::Attribute| updated_at|1|0|1|0
386
+ Arel::Collectors::Bind| id|1|0|0|0
387
+ Arel::Collectors::Bind| integer_col|1|0|0|0
388
+ Arel::Collectors::Bind| string_col|1|0|0|0
389
+ Arel::Collectors::Bind| datetime_col|1|0|0|0
390
+ Arel::Collectors::Bind| float_col|1|0|0|0
391
+ Arel::Collectors::Bind| json_col|1|0|0|0
392
+ Arel::Collectors::Bind| jsonb_col|1|0|0|0
393
+ Arel::Collectors::Bind| created_at|1|0|0|0
394
+ Arel::Collectors::Bind| updated_at|1|0|0|0
395
+ Arel::Collectors::Composite| id|1|0|0|0
396
+ Arel::Collectors::Composite| integer_col|1|0|0|0
397
+ Arel::Collectors::Composite| string_col|1|0|0|0
398
+ Arel::Collectors::Composite| datetime_col|1|0|0|0
399
+ Arel::Collectors::Composite| float_col|1|0|0|0
400
+ Arel::Collectors::Composite| json_col|1|0|0|0
401
+ Arel::Collectors::Composite| jsonb_col|1|0|0|0
402
+ Arel::Collectors::Composite| created_at|1|0|0|0
403
+ Arel::Collectors::Composite| updated_at|1|0|0|0
404
+ Arel::Collectors::SQLString| id|1|0|1|0
405
+ Arel::Collectors::SQLString| integer_col|1|0|1|0
406
+ Arel::Collectors::SQLString| string_col|1|0|1|0
407
+ Arel::Collectors::SQLString| datetime_col|1|0|1|0
408
+ Arel::Collectors::SQLString| float_col|1|0|1|0
409
+ Arel::Collectors::SQLString| json_col|1|0|1|0
410
+ Arel::Collectors::SQLString| jsonb_col|1|0|1|0
411
+ Arel::Collectors::SQLString| created_at|1|0|1|0
412
+ Arel::Collectors::SQLString| updated_at|1|0|1|0
413
+ Arel::Nodes::BindParam| id|1|0|1|0
414
+ Arel::Nodes::BindParam| integer_col|1|0|1|0
415
+ Arel::Nodes::BindParam| string_col|1|0|1|0
416
+ Arel::Nodes::BindParam| datetime_col|1|0|1|0
417
+ Arel::Nodes::BindParam| float_col|1|0|1|0
418
+ Arel::Nodes::BindParam| json_col|1|0|1|0
419
+ Arel::Nodes::BindParam| jsonb_col|1|0|1|0
420
+ Arel::Nodes::BindParam| created_at|1|0|1|0
421
+ Arel::Nodes::BindParam| updated_at|1|0|1|0
422
+ Arel::Nodes::JoinSource| id|1|0|1|0
423
+ Arel::Nodes::JoinSource| integer_col|1|0|1|0
424
+ Arel::Nodes::JoinSource| string_col|1|0|1|0
425
+ Arel::Nodes::JoinSource| datetime_col|1|0|1|0
426
+ Arel::Nodes::JoinSource| float_col|1|0|1|0
427
+ Arel::Nodes::JoinSource| json_col|1|0|1|0
428
+ Arel::Nodes::JoinSource| jsonb_col|1|0|1|0
429
+ Arel::Nodes::JoinSource| created_at|1|0|1|0
430
+ Arel::Nodes::JoinSource| updated_at|1|0|1|0
431
+ Arel::Nodes::Limit| id|1|0|1|0
432
+ Arel::Nodes::Limit| integer_col|1|0|1|0
433
+ Arel::Nodes::Limit| string_col|1|0|1|0
434
+ Arel::Nodes::Limit| datetime_col|1|0|1|0
435
+ Arel::Nodes::Limit| float_col|1|0|1|0
436
+ Arel::Nodes::Limit| json_col|1|0|1|0
437
+ Arel::Nodes::Limit| jsonb_col|1|0|1|0
438
+ Arel::Nodes::Limit| created_at|1|0|1|0
439
+ Arel::Nodes::Limit| updated_at|1|0|1|0
440
+ Arel::Nodes::SelectCore| id|1|0|1|0
441
+ Arel::Nodes::SelectCore| integer_col|1|0|1|0
442
+ Arel::Nodes::SelectCore| string_col|1|0|1|0
443
+ Arel::Nodes::SelectCore| datetime_col|1|0|1|0
444
+ Arel::Nodes::SelectCore| float_col|1|0|1|0
445
+ Arel::Nodes::SelectCore| json_col|1|0|1|0
446
+ Arel::Nodes::SelectCore| jsonb_col|1|0|1|0
447
+ Arel::Nodes::SelectCore| created_at|1|0|1|0
448
+ Arel::Nodes::SelectCore| updated_at|1|0|1|0
449
+ Arel::Nodes::SelectStatement| id|1|0|1|0
450
+ Arel::Nodes::SelectStatement| integer_col|1|0|1|0
451
+ Arel::Nodes::SelectStatement| string_col|1|0|1|0
452
+ Arel::Nodes::SelectStatement| datetime_col|1|0|1|0
453
+ Arel::Nodes::SelectStatement| float_col|1|0|1|0
454
+ Arel::Nodes::SelectStatement| json_col|1|0|1|0
455
+ Arel::Nodes::SelectStatement| jsonb_col|1|0|1|0
456
+ Arel::Nodes::SelectStatement| created_at|1|0|1|0
457
+ Arel::Nodes::SelectStatement| updated_at|1|0|1|0
458
+ Arel::Nodes::Top| id|1|0|1|0
459
+ Arel::Nodes::Top| integer_col|1|0|1|0
460
+ Arel::Nodes::Top| string_col|1|0|1|0
461
+ Arel::Nodes::Top| datetime_col|1|0|1|0
462
+ Arel::Nodes::Top| float_col|1|0|1|0
463
+ Arel::Nodes::Top| json_col|1|0|1|0
464
+ Arel::Nodes::Top| jsonb_col|1|0|1|0
465
+ Arel::Nodes::Top| created_at|1|0|1|0
466
+ Arel::Nodes::Top| updated_at|1|0|1|0
467
+ Arel::SelectManager| id|1|0|1|0
468
+ Arel::SelectManager| integer_col|1|0|1|0
469
+ Arel::SelectManager| string_col|1|0|1|0
470
+ Arel::SelectManager| datetime_col|1|0|1|0
471
+ Arel::SelectManager| float_col|1|0|1|0
472
+ Arel::SelectManager| json_col|1|0|1|0
473
+ Arel::SelectManager| jsonb_col|1|0|1|0
474
+ Arel::SelectManager| created_at|1|0|1|0
475
+ Arel::SelectManager| updated_at|1|0|1|0
476
+ MatchData| id|1|0|0|0
477
+ MatchData| integer_col|1|0|0|0
478
+ MatchData| string_col|1|0|0|0
479
+ MatchData| datetime_col|1001|0|0|0
480
+ MatchData| float_col|1|0|0|0
481
+ MatchData| json_col|1|0|0|0
482
+ MatchData| jsonb_col|1|0|0|0
483
+ MatchData| created_at|1001|0|0|0
484
+ MatchData| updated_at|1001|0|0|0
485
+ PG::Result| id|1|1|1|1
486
+ PG::Result| integer_col|1|1|1|1
487
+ PG::Result| string_col|1|1|1|1
488
+ PG::Result| datetime_col|1|1|1|1
489
+ PG::Result| float_col|1|1|1|1
490
+ PG::Result| json_col|1|1|1|1
491
+ PG::Result| jsonb_col|1|1|1|1
492
+ PG::Result| created_at|1|1|1|1
493
+ PG::Result| updated_at|1|1|1|1
494
+ PG::TypeMapByColumn| id|1|1|1|1
495
+ PG::TypeMapByColumn| integer_col|1|1|1|1
496
+ PG::TypeMapByColumn| string_col|1|1|1|1
497
+ PG::TypeMapByColumn| datetime_col|1|1|1|1
498
+ PG::TypeMapByColumn| float_col|1|1|1|1
499
+ PG::TypeMapByColumn| json_col|1|1|1|1
500
+ PG::TypeMapByColumn| jsonb_col|1|1|1|1
501
+ PG::TypeMapByColumn| created_at|1|1|1|1
502
+ PG::TypeMapByColumn| updated_at|1|1|1|1
503
+ Rational| datetime_col|2000|0|0|0
504
+ Rational| created_at|2000|0|0|0
505
+ Rational| updated_at|2000|0|0|0
506
+ JSON::Ext::Parser| json_col|1000|1000|1000|1000
507
+ JSON::Ext::Parser| jsonb_col|1000|1000|1000|1000
508
+ Arel::Collectors::SubstituteBinds| id|0|0|1|0
509
+ Arel::Collectors::SubstituteBinds| integer_col|0|0|1|0
510
+ Arel::Collectors::SubstituteBinds| string_col|0|0|1|0
511
+ Arel::Collectors::SubstituteBinds| datetime_col|0|0|1|0
512
+ Arel::Collectors::SubstituteBinds| float_col|0|0|1|0
513
+ Arel::Collectors::SubstituteBinds| json_col|0|0|1|0
514
+ Arel::Collectors::SubstituteBinds| jsonb_col|0|0|1|0
515
+ Arel::Collectors::SubstituteBinds| created_at|0|0|1|0
516
+ Arel::Collectors::SubstituteBinds| updated_at|0|0|1|0
517
+
518
+
519
+
520
+ ## RunTime Benchmarks
521
+
522
+ To run the benchmarks use:
523
+ `BenchMarks::RunTime::benchmark`<br>
524
+
525
+ Method | Row Number | Column Name | Results
526
+ ------------------|------------|----------------|---------------------------------------------------------------
527
+ pluck | 1000 | id | 734.245 (± 7.4%) i/s - 3.675k in 5.036733s
528
+ nativepluck | 1000 | id | 1.660k (±15.1%) i/s - 8.052k in 5.013248s
529
+ nativepluck_raw :to_sql | 1000 | id | 1.140k (±23.7%) i/s - 5.280k in 5.027243s
530
+ nativepluck_raw SQL_RAW | 1000 | id | 1.516k (±15.5%) i/s - 7.544k in 5.108323s
531
+ nativepluck | 1000 | id: | 1660.5 i/s
532
+ nativepluck_raw SQL_RAW | 1000 | id: | 1516.2 i/s - same-ish: difference falls within error
533
+ nativepluck_raw :to_sql | 1000 | id: | 1139.7 i/s - same-ish: difference falls within error
534
+ pluck | 1000 | id: | 734.2 i/s - 2.26x slower
535
+ pluck | 1000 | integer_col | 594.946 (±18.3%) i/s - 2.891k in 5.071396s
536
+ nativepluck | 1000 | integer_col | 1.389k (±11.5%) i/s - 6.885k in 5.040319s
537
+ nativepluck_raw :to_sql | 1000 | integer_col | 1.153k (±11.7%) i/s - 5.712k in 5.040637s
538
+ nativepluck_raw SQL_RAW | 1000 | integer_col | 1.515k (±18.8%) i/s - 7.168k in 5.073318s
539
+ nativepluck_raw SQL_RAW | 1000 | integer_col: | 1515.4 i/s
540
+ nativepluck | 1000 | integer_col: | 1388.6 i/s - same-ish: difference falls within error
541
+ nativepluck_raw :to_sql | 1000 | integer_col: | 1152.5 i/s - same-ish: difference falls within error
542
+ pluck | 1000 | integer_col: | 594.9 i/s - 2.55x slower
543
+ pluck | 1000 | string_col | 454.914 (±14.9%) i/s - 2.214k in 5.008098s
544
+ nativepluck | 1000 | string_col | 1.318k (±19.7%) i/s - 6.308k in 5.043532s
545
+ nativepluck_raw :to_sql | 1000 | string_col | 980.711 (±12.1%) i/s - 4.872k in 5.052058s
546
+ nativepluck_raw SQL_RAW | 1000 | string_col | 1.104k (±30.4%) i/s - 5.000k in 5.004424s
547
+ nativepluck | 1000 | string_col: | 1317.6 i/s
548
+ nativepluck_raw SQL_RAW | 1000 | string_col: | 1103.6 i/s - same-ish: difference falls within error
549
+ nativepluck_raw :to_sql | 1000 | string_col: | 980.7 i/s - same-ish: difference falls within error
550
+ pluck | 1000 | string_col: | 454.9 i/s - 2.90x slower
551
+ pluck | 1000 | datetime_col | 42.642 (±18.8%) i/s - 208.000 in 5.128522s
552
+ nativepluck | 1000 | datetime_col | 168.646 (±23.1%) i/s - 800.000 in 5.054452s
553
+ nativepluck_raw :to_sql | 1000 | datetime_col | 210.517 (± 5.2%) i/s - 1.054k in 5.021131s
554
+ nativepluck_raw SQL_RAW | 1000 | datetime_col | 217.352 (± 8.7%) i/s - 1.080k in 5.024471s
555
+ nativepluck_raw SQL_RAW | 1000 | datetime_col: | 217.4 i/s
556
+ nativepluck_raw :to_sql | 1000 | datetime_col: | 210.5 i/s - same-ish: difference falls within error
557
+ nativepluck | 1000 | datetime_col: | 168.6 i/s - same-ish: difference falls within error
558
+ pluck | 1000 | datetime_col: | 42.6 i/s - 5.10x slower
559
+ pluck | 1000 | float_col | 374.268 (± 3.2%) i/s - 1.887k in 5.047628s
560
+ nativepluck | 1000 | float_col | 666.547 (± 3.5%) i/s - 3.350k in 5.032298s
561
+ nativepluck_raw :to_sql | 1000 | float_col | 524.621 (±20.6%) i/s - 2.501k in 5.039590s
562
+ nativepluck_raw SQL_RAW | 1000 | float_col | 420.448 (±32.8%) i/s - 1.876k in 5.079478s
563
+ nativepluck | 1000 | float_col: | 666.5 i/s
564
+ nativepluck_raw :to_sql | 1000 | float_col: | 524.6 i/s - 1.27x slower
565
+ nativepluck_raw SQL_RAW | 1000 | float_col: | 420.4 i/s - 1.59x slower
566
+ pluck | 1000 | float_col: | 374.3 i/s - 1.78x slower
567
+ pluck | 1000 | json_col | 80.572 (±24.8%) i/s - 369.000 in 5.000541s
568
+ nativepluck | 1000 | json_col | 108.713 (± 5.5%) i/s - 549.000 in 5.064493s
569
+ nativepluck_raw :to_sql | 1000 | json_col | 106.966 (± 7.5%) i/s - 535.000 in 5.038752s
570
+ nativepluck_raw SQL_RAW | 1000 | json_col | 111.460 (± 6.3%) i/s - 556.000 in 5.008867s
571
+ nativepluck_raw SQL_RAW | 1000 | json_col: | 111.5 i/s
572
+ nativepluck | 1000 | json_col: | 108.7 i/s - same-ish: difference falls within error
573
+ nativepluck_raw :to_sql | 1000 | json_col: | 107.0 i/s - same-ish: difference falls within error
574
+ pluck | 1000 | json_col: | 80.6 i/s - 1.38x slower
575
+ pluck | 1000 | jsonb_col | 90.935 (± 5.5%) i/s - 459.000 in 5.065060s
576
+ nativepluck | 1000 | jsonb_col | 102.772 (± 4.9%) i/s - 520.000 in 5.069177s
577
+ nativepluck_raw :to_sql | 1000 | jsonb_col | 100.030 (± 5.0%) i/s - 500.000 in 5.012083s
578
+ nativepluck_raw SQL_RAW | 1000 | jsonb_col | 102.059 (± 5.9%) i/s - 510.000 in 5.017367s
579
+ nativepluck | 1000 | jsonb_col: | 102.8 i/s
580
+ nativepluck_raw SQL_RAW | 1000 | jsonb_col: | 102.1 i/s - same-ish: difference falls within error
581
+ nativepluck_raw :to_sql | 1000 | jsonb_col: | 100.0 i/s - same-ish: difference falls within error
582
+ pluck | 1000 | jsonb_col: | 90.9 i/s - 1.13x slower
583
+ pluck | 1000 | created_at | 45.932 (± 4.4%) i/s - 232.000 in 5.056838s
584
+ nativepluck | 1000 | created_at | 196.429 (± 2.5%) i/s - 988.000 in 5.033270s
585
+ nativepluck_raw :to_sql | 1000 | created_at | 187.641 (± 4.8%) i/s - 950.000 in 5.077301s
586
+ nativepluck_raw SQL_RAW | 1000 | created_at | 199.361 (± 3.0%) i/s - 1.007k in 5.055300s
587
+ nativepluck_raw SQL_RAW | 1000 | created_at: | 199.4 i/s
588
+ nativepluck | 1000 | created_at: | 196.4 i/s - same-ish: difference falls within error
589
+ nativepluck_raw :to_sql | 1000 | created_at: | 187.6 i/s - same-ish: difference falls within error
590
+ pluck | 1000 | created_at: | 45.9 i/s - 4.34x slower
591
+ pluck | 1000 | updated_at | 40.874 (±22.0%) i/s - 184.000 in 5.024964s
592
+ nativepluck | 1000 | updated_at | 193.426 (±17.6%) i/s - 920.000 in 5.063586s
593
+ nativepluck_raw :to_sql | 1000 | updated_at | 197.212 (± 7.6%) i/s - 988.000 in 5.040263s
594
+ nativepluck_raw SQL_RAW | 1000 | updated_at | 204.420 (± 5.9%) i/s - 1.020k in 5.007479s
595
+ nativepluck_raw SQL_RAW | 1000 | updated_at: | 204.4 i/s
596
+ nativepluck_raw :to_sql | 1000 | updated_at: | 197.2 i/s - same-ish: difference falls within error
597
+ nativepluck | 1000 | updated_at: | 193.4 i/s - same-ish: difference falls within error
598
+ pluck | 1000 | updated_at: | 40.9 i/s - 5.00x slower
34
599
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/nativepluck. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
600
 
37
601
  ## License
38
602
 
39
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
603
+ The gem is available as open source under the terms of the [Apache 2.0 License](https://opensource.org/licenses/Apache-2.0).
604
+
605
+ ## Development
606
+
607
+ 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.
608
+
609
+ 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](https://rubygems.org/).
610
+
611
+ ## Contributing
612
+
613
+ 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](http://contributor-covenant.org/) code of conduct.
40
614
 
41
615
  ## Code of Conduct
42
616
 
43
- Everyone interacting in the Nativepluck project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/nativepluck/blob/master/CODE_OF_CONDUCT.md).
617
+ Everyone interacting in the Nativepluck project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://gitlab.com/nativepluck/nativepluck/blob/master/CODE_OF_CONDUCT.md).
@@ -1,3 +1,17 @@
1
+ # Copyright 2018 Ohad Dahan, Al Chou
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
1
15
  module Nativepluck
2
- VERSION = "0.1.0"
16
+ VERSION = "0.1.1"
3
17
  end
data/lib/nativepluck.rb CHANGED
@@ -1,5 +1,88 @@
1
+ # Copyright 2018 Ohad Dahan, Al Chou
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
1
15
  require "nativepluck/version"
2
16
 
3
17
  module Nativepluck
4
- # Your code goes here...
18
+ @nativepluck_init = false
19
+
20
+ class << self
21
+ attr_accessor :nativepluck_type_map_for_results, :nativepluck_type_map_for_queries
22
+ attr_accessor :original_type_map_for_results, :original_type_map_for_queries
23
+ attr_accessor :nativepluck_init
24
+ end
25
+
26
+ def self.included(klass)
27
+ klass.extend(ClassMethods)
28
+ init_nativepluck
29
+ end
30
+
31
+ def self.init_nativepluck
32
+ return if @nativepluck_init
33
+ @nativepluck_type_map_for_results = PG::BasicTypeMapForResults.new ActiveRecord::Base.connection.raw_connection
34
+ @nativepluck_type_map_for_queries = PG::BasicTypeMapForQueries.new ActiveRecord::Base.connection.raw_connection
35
+ @original_type_map_for_results = ActiveRecord::Base.connection.raw_connection.type_map_for_results
36
+ @original_type_map_for_queries = ActiveRecord::Base.connection.raw_connection.type_map_for_queries
37
+ @nativepluck_init = true
38
+ end
39
+
40
+ def self.set_pg_native_casters
41
+ init_nativepluck
42
+ ActiveRecord::Base.connection.raw_connection.type_map_for_results = Nativepluck.nativepluck_type_map_for_results
43
+ ActiveRecord::Base.connection.raw_connection.type_map_for_queries = Nativepluck.nativepluck_type_map_for_queries
44
+ end
45
+
46
+ def self.return_original_casters
47
+ init_nativepluck
48
+ ActiveRecord::Base.connection.raw_connection.type_map_for_results = Nativepluck.original_type_map_for_results
49
+ ActiveRecord::Base.connection.raw_connection.type_map_for_queries = Nativepluck.original_type_map_for_queries
50
+ end
51
+
52
+ def self.nativepluck(input)
53
+ begin
54
+ sql = input.respond_to?(:to_sql) ? input.to_sql : input
55
+ Nativepluck.set_pg_native_casters
56
+ results = ActiveRecord::Base.connection.raw_connection.async_exec(sql)
57
+ results.nfields == 1 ? out = results.column_values(0) : out = results.values
58
+ ensure
59
+ results.try(:clear)
60
+ Nativepluck.return_original_casters
61
+ end
62
+ return out
63
+ end
64
+
65
+ module ClassMethods
66
+ def nativepluck(*columns, **opts)
67
+ raise ArgumentError.new('No columns to pluck were provided') if columns.size == 0
68
+ begin
69
+ Nativepluck.set_pg_native_casters
70
+ sql = "
71
+ SELECT #{columns.join(',')}
72
+ FROM #{self.table_name}
73
+ #{"GROUP BY #{opts[:group].zip.map { |i| i.join(' ') }.join(',')}" if opts[:group]}
74
+ #{"ORDER BY #{opts[:order].zip.map { |i| i.join(' ') }.join(',')}" if opts[:order]}
75
+ #{"LIMIT #{opts[:limit]}" if opts[:limit]}
76
+ #{"OFFSET #{opts[:offset]}" if opts[:offset]}
77
+ "
78
+ results = ActiveRecord::Base.connection.raw_connection.async_exec(sql)
79
+ puts "#{__method__} sql = #{sql}" if opts[:verbose]
80
+ results.nfields == 1 ? out = results.column_values(0) : out = results.values
81
+ ensure
82
+ results.try(:clear)
83
+ Nativepluck.return_original_casters
84
+ end
85
+ return out
86
+ end
87
+ end
5
88
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nativepluck
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ohad Dahan
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-10-19 00:00:00.000000000 Z
12
+ date: 2018-11-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -46,6 +46,7 @@ executables: []
46
46
  extensions: []
47
47
  extra_rdoc_files: []
48
48
  files:
49
+ - LICENSE
49
50
  - README.md
50
51
  - Rakefile
51
52
  - lib/nativepluck.rb