Re: [sqlite] Generating VDBE program

2014-09-18 Thread Stephen Chrzanowski
When you do add scripts, put them on pastebin or something of the sort as
this mailing list doesn't always allow attachments.  (I've seen one or two
slip through the cracks)

On Fri, Sep 19, 2014 at 1:20 AM, Prakash Premkumar 
wrote:

> Thanks a lot Richard for your help. I apologize for not including the
> script. I will make it a point to add the scripts from hereon.
>
> On Fri, Sep 19, 2014 at 10:30 AM, Richard Hipp  wrote:
>
> > You start by presenting us with a stand-alone script that we can run to
> see
> > your question.  See you are getting free help, you really should be
> > striving to make it easy for people to help you.  We don't have a script
> > from you, so I made one up.  I'm using:
> >
> > CREATE TABLE employee(eid INTEGER PRIMARY KEY, name TEXT);
> > CREATE TABLE location(lid INTEGER PRIMARY KEY, name TEXT);
> > CREATE TABLE company(cid INTEGER PRIMARY KEY, name TEXT);
> > .explain
> > EXPLAIN
> > SELECT *
> >   FROM employee, company, location
> >  WHERE location.name=company.name
> >AND location.name=employee.name;
> >
> > Be sure to indent your code clearly so that people and understand it more
> > easily.
> >
> > For the trunk of SQLite, the first few instructions are:
> >
> > addr  opcode p1p2p3p4 p5  comment
> >   -        -  --  -
> > 0 Init   0 44000  Start at 44
> > 1 OpenRead   0 2 0 2  00  root=2 iDb=0;
> > employee
> > 2 OpenRead   2 3 0 2  00  root=3 iDb=0;
> > location
> > 3 OpenRead   1 4 0 2  00  root=4 iDb=0;
> > company
> > 4 Explain0 0 0 SCAN TABLE employee
> > 00
> > 5 Rewind 0 42000
> > 6   Once   0 14000
> > 7   OpenAutoindex  3 2 0 k(2,nil,nil)   00  nColumn=2;
> for
> > location
> > 8   Rewind 2 14000
> > 9 Column 2 1 200  r[2]=
> > location.name
> > 10Rowid  2 3 000  r[3]=rowid
> > 11MakeRecord 2 2 100
> > r[1]=mkrec(r[2..3])
> > 12IdxInsert  3 1 010  key=r[1]
> > 13  Next   2 9 003
> >
> > I think you are interested in knowing where the P3 operand (the output
> > register number) for instruction 9 comes from.  (Note that the program
> > shown above might be slightly different in whatever version of SQLite you
> > are running.)
> >
> > The way you find this out is to first compile sqlite3 using
> > -DSQLITE_DEBUG.  Then add the statement:
> >
> >  PRAGMA vdbe_addoptrace=ON;
> >
> > Right before the "EXPLAIN" in the script.  That pragma (only available
> when
> > SQLite is compiled with -DSQLITE_DEBUG) causes SQLite to print a message
> on
> > the screen every time it generates a new opcode.  Next, run sqlite3 in a
> > debugger and set a breakpoint on the "test_addop_breakpoint" procedure.
> > (This is a dummy procedure created specifically to give you a place to
> set
> > a breakpoint.)  Then run your script.  Continue past the first few
> > breakpoints until the "Column" instruction is emitted.  Now you can
> examine
> > the call stack to figure out exactly how that opcode was generated.
> >
> > It appears that the output register 2 comes from here:
> >
> > http://www.sqlite.org/src/artifact/fae81cc2eb14b?ln=812-813
> >
> > Specifically the last parameter.  regBase+j.  You can continue to follow
> > the stack to figure out where regBase was computed.  There are comments
> on
> > each function that try to explain what that particular function is doing.
> >
> >
> >
> >
> >
> >
> > --
> > D. Richard Hipp
> > d...@sqlite.org
> > ___
> > sqlite-users mailing list
> > sqlite-users@sqlite.org
> > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
> >
> ___
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Generating VDBE program

2014-09-18 Thread Prakash Premkumar
Thanks a lot Richard for your help. I apologize for not including the
script. I will make it a point to add the scripts from hereon.

On Fri, Sep 19, 2014 at 10:30 AM, Richard Hipp  wrote:

