Re: What's the fastest way to...
Posted in 1994
>
> There may have been some other error on the same line that was corrected
> when the where 1 = 1 was added. 4gl _assumes_ 1 = 1 if no where clause
> is included.
the .ec code from my DELETE statement follows (generated by c4gl):
/*
* $ delete from idx_src;
*/
{
static char *sqlcmdtxt[] =
{
" delete from idx_src",
(char *) 0
};
static _SQSTMT _SQ0 = {0};
_iqstmnt(&_SQ0, sqlcmdtxt, 0, (char *) 0, (char *) 0);
}
status = sqlca.sqlcode;
(sqexplain.out)
QUERY:
------
delete from idx_src
Estimated Cost: 35
Estimated # of Rows Returned: 241
1) jparker.idx_src: SEQUENTIAL SCAN
QUERY:
------
delete from idx_src where 1=1
Estimated Cost: 35
Estimated # of Rows Returned: 241
1) jparker.idx_src: SEQUENTIAL SCAN
Filters: 1 = 1
In the second case it is passing through a filter - which it is not in the
first case. But it seems to make little difference in length of time.
I just tried it both ways 6 times and the deviation in time between each
invocation of the same sql is greater than any difference between the two
methods. Of course my dataset is fairly small.
>
> It's not a bad idea however, to include a "where 1 = 1" clause anyway.
> A good example of this is the construct statement: Build
I think an argument could be made that the where 1=1 is useful for
documentation, but it is sort of implied.
> a construct, don't enter any values and then look at the "output: from
> the construct. Ta da 1=1.
Yes, because that's how a construct works. Because your string when you
prepare it is going to be "SELECT * FROM table WHERE ", construct_strg.
Therefore construct_strg ALWAYS has to have something valid in it. Even
when the user just hits ACCEPT, not because a WHERE clause is required.
Otherwise your prepared string would be garbage.
j.
_____________________________________________________________________________
Jack Parker |
Hewlett Packard, BSMC Boise, Idaho, USA| If you put all of the lawyers in
jparker@hpbs3645.boi.hp.com | this country end to end,
(208) 396-5388 (W) (208) 384-1623 (H) | it would be a good thing.
_____________________________________________________________________________
Any opinions expressed herein are my own and not those of my employers.
_____________________________________________________________________________