Quantcast

What does this code do?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

What does this code do?

Ludvig Strigeus-2
In sqlite3VdbeRecordCompare()

    /* Read the serial types for the next element in each key. */
    idx1 += sqlite3GetVarint32(&aKey1[idx1], &serial_type1);
    if( d1>=nKey1 && sqlite3VdbeSerialTypeLen(serial_type1)>0 ) break;
    idx2 += sqlite3GetVarint32(&aKey2[idx2], &serial_type2);
    if( d2>=nKey2 && sqlite3VdbeSerialTypeLen(serial_type2)>0 ) break;

What is the purpose of the sqlite3VdbeSerialTypeLen(serial_type1)>0 here?

/Ludvig
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: What does this code do?

Dan Kennedy

--- Ludvig Strigeus <[hidden email]> wrote:
> In sqlite3VdbeRecordCompare()
>
>     /* Read the serial types for the next element in each key. */
>     idx1 += sqlite3GetVarint32(&aKey1[idx1], &serial_type1);f
>     if( d1>=nKey1 && sqlite3VdbeSerialTypeLen(serial_type1)>0 ) break;
>     idx2 += sqlite3GetVarint32(&aKey2[idx2], &serial_type2);
>     if( d2>=nKey2 && sqlite3VdbeSerialTypeLen(serial_type2)>0 ) break;
>
> What is the purpose of the sqlite3VdbeSerialTypeLen(serial_type1)>0 here?

If the last field in the record is an SQL NULL, then d1==nKey1 and
sqlite3VdbeSerialTypeLen() returns zero. In this case the record hasn't
run out of fields, so we don't want to break out of that loop.



               
Yahoo! Mail
Stay connected, organized, and protected. Take the tour:
http://tour.mail.yahoo.com/mailtour.html

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: What does this code do?

Ludvig Strigeus-2
What if the last field of record1 is a NULL,
and the last field of record2 is an empty string.

Then there's no way to tell sqlite3VdbeRecordCompare that you don't
want to compare those items. If you set nKey1 and nKey2 to the last
offsets of each record, the last items will be compared too.

Why not pass a single number to sqlite3VdbeRecordCompare instead, that
just says how many fields to compare? That seems simpler. Why was the
current design chosen.

/Ludvig

On 5/22/05, Dan Kennedy <[hidden email]> wrote:

>
> --- Ludvig Strigeus <[hidden email]> wrote:
> > In sqlite3VdbeRecordCompare()
> >
> >     /* Read the serial types for the next element in each key. */
> >     idx1 += sqlite3GetVarint32(&aKey1[idx1], &serial_type1);f
> >     if( d1>=nKey1 && sqlite3VdbeSerialTypeLen(serial_type1)>0 ) break;
> >     idx2 += sqlite3GetVarint32(&aKey2[idx2], &serial_type2);
> >     if( d2>=nKey2 && sqlite3VdbeSerialTypeLen(serial_type2)>0 ) break;
> >
> > What is the purpose of the sqlite3VdbeSerialTypeLen(serial_type1)>0 here?
>
> If the last field in the record is an SQL NULL, then d1==nKey1 and
> sqlite3VdbeSerialTypeLen() returns zero. In this case the record hasn't
> run out of fields, so we don't want to break out of that loop.
>
>
>
>
> Yahoo! Mail
> Stay connected, organized, and protected. Take the tour:
> http://tour.mail.yahoo.com/mailtour.html
>
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: What does this code do?

D. Richard Hipp
On Sun, 2005-05-22 at 10:19 +0200, Ludvig Strigeus wrote:
> Why not pass a single number to sqlite3VdbeRecordCompare instead, that
> just says how many fields to compare? That seems simpler. Why was the
> current design chosen.
>
The reason for not passing in a nField value is that the BTree layer
which calls VdbeRecordCompare does not know about fields.  The BTree
layer thinks of each row as a single BLOB - a sequence of bytes - with
no internal structure.  So the BTree layer has no idea how many fields
their are.

The first parameter to VdbeRecordCompare is a structure that defines
the format of the BLOBs being compared and *does* contain an nField
parameter.  But the rowid that appears at the end of index entries
is omitted from the count.  So nField is off by one. But perhaps you
can use it instead of a call to sqlite3VdbeSerialTypeLen().  If you
can get such a change to pass a full regression test, I will likely
check it in.

--
D. Richard Hipp <[hidden email]>

Loading...