List:Internals« Previous MessageNext Message »
From:Sergei Golubchik Date:June 30 2008 5:51pm
Subject:Re: position and rnd_pos
View as plain text  
Hi!

On Jun 25, Scara Maccai wrote:
> Sergei Golubchik wrote:
>> You could grep the source for '->position(' to see where it's called.
>> It's sql_update.cc, sql_delete.cc, sql_select.cc, opt_range.h,
>> opt_range.cc, filesort.cc. Out of that filesort is the easiest way to
>> trigger ::position() call.
>>
>> In opt_range.cc it's inside 
>> QUICK_INDEX_MERGE_SELECT::read_keys_and_merge(),
>> so you'll need to trigger index merge first. In sql_delete.cc and
>> sql_update.cc it's used in multi-table delete/update, and when you
>> update some indexed column with WHERE condition on a this very column.
>> In sql_select.cc it's used in certain queries with DISTINCT.
>>
>> Besides, the manual page you're quoting says "certain operations rely on
>> proper implementation of position() and rnd_pos() calls. Two examples of
>> such operations are multi-table UPDATE and SELECT .. table.blob_column
>> ORDER BY something".
>
> Well I'm not going to use any INSERT/UPDATE/DELETE (it's a read only custom 
> engine) and no blobs.
>
> "certain queries with DISTINCT": which ones?
> How can I trigger an index merge?
> And a filesort?

Here's the one with filesort (I used MyISAM below):

create table t1 (a varchar(200));
insert t1 values (rand());
insert t1 select rand() from t1;
insert t1 select rand() from t1;
insert t1 select rand() from t1;
insert t1 select rand() from t1;
insert t1 select rand() from t1;
select * from t1 order by a limit 5;

The last one has tripped over my breakpoint in ha_myisam::position().

>> Yeah, it's wrong. The reference is stored in this->ref. And the contents
>> of this *reference* is up to you whatever value ... etc
>
> Ok. Can I set ref_length myself? I mean: can I decide its length?

Yes, certainly. If you do

   % grep '\<ref_length *= *' storage/*/ha_*.cc

you'll see that every storage engine sets ref_length.

> Should I call a "free_ptr" somewhere or mysql will take care of releasing 
> the pointer?

MySQL doesn't ask you to allocate anything, so MySQL won't free it
either. You're expected to put the "position" in this->ref. MySQL will
copy it out from there. Later it'll use this copy as an argument for
rnd_pos(). What is it that you need to be released ?

Regards / Mit vielen Grüssen,
Sergei

-- 
   __  ___     ___ ____  __
  /  |/  /_ __/ __/ __ \/ /   Sergei Golubchik <serg@stripped>
 / /|_/ / // /\ \/ /_/ / /__  Principal Software Engineer/Server Architect
/_/  /_/\_, /___/\___\_\___/  Sun Microsystems GmbH, HRB München 161028
       <___/                  Sonnenallee 1, 85551 Kirchheim-Heimstetten
Geschäftsführer: Thomas Schroeder, Wolfgang Engels, Dr. Roland Boemer
Vorsitzender des Aufsichtsrates: Martin Häring
Thread
position and rnd_posScara Maccai25 Jun
  • re: position and rnd_posMichael Widenius25 Jun
  • Re: position and rnd_posSergei Golubchik25 Jun
    • Re: position and rnd_posScara Maccai25 Jun
      • Re: position and rnd_posSergei Golubchik30 Jun
        • Re: position and rnd_posScara Maccai2 Jul
    • Re: position and rnd_posMark Callaghan26 Jun