> You start by presenting us with a stand-alone script that we can run to see
> your question.  See you are getting free help, you really should be
> striving to make it easy for people to help you.  We don't have a script
> from you, so I made one up.  I'm using:
>
> CREATE TABLE employee(eid INTEGER PRIMARY KEY, name TEXT);
> CREATE TABLE location(lid INTEGER PRIMARY KEY, name TEXT);
> CREATE TABLE company(cid INTEGER PRIMARY KEY, name TEXT);
> .explain
> EXPLAIN
> SELECT *
>   FROM employee, company, location
>  WHERE location.name=company.name
>AND location.name=employee.name;
>
> Be sure to indent your code clearly so that people and understand it more
> easily.
>
> For the trunk of SQLite, the first few instructions are:
>
> addr  opcode p1p2p3p4 p5  comment
>   -        -  --  -
> 0 Init   0 44000  Start at 44
> 1 OpenRead   0 2 0 2  00  root=2 iDb=0;
> employee
> 2 OpenRead   2 3 0 2  00  root=3 iDb=0;
> location
> 3 OpenRead   1 4 0 2  00  root=4 iDb=0;
> company
> 4 Explain0 0 0 SCAN TABLE employee
> 00
> 5 Rewind 0 42000
> 6   Once   0 14000
> 7   OpenAutoindex  3 2 0 k(2,nil,nil)   00  nColumn=2; for
> location
> 8   Rewind 2 14000
> 9 Column 2 1 200  r[2]=
> location.name
> 10Rowid  2 3 000  r[3]=rowid
> 11MakeRecord 2 2 100
> r[1]=mkrec(r[2..3])
> 12IdxInsert  3 1 010  key=r[1]
> 13  Next   2 9 003
>
> I think you are interested in knowing where the P3 operand (the output
> register number) for instruction 9 comes from.  (Note that the program
> shown above might be slightly different in whatever version of SQLite you
> are running.)
>
> The way you find this out is to first compile sqlite3 using
> -DSQLITE_DEBUG.  Then add the statement:
>
>  PRAGMA vdbe_addoptrace=ON;
>
> Right before the "EXPLAIN" in the script.  That pragma (only available when
> SQLite is compiled with -DSQLITE_DEBUG) causes SQLite to print a message on
> the screen every time it generates a new opcode.  Next, run sqlite3 in a
> debugger and set a breakpoint on the "test_addop_breakpoint" procedure.
> (This is a dummy procedure created specifically to give you a place to set
> a breakpoint.)  Then run your script.  Continue past the first few
> breakpoints until the "Column" instruction is emitted.  Now you can examine
> the call stack to figure out exactly how that opcode was generated.
>
> It appears that the output register 2 comes from here:
>
> http://www.sqlite.org/src/artifact/fae81cc2eb14b?ln=812-813
>
> Specifically the last parameter.  regBase+j.  You can continue to follow
> the stack to figure out where regBase was computed.  There are comments on
> each function that try to explain what that particular function is doing.
>
>
>
>
>
>
> --
> D. Richard Hipp
> d...@sqlite.org
> ___
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Generating VDBE program

2014-09-18 Thread Richard Hipp
You start by presenting us with a stand-alone script that we can run to see
your question.  See you are getting free help, you really should be
striving to make it easy for people to help you.  We don't have a script
from you, so I made one up.  I'm using:

CREATE TABLE employee(eid INTEGER PRIMARY KEY, name TEXT);
CREATE TABLE location(lid INTEGER PRIMARY KEY, name TEXT);
CREATE TABLE company(cid INTEGER PRIMARY KEY, name TEXT);
.explain
EXPLAIN
SELECT *
  FROM employee, company, location
 WHERE location.name=company.name
   AND location.name=employee.name;

Be sure to indent your code clearly so that people and understand it more
easily.

For the trunk of SQLite, the first few instructions are:

addr  opcode p1p2p3p4 p5  comment
  -        -  --  -
