Subject | RE: [firebird-support] Performance of the count Function. |
---|---|
Author | Nigel Weeks |
Post date | 2005-03-01T00:24:36Z |
>One of the biggest things I've learnt with Firebird, is to stand back a
> And how do you get a fast count when having the following table
>
> TABLE (
> X INT NOT NULL,
> Y CHAR NOT NULL,
> PRIMARY KEY (X,Y)
> )
> and want to know the number of records that satisfies for
> Y=Y1 and Y=Y2?
>
> eg.
>
> X Y
> ------------
> X1 Y1 <-----
> X2 Y1
> X1 Y2 <-----
> X2 Y3
> X3 Y1 <-----
> X3 Y2 <-----
>
> The result here would be count(*) =2
>
> The way I count is:
>
> SELECT COUNT(*)
> FROM TABLE T
> WHERE T.Y = Y1
> AND T.X IN (SELECT T.X FROM T WHERE T.Y = Y2)
>
> whereby having Y1 the value with the lowest count (maintained
> in a table
> like you suggested).
> Is there also a faster way for this scenario?
>
>
little, and ask myself, "Why do I need to know the number of records?"
If you simply wanted to show the number of records at the bottom of a
listing, i.e.:
Number of results returned: 950
You can just use an incrementing variable in your front end code.
Can you do without the count when applying 'where' conditions?
N.