On Sun, Aug 26, 2001 at 02:59:28PM -0500, Steve Howard wrote:
> Not the case in this question. What is being returned is the reference -
> values other than a single reference are not being copied. This is how
> fetchrow_arrayref works as well - only a reference to the array is returned,
> but when columns are bound, the reference must be dereferenced somehow so
> that I get to the values of the columns as I bound them. I expected there to
> be noticeable overhead there, and was thinking by not binding columns, and
> dereferencing the returned reference directly I should be able to avoid that
> small overhead. My question is aksed because there is NO difference - not
> that the direct dereference is slower.
Benchmarks are very tricky.
> Try what I wrote. You'll get an array reference as the value of $row - not
> an array. so
>
> $row = $selecth->fetch; #returns a reference - not an array
>
> is not the same as:
>
> @row = $selecth->fetchrow; #copies into an array.
>
> So what I don't understand is what how bind_columns is dereferencing this in
> such a manner as to allow me to refer to the columns as scalars WITHOUT
> showing seeming to show any overhead.
The magic of aliasing. Watch:
# create the row buffer (done once at prepare/execute time)
$row_field_array = [];
# bind a column of the row buffer to a scalar variable
*bind_column_value = \$row_field_buffer->[4];
# fetch the fields of the current row
foreach (0..9) {
$row_field_buffer->[$_] = $_ * 100;
}
print "$bind_column_value\n";
Run it and it prints 400. Magic.
Tim.