0 Init   0 44000  Start at 44
1 OpenRead   0 2 0 2  00  root=2 iDb=0;
employee
2 OpenRead   2 3 0 2  00  root=3 iDb=0;
location
3 OpenRead   1 4 0 2  00  root=4 iDb=0;
company
4 Explain0 0 0 SCAN TABLE employee
00
5 Rewind 0 42000
6   Once   0 14000
7   OpenAutoindex  3 2 0 k(2,nil,nil)   00  nColumn=2; for
location
8   Rewind 2 14000
9 Column 2 1 200  r[2]=
location.name
10Rowid  2 3 000  r[3]=rowid
11MakeRecord 2 2 100
r[1]=mkrec(r[2..3])
12IdxInsert  3 1 010  key=r[1]
13  Next   2 9 003

I think you are interested in knowing where the P3 operand (the output
register number) for instruction 9 comes from.  (Note that the program
shown above might be slightly different in whatever version of SQLite you
are running.)

The way you find this out is to first compile sqlite3 using
-DSQLITE_DEBUG.  Then add the statement:

 PRAGMA vdbe_addoptrace=ON;

Right before the "EXPLAIN" in the script.  That pragma (only available when
SQLite is compiled with -DSQLITE_DEBUG) causes SQLite to print a message on
the screen every time it generates a new opcode.  Next, run sqlite3 in a
debugger and set a breakpoint on the "test_addop_breakpoint" procedure.
(This is a dummy procedure created specifically to give you a place to set
a breakpoint.)  Then run your script.  Continue past the first few
breakpoints until the "Column" instruction is emitted.  Now you can examine
the call stack to figure out exactly how that opcode was generated.

It appears that the output register 2 comes from here:

http://www.sqlite.org/src/artifact/fae81cc2eb14b?ln=812-813

Specifically the last parameter.  regBase+j.  You can continue to follow
the stack to figure out where regBase was computed.  There are comments on
each function that try to explain what that particular function is doing.






-- 
D. Richard Hipp
d...@sqlite.org
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Generating VDBE program

2014-09-18 Thread Prakash Premkumar
The schema is as follows :

create table employee (name text,age int);
create table location (name text,addr text);
create table company (name text,cname text);

Thanks

On Fri, Sep 19, 2014 at 10:13 AM, Richard Hipp  wrote:

> On Fri, Sep 19, 2014 at 12:35 AM, Prakash Premkumar <
> prakash.p...@gmail.com>
> wrote:
>
> > Let's take this example
> >
> > explain select * from employee,company,location where location.name=
> > company.name and location.name=employee.name;
> >
>
> Also please include the schema for your database.
>
>
>
> >
> > addr  opcode p1p2p3p4 p5  comment
> >
> >   -        -  --  -
> >
> > 0 Init   0 46000  Start at 46
> >
> > 1 OpenRead   0 2 0 2  00  root=2 iDb=0;
> > employee
> >
> > 2 OpenRead   2 3 0 2  00  root=3 iDb=0;
> > location
> >
> > 3 OpenRead   1 4 0 2  00  root=4 iDb=0;
> > company
> >
> > 4 Explain0 0 0 SCAN TABLE employee  00
> >
> >
> > 5 Rewind 0 44000
> >
> > 6   Once   0 15000
> >
> > 7   OpenAutoindex  3 3 0 k(3,nil,nil,nil)  00  nColumn=3;
> > for location
> >
> > 8   Rewind 2 15000
> >
> > 9 Column 2 0 200  r[2]=
> > location.name
> >
> > 10Column 2 1 300
> > r[3]=location.addr
> >
> > 11Rowid  2 4 000  r[4]=rowid
> >
> > 12MakeRecord 2 3 100
> > r[1]=mkrec(r[2..4])
> >
> > 13IdxInsert  3 1 010  key=r[1]
> >
> > 14  Next   2 9 003
> >
> > 15  Explain0 1 2 SEARCH TABLE location USING
> > AUTOMATIC COVERING INDEX (name=?)  00
> >
> > 16  Column 0 0 500  r[5]=
> > employee.name
> >
> > 17  IsNull 5 43000  if r[5]==NULL
> > goto 43
> >
> > 18  SeekGE 3 435 1  00  key=r[5]
> >
> > 19IdxGT  3 435 1  00  key=r[5]
> >
> > 20Once   1 29000
> >
> > 21OpenAutoindex  4 3 0 k(3,nil,nil,nil)  00
> nColumn=3;
> > for company
> >
> > 22Rewind 1 29000
> >
> > 23  Column 1 0 200  r[2]=
> > company.name
> >
> > 24  Column 1 1 300
> > r[3]=company.cname
> >
> > 25  Rowid  1 4 000
> r[4]=rowid
> >
> >
> > 26  MakeRecord 2 3 100
> > r[1]=mkrec(r[2..4])
> >
> > 27  IdxInsert  4 1 010  key=r[1]
> >
> >
> > 28Next   1 23003
> >
> > 29Explain0 2 1 SEARCH TABLE company USING
> > AUTOMATIC COVERING INDEX (name=?)  00
> >
> > 30Column 3 0 600  r[6]=
> > location.name
> >
> > 31IsNull 6 42000  if
> r[6]==NULL
> > goto 42
> >
> > 32SeekGE 4 426 1  00  key=r[6]
> >
> > 33  IdxGT  4 426 1  00  key=r[6]
> >
> >
> > 34  Copy   5 7 000  r[7]=r[5]
> >
> >
> > 35  Column 0 1 800
> > r[8]=employee.age
> >
> > 36  Column 4 0 900  r[9]=
> > company.name
> >
> > 37  Column 4 1 10   00
> > r[10]=company.cname
> >
> > 38  Copy   6 11000
> r[11]=r[6]
> >
> >
> > 39  Column 3 1 12   00
> > r[12]=location.addr
> >
> > 40  ResultRow  7 6 000
> > output=r[7..12]
> >
> > 41Next   4 33000
> >
> > 42  Next   3 19000
> >
> > 43Next   0 6 001
> >
> > 44Close  0 0 000
> >
> > 45Halt   0 0 000
> >
> > 46Transaction0 0 3 0  01
> >
> > 47TableLock  0 2 0 employee   00  iDb=0 root=2
> > write=0
> >
> > 48TableLock  0 3 0 location   00  iDb=0 root=3
> > write=0
> >
> > 49TableLock  0 4 0 company00  iDb=0 root=4
> > write=0
> >
> > 50Goto   0 1 0

