Re: [sqlite] optimizing out function calls

2005-11-16 Thread Robin Breathe
Nathan Kurz wrote: > I'm using a computationally expensive user defined function called > 'match()'. In case it makes a difference, match() is written in C, > and for testing, I'm loading it as a shared library into the sqlite3 > shell application. I want to return the value of match(), and also

Re: [sqlite] optimizing out function calls

2005-11-14 Thread Arjen Markus
Jay Sprenkle wrote: > > On 11/14/05, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > > Original Message > > > Subject: Re: [sqlite] optimizing out function calls > > > From: Jay Sprenkle <[EMAIL PROTECTED]> > > > Date:

Re: [sqlite] optimizing out function calls

2005-11-14 Thread Jay Sprenkle
On 11/14/05, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > Original Message > > Subject: Re: [sqlite] optimizing out function calls > > From: Jay Sprenkle <[EMAIL PROTECTED]> > > Date: Mon, November 14, 2005 4:34 pm > > To: sqli

RE: [sqlite] optimizing out function calls

2005-11-14 Thread roger
> Original Message > Subject: Re: [sqlite] optimizing out function calls > From: Jay Sprenkle <[EMAIL PROTECTED]> > Date: Mon, November 14, 2005 4:34 pm > To: sqlite-users@sqlite.org > > > - the random function in C has no arguments, it will produ

Re: [sqlite] optimizing out function calls

2005-11-14 Thread Jay Sprenkle
> - the random function in C has no arguments, it will produce > a different result on every call (within the limits of the > random number generator that is used). Of course from a > mathematical point of view this is a monstrosity ;). > Functions should return the same values given the sa

Re: [sqlite] optimizing out function calls

2005-11-14 Thread Jay Sprenkle
On 11/13/05, Joe Wilson <[EMAIL PROTECTED]> wrote: > MS Access appears to assume all functions called with the same > arguments are constant and returns the same result for every row: > > SQLite is apparently the other extreme - it assumes that each call a > function can potentially yield a diffe

RE: [sqlite] optimizing out function calls

2005-11-14 Thread Brandon, Nicholas
Have a look at archive here http://thread.gmane.org/gmane.comp.db.sqlite.general/13781 At the time I was using the random number generator function and was confused about its usage. It may help some of you. Regards Nick Thi

Re: [sqlite] optimizing out function calls

2005-11-14 Thread Arjen Markus
Joe Wilson wrote: > > What do other databases return for the types of SQL queries below? > > SELECT random(1) AS func FROM test ORDER BY func; > SELECT random() AS func FROM test WHERE func > 10; > > MS Access appears to assume all functions called with the same > arguments are constant and

Re: [sqlite] optimizing out function calls

2005-11-13 Thread Joe Wilson
What do other databases return for the types of SQL queries below? SELECT random(1) AS func FROM test ORDER BY func; SELECT random() AS func FROM test WHERE func > 10; MS Access appears to assume all functions called with the same arguments are constant and returns the same result for every

Re: [sqlite] optimizing out function calls

2005-11-13 Thread Eric Bohlman
[EMAIL PROTECTED] wrote: Nathan Kurz <[EMAIL PROTECTED]> wrote: SELECT uid, match("complex", "function", vector) AS match FROM vectors ORDER BY match DESC LIMIT 20; SELECT uid, mx FROM (SELECT uid, match(...) AS mx FROM vectors LIMIT -1) ORDER BY mx DESC LIMIT 20; The LIMIT -1 on the

Re: [sqlite] optimizing out function calls

2005-11-13 Thread Jay Sprenkle
On 11/13/05, Nathan Kurz <[EMAIL PROTECTED]> wrote: > > On Sun, Nov 13, 2005 at 07:30:58AM -0500, [EMAIL PROTECTED] wrote: > Or even better, is there any way to write a user defined function that > could do the ordering and limiting internally to reduce the data set > early? I suppose I could do it

Re: [sqlite] optimizing out function calls

2005-11-13 Thread Nathan Kurz
On Sun, Nov 13, 2005 at 07:30:58AM -0500, [EMAIL PROTECTED] wrote: > Nathan Kurz <[EMAIL PROTECTED]> wrote: > > > > SELECT uid, match("complex", "function", vector) AS match FROM vectors > > ORDER BY match DESC LIMIT 20; > > SELECT uid, mx FROM > (SELECT uid, match(...) AS mx FROM vector

Re: [sqlite] optimizing out function calls

2005-11-13 Thread drh
Nathan Kurz <[EMAIL PROTECTED]> wrote: > > SELECT uid, match("complex", "function", vector) AS match FROM vectors > ORDER BY match DESC LIMIT 20; SELECT uid, mx FROM (SELECT uid, match(...) AS mx FROM vectors LIMIT -1) ORDER BY mx DESC LIMIT 20; The LIMIT -1 on the subquery is to fake o

Re: [sqlite] optimizing out function calls

2005-11-12 Thread Darren Duncan
According to my understanding of standard SQL, you should be able to say: SELECT arbitrary_expression() AS bar FROM foo ORDER BY bar; ... and the expression is only evaluated once per row, not twice. Your actual example seems confusing, since you appear to alias your 'vectors' table to 'match

Re: [sqlite] optimizing out function calls

2005-11-12 Thread Nathan Kurz
On Sat, Nov 12, 2005 at 10:01:29PM -0700, Nathan Kurz wrote: > SELECT uid, match("complex", "function", vector) FROM vectors AS match > ORDER BY match DESC LIMIT 20; Please pardon the silly typo. I do have the AS in the right spot. SELECT uid, match("complex", "function", vector) AS match F

[sqlite] optimizing out function calls

2005-11-12 Thread Nathan Kurz
Hello -- I'm trying to figure out how to optimize a query a bit, and think I've hit a case that could easily be optimized by sqlite but isn't. I'm wondering if it would be an easy optimization to add, or whether there is some way I can 'hint' the optization into being. I'm using a computationall