teststore.example',
'A Test Store');
INSERT INTO webhosts (domain, description) ('www.smallblog.example',
'A Small Blog');
On the other hand, the ActiveRecord::Extensions code produces a query like this:
CHAPTER 10 n CALCULATING COSTS BY ANALYZING APACHE WEB LOGS 190
INSERT INTO webhosts (domain, description) ('www.somecompany.example',
'Some Company Site'),
('www.teststore.example',
'A Test Store'),
('www.smallblog.example',
'A Small Blog');
As you can see, the same data is inserted in three queries in the first example but in
just one query in the second example. It won??™t take very long to insert three records no
matter what you do. However, in cases where you need to scale, and even more so when
you need to insert large amounts of data at once, the time savings can be quite valuable.
You might initially think that a database like MySQL or PostgreSQL would take the
same amount of time to insert a given number of rows, without regard to how many
queries are used, but that??™s not true. Significant overhead is associated with each additional
query.
Pages:
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276