Re: [sqlite] Generating VDBE program

2014-09-18 Thread Prakash Premkumar
The opcode I'm interested in is
10 column 2 1 3 00
 On 19 Sep 2014 10:11, "Richard Hipp"  wrote:

> On Fri, Sep 19, 2014 at 12:35 AM, Prakash Premkumar <
> prakash.p...@gmail.com>
> wrote:
>
> > Let's take this example
> >
> > explain select * from employee,company,location where location.name=
> > company.name and location.name=employee.name;
> >
> >
> > How's the register for the highlighted opcode allocated and how does the
> > virtual machine remember this allocation ?
> >
> >
> This mailing list uses plain text (not HTML) for maximal portability.  That
> means that there is no highlighting.
>
> Please provide the opcode address and the operand (P1, P2, P3, etc) that
> you are interested in.
>
> --
> D. Richard Hipp
> d...@sqlite.org
> ___
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Generating VDBE program

2014-09-18 Thread Richard Hipp
On Fri, Sep 19, 2014 at 12:35 AM, Prakash Premkumar 
wrote:

> Let's take this example
>
> explain select * from employee,company,location where location.name=
> company.name and location.name=employee.name;
>

Also please include the schema for your database.



>
> addr  opcode p1p2p3p4 p5  comment
>
>   -        -  --  -
>
> 0 Init   0 46000  Start at 46
>
> 1 OpenRead   0 2 0 2  00  root=2 iDb=0;
> employee
>
> 2 OpenRead   2 3 0 2  00  root=3 iDb=0;
> location
>
> 3 OpenRead   1 4 0 2  00  root=4 iDb=0;
> company
>
> 4 Explain0 0 0 SCAN TABLE employee  00
>
>
> 5 Rewind 0 44000
>
> 6   Once   0 15000
>
> 7   OpenAutoindex  3 3 0 k(3,nil,nil,nil)  00  nColumn=3;
> for location
>
> 8   Rewind 2 15000
>
> 9 Column 2 0 200  r[2]=
> location.name
>
> 10Column 2 1 300
> r[3]=location.addr
>
> 11Rowid  2 4 000  r[4]=rowid
>
> 12MakeRecord 2 3 100
> r[1]=mkrec(r[2..4])
>
> 13IdxInsert  3 1 010  key=r[1]
>
> 14  Next   2 9 003
>
> 15  Explain0 1 2 SEARCH TABLE location USING
> AUTOMATIC COVERING INDEX (name=?)  00
>
> 16  Column 0 0 500  r[5]=
> employee.name
>
> 17  IsNull 5 43000  if r[5]==NULL
> goto 43
>
> 18  SeekGE 3 435 1  00  key=r[5]
>
> 19IdxGT  3 435 1  00  key=r[5]
>
> 20Once   1 29000
>
> 21OpenAutoindex  4 3 0 k(3,nil,nil,nil)  00  nColumn=3;
> for company
>
> 22Rewind 1 29000
>
> 23  Column 1 0 200  r[2]=
> company.name
>
> 24  Column 1 1 300
> r[3]=company.cname
>
> 25  Rowid  1 4 000  r[4]=rowid
>
>
> 26  MakeRecord 2 3 100
> r[1]=mkrec(r[2..4])
>
> 27  IdxInsert  4 1 010  key=r[1]
>
>
> 28Next   1 23003
>
> 29Explain0 2 1 SEARCH TABLE company USING
> AUTOMATIC COVERING INDEX (name=?)  00
>
> 30Column 3 0 600  r[6]=
> location.name
>
> 31IsNull 6 42000  if r[6]==NULL
> goto 42
>
> 32SeekGE 4 426 1  00  key=r[6]
>
> 33  IdxGT  4 426 1  00  key=r[6]
>
>
> 34  Copy   5 7 000  r[7]=r[5]
>
>
> 35  Column 0 1 800
> r[8]=employee.age
>
> 36  Column 4 0 900  r[9]=
> company.name
>
> 37  Column 4 1 10   00
> r[10]=company.cname
>
> 38  Copy   6 11000  r[11]=r[6]
>
>
> 39  Column 3 1 12   00
> r[12]=location.addr
>
> 40  ResultRow  7 6 000
> output=r[7..12]
>
> 41Next   4 33000
>
> 42  Next   3 19000
>
> 43Next   0 6 001
>
> 44Close  0 0 000
>
> 45Halt   0 0 000
>
> 46Transaction0 0 3 0  01
>
> 47TableLock  0 2 0 employee   00  iDb=0 root=2
> write=0
>
> 48TableLock  0 3 0 location   00  iDb=0 root=3
> write=0
>
> 49TableLock  0 4 0 company00  iDb=0 root=4
> write=0
>
> 50Goto   0 1 000
>
>
> How's the register for the highlighted opcode allocated and how does the
> virtual machine remember this allocation ?
>
> Thanks for your help
>
> On Fri, Sep 19, 2014 at 9:46 AM, Richard Hipp  wrote:
>
> > On Fri, Sep 19, 2014 at 12:10 AM, Prakash Premkumar <
> > prakash.p...@gmail.com>
> > wrote:
> >
> > > Thanks for your reply. I would like to know how the register allocation
> > > decision is made and the part of the code which does it . can you
> please
> > > help me find that? Thanks
> > >
> >
> > Which register.
> >
> > Show me

