Re: Nasty bug in Informix optimizer...
Posted in 1999
Topics: Performance & Tuning
I do agree Informix should do the optimization in "MONTH(TODAY)-1"
case, but the code examples are not so concludent. In my understanding
there is a couple of IFs when analyzing the "for" loop optimization:
- the optimizer should check for side effects on r inside the for loop
- the optimizer should check for side effects on r and i in foo function
(if they are global variables).
Kind Regards,
Octav
Mike Segel wrote:
>
> Hey Informix,
>
> Did it ever occur to you to evaluate a function before optimization?
>
> Here's the problem.
>
> I have a simple query on a table that is fragmented by month of year. I
> have a field lets call inputMonth....
>
> So I say
>
> Select foo....
> >From bar
> Where inputMonth = MONTH(TODAY) -1;>
> Now the problem is that I scan every fragment, instead of only last
> month's fragment.
>
> If I said
> Where inputMonth = x
>
> where x is some litteral passed in, the program scans the proper
> fragment.
>
> Now if this seems confusing, look at it this way.
>
> Whats the difference between the following code fragments
>
> for (i=0; i < foo(r); i++) {
> ; do something stupid;
> }
>
> and
> j = foo(r);
> for(i=0; i <j; i++){
> ;do something stupid;
> }
>
> foo() is some function, and for the sake of arguments, i,j,r are all
> integers.
>
> Ok, this is actually an interview question I ask people as part of a
> technical interview.
>
> Seems simple right?
> You'd be surprised at the answers I get.....
>
> -Mikey
--
Octav Chiriac Phone: (373) 2 22 99 67
NetInfo S.R.L. Fax: (373) 2 21 36 59
Chisinau (373) 2 22 84 88
Moldova, Republic of mailto:com@netinfo-moldova.com
In article <80rn7d$1mj$1@news.xmission.com>, Octav Chiriac <com@netinfo-
moldova.com> writes
>
>
>I do agree Informix should do the optimization in "MONTH(TODAY)-1"
>case, but the code examples are not so concludent. In my understanding
>there is a couple of IFs when analyzing the "for" loop optimization:
>- the optimizer should check for side effects on r inside the for loop
>- the optimizer should check for side effects on r and i in foo function
> (if they are global variables).
>
>Kind Regards,
>Octav
>
>Mike Segel wrote:
>>
>> Hey Informix,
>>
>> Did it ever occur to you to evaluate a function before optimization?
>>
>> Here's the problem.
>>
>> I have a simple query on a table that is fragmented by month of year. I
>> have a field lets call inputMonth....
>>
>> So I say
>>
>> Select foo....
>> >From bar
>> Where inputMonth = MONTH(TODAY) -1;>>
>> Now the problem is that I scan every fragment, instead of only last
>> month's fragment.
>>
>> If I said
>> Where inputMonth = x
>>
>> where x is some litteral passed in, the program scans the proper
>> fragment.
>>
>> Now if this seems confusing, look at it this way.
>>
>> Whats the difference between the following code fragments
>>
>> for (i=0; i < foo(r); i++) {
>> ; do something stupid;
>> }
>>
this is
i=0
label 1: push r
call foo
pop tmp1
if i >=tmp1 goto out <-----------
do something stupid
i++
goto label 1:
label out:
At <----------- the first time i MAY or may not be 0 depends what foo
does and the scope of i. At any subsequent time <---- is reached i
may or may not be one larger than the value it had the last time <---
was reached.
E.g. foo uses a pointer which gets a strange value and *zzzz = 99999
means the memory location containing i is affected!!
or what if i is in volatile memory e.g. a memory mapped I/O location
affect by foo!
>
>> and
>> j = foo(r);
>> for(i=0; i <j; i++){
>> ;do something stupid;
>> }
>>
This is
push r
call foo
pop j
i=0
label 1: if i>-j goto out
do something stupid
i++
goto label i:
label out:
Here i increases sequentially assuming
a) i is not volatile (e.g. memory mapped I/O location)
b) do something stupid does not affect the memory pointed to by i.
Or course this all assume ANSI or KnR C syntax + langauage semantics
and this i is a numeric type and does not overflow, not i j larger
than the maximum possible value for i e.g. i is int, j is long and
>INT_MAX and longs can be larger than ints!
Phew! Time for bed...
>> foo() is some function, and for the sake of arguments, i,j,r are all
>> integers.
>>
>> Ok, this is actually an interview question I ask people as part of a
>> technical interview.
>>
>> Seems simple right?
>> You'd be surprised at the answers I get.....
Especially mine!
>>
>> -Mikey
>
--
David Williams