Re: [sqlite] Generating VDBE program

2014-09-18 Thread Richard Hipp
On Fri, Sep 19, 2014 at 12:35 AM, Prakash Premkumar 
wrote:

> Let's take this example
>
> explain select * from employee,company,location where location.name=
> company.name and location.name=employee.name;
>
>
> How's the register for the highlighted opcode allocated and how does the
> virtual machine remember this allocation ?
>
>
This mailing list uses plain text (not HTML) for maximal portability.  That
means that there is no highlighting.

Please provide the opcode address and the operand (P1, P2, P3, etc) that
you are interested in.

-- 
D. Richard Hipp
d...@sqlite.org
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Generating VDBE program

2014-09-18 Thread Prakash Premkumar
Let's take this example

explain select * from employee,company,location where location.name=
company.name and location.name=employee.name;

addr  opcode p1p2p3p4 p5  comment

  -        -  --  -

0 Init   0 46000  Start at 46

1 OpenRead   0 2 0 2  00  root=2 iDb=0;
employee

2 OpenRead   2 3 0 2  00  root=3 iDb=0;
location

3 OpenRead   1 4 0 2  00  root=4 iDb=0;
company

4 Explain0 0 0 SCAN TABLE employee  00


5 Rewind 0 44000

6   Once   0 15000

7   OpenAutoindex  3 3 0 k(3,nil,nil,nil)  00  nColumn=3;
for location

8   Rewind 2 15000

9 Column 2 0 200  r[2]=
location.name

10Column 2 1 300
r[3]=location.addr

11Rowid  2 4 000  r[4]=rowid

12MakeRecord 2 3 100
r[1]=mkrec(r[2..4])

13IdxInsert  3 1 010  key=r[1]

14  Next   2 9 003

15  Explain0 1 2 SEARCH TABLE location USING
AUTOMATIC COVERING INDEX (name=?)  00

16  Column 0 0 500  r[5]=
employee.name

17  IsNull 5 43000  if r[5]==NULL
goto 43

18  SeekGE 3 435 1  00  key=r[5]

19IdxGT  3 435 1  00  key=r[5]

20Once   1 29000

21OpenAutoindex  4 3 0 k(3,nil,nil,nil)  00  nColumn=3;
for company

22Rewind 1 29000

23  Column 1 0 200  r[2]=
company.name

24  Column 1 1 300
r[3]=company.cname

25  Rowid  1 4 000  r[4]=rowid


26  MakeRecord 2 3 100
r[1]=mkrec(r[2..4])

27  IdxInsert  4 1 010  key=r[1]


28Next   1 23003

29Explain0 2 1 SEARCH TABLE company USING
AUTOMATIC COVERING INDEX (name=?)  00

30Column 3 0 600  r[6]=
location.name

31IsNull 6 42000  if r[6]==NULL
goto 42

32SeekGE 4 426 1  00  key=r[6]

33  IdxGT  4 426 1  00  key=r[6]


34  Copy   5 7 000  r[7]=r[5]


35  Column 0 1 800
r[8]=employee.age

36  Column 4 0 900  r[9]=
company.name

37  Column 4 1 10   00
r[10]=company.cname

38  Copy   6 11000  r[11]=r[6]


39  Column 3 1 12   00
r[12]=location.addr

40  ResultRow  7 6 000
output=r[7..12]

41Next   4 33000

42  Next   3 19000

43Next   0 6 001

44Close  0 0 000

45Halt   0 0 000

46Transaction0 0 3 0  01

47TableLock  0 2 0 employee   00  iDb=0 root=2
write=0

48TableLock  0 3 0 location   00  iDb=0 root=3
write=0

49TableLock  0 4 0 company00  iDb=0 root=4
write=0

50Goto   0 1 000


How's the register for the highlighted opcode allocated and how does the
virtual machine remember this allocation ?

Thanks for your help

On Fri, Sep 19, 2014 at 9:46 AM, Richard Hipp  wrote:

> On Fri, Sep 19, 2014 at 12:10 AM, Prakash Premkumar <
> prakash.p...@gmail.com>
> wrote:
>
> > Thanks for your reply. I would like to know how the register allocation
> > decision is made and the part of the code which does it . can you please
> > help me find that? Thanks
> >
>
> Which register.
>
> Show me a specific VDBE program and a specific instruction in that program
> and a specific operand on that instruction, and I can point you to the
> place in the code where that register is allocated.
>
>
> --
> D. Richard Hipp
> d...@sqlite.org
> ___
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/m

Re: [sqlite] Generating VDBE program

2014-09-18 Thread Simon Slavin

On 19 Sep 2014, at 5:10am, Prakash Premkumar  wrote:

> Thanks for your reply. I would like to know how the register allocation
> decision is made and the part of the code which does it . can you please
> help me find that? Thanks

Prakesh, perhaps it would help to read this document:



And then download and browse the SQLite source code from this file

sqlite-src-3080600.zip

on this page:



You should be able to work out which pieces of source code are involved in the 
virtual machine.

Simon.
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Generating VDBE program

2014-09-18 Thread Richard Hipp
On Fri, Sep 19, 2014 at 12:10 AM, Prakash Premkumar 
wrote:

> Thanks for your reply. I would like to know how the register allocation
> decision is made and the part of the code which does it . can you please
> help me find that? Thanks
>

Which register.

Show me a specific VDBE program and a specific instruction in that program
and a specific operand on that instruction, and I can point you to the
place in the code where that register is allocated.


-- 
D. Richard Hipp
d...@sqlite.org
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Generating VDBE program

2014-09-18 Thread Prakash Premkumar
Thanks for your reply. I would like to know how the register allocation
decision is made and the part of the code which does it . can you please
help me find that? Thanks
On 18 Sep 2014 20:20, "Richard Hipp"  wrote:

> On Thu, Sep 18, 2014 at 10:10 AM, Prakash Premkumar <
> prakash.p...@gmail.com>
> wrote:
>
> > Which function in the sqlite generates the Vdbe program for the given
> > query?
> >
> > Let's take an example of the join of two tables. Table A has n columns
> and
> > Table B has m columns, and the result has n+m columns.
> >
> > During the execution of the Vdbe program the values from these columns
> get
> > copied to the Mem struct randomly (when OP_Column opcode is formed) and
> > finally when the OP_ResultRow is executed, the Mem's are rearranged so
> that
> > the columns of each table are contiguous.
> >
> > How does sqlite know in which Mem the value of a column is stored and how
> > does it finally rearrange the Mems contiguously?
> > Can you point me to the portion of the source code which makes this
> > decision?
> >
> > Can you kindly explain me the concept?
> >
>
> SQLite is a compiler.  It transforms a high-level language (SQL) into
> machine code (or in this case VDBE code, which is very similar to machine
> code).   In this sense, SQLite is similar to GCC.  GCC translates C code
> into x86 assembly language.  SQLite translates SQL into VDBE assembly
> language.  The source and target languages are different, but the
> fundamental techniques are the same.
>
> When you ask "how does sqlite know which Mem the value of a column is
> stored?" that is the same as asking "how does gcc know which processor
> registers the value of a variable is stored?".
>
> I recommend that you first study up on compiler construction.  After you
> understand how compilers work, SQLite will likely make a lot more sense to
> you.
>
> --
> D. Richard Hipp
> d...@sqlite.org
> ___
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Generating VDBE program

2014-09-18 Thread Richard Hipp
On Thu, Sep 18, 2014 at 10:10 AM, Prakash Premkumar 
wrote:

> Which function in the sqlite generates the Vdbe program for the given
> query?
>
> Let's take an example of the join of two tables. Table A has n columns and
> Table B has m columns, and the result has n+m columns.
>
> During the execution of the Vdbe program the values from these columns get
> copied to the Mem struct randomly (when OP_Column opcode is formed) and
> finally when the OP_ResultRow is executed, the Mem's are rearranged so that
> the columns of each table are contiguous.
>
> How does sqlite know in which Mem the value of a column is stored and how
> does it finally rearrange the Mems contiguously?
> Can you point me to the portion of the source code which makes this
> decision?
>
> Can you kindly explain me the concept?
>

SQLite is a compiler.  It transforms a high-level language (SQL) into
machine code (or in this case VDBE code, which is very similar to machine
code).   In this sense, SQLite is similar to GCC.  GCC translates C code
into x86 assembly language.  SQLite translates SQL into VDBE assembly
language.  The source and target languages are different, but the
fundamental techniques are the same.

When you ask "how does sqlite know which Mem the value of a column is
stored?" that is the same as asking "how does gcc know which processor
registers the value of a variable is stored?".

I recommend that you first study up on compiler construction.  After you
understand how compilers work, SQLite will likely make a lot more sense to
you.

-- 
D. Richard Hipp
d...@sqlite.org
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


[sqlite] Generating VDBE program

2014-09-18 Thread Prakash Premkumar
Which function in the sqlite generates the Vdbe program for the given query?

Let's take an example of the join of two tables. Table A has n columns and
Table B has m columns, and the result has n+m columns.

During the execution of the Vdbe program the values from these columns get
copied to the Mem struct randomly (when OP_Column opcode is formed) and
finally when the OP_ResultRow is executed, the Mem's are rearranged so that
the columns of each table are contiguous.

How does sqlite know in which Mem the value of a column is stored and how
does it finally rearrange the Mems contiguously?
Can you point me to the portion of the source code which makes this
decision?

Can you kindly explain me the concept?

Thanks for you help.

Regards,
Prakash Premkumar
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users