Translating with DrWatson… this can take a few seconds the first time.
This is a genuine, complex translation. DrWatson protects commands, error codes, and log output while naturally translating the surrounding text. It’s translated once and saved.
problem with select count(distinct
Answered: red (solid confidence) — SELECT COUNT(DISTINCT ...) gives a different, wrong answer once a plain index exists on the column; a known IBM knowledge-base defect (fixed in UC5) is raised as a candidate explanation but is walked back as not quite matching (non-unique, non-composite index), and the thread ends without a working fix.
Clive Eisen (IDS 10.00.UC5I1 on Linux) found that "select count(distinct phone)" on a round-robin fragmented table returned the correct value (3,862,276) with no index, but an inflated value (~4.37M) once a simple single-column index on the phone column was created; dropping and recreating the index reproduced it every time. UPDATE STATISTICS made no difference, and a dbexport/dbimport gave yet another wrong count. Another poster pointed to a known count bug (composite-index related) fixed in UC5, whose workaround was to index the distinct column alone \\u2014 which was already the case here, so it didn't apply. Advice was to check against stock 10.00.UC5 and contact support; no resolution is recorded in the thread.
Auto-generated by DrWatson from the posts below — may be imperfect; read the full thread.
Running 10.00.UC5I1 on linux
With the following schema and static data i.e. I am the only user
create table 'informix'.phone (
id SERIAL not null,
phone CHAR(11) not null,
batch_id INT not null
)
fragment by round robin in data1,data2,data3
extent size 350000 next size 20000
lock mode row;
The following code
echo "select count(distinct phone) from phone" | dbaccess data
produces
Database selected.
(count)
3862276
However - if I add the following
create index 'informix'.ix101_2 on 'informix'.phone
(
phone
);
I get
Database selected.
(count)
4374605
FWIW
1) the first is the 'correct' answer i.e. 3862276
I unloaded the column from the table
and ran through sort -u | wc -l
2) before you ask OTC, I HAVE tried UPDATE STATISTICS
3) This is entirely reproducible -
drop index - answer 1
re-add index - answer 2
I'm going to try a dbexport and dbimport and will report back.
Any comments gratefully received
--
Clive
Clive Eisen wrote:
> Clive Eisen wrote:
>
>> I'm going to try a dbexport and dbimport and will report back.
> No change
>
Sorry to re-comment on my own comment but actually it's WORSE
echo "select count(distinct phone) from phone" | dbaccess data_test
Database selected.
(count)
4348249
Ho hum
--
Clive
↪ replying to Clive Eisen
Diego Morales — — source: Usenet: comp.databases.informix
Update statistics???
-----Mensaje original-----
De: informix-list-bounces@iiug.org [mailto:informix-list-bounces@iiug.org]
En nombre de Clive Eisen
Enviado el: lunes, 27 de noviembre de 2006 14:24
Para: informix-list@iiug.org
Asunto: Re: problem with select count(distinct
Clive Eisen wrote:
> Clive Eisen wrote:
>
>> I'm going to try a dbexport and dbimport and will report back.
> No change
>
Sorry to re-comment on my own comment but actually it's WORSE
echo "select count(distinct phone) from phone" | dbaccess data_test
Database selected.
(count)
4348249
Ho hum
--
Clive
_______________________________________________
Informix-list mailing list
Informix-list@iiug.org
http://www.iiug.org/mailman/listinfo/informix-list
what is
10.00.UC5I1
and where did it come from? Is this a fully supported version? Eval is
usually E1, PID drops would be W1 and special builds are normally X1 so
I am unsure what I1 is
Does it reproduce on 10.00.UC5
If it does, or if 10.00.UC5I1 is a fully supported version then
contact your support provider
scottishpoet wrote:
> what is
>
> 10.00.UC5I1
>
> and where did it come from? Is this a fully supported version? Eval is
> usually E1, PID drops would be W1 and special builds are normally X1 so
> I am unsure what I1 is
>
> Does it reproduce on 10.00.UC5
>
> If it does, or if 10.00.UC5I1 is a fully supported version then
> contact your support provider
>
It's the download from the IIUG :-)
Just trying on 10.00.UC3R1TL - 90 day time bombed version from informix.com
--
Clive
scottishpoet wrote:
> the index in that article was not unique either
>
> does the workaround suggested resolve your problem?
>
Quote--
WORKAROUND
Make the distinct column an index by itself.
Example
create index idx2 on table1(col1)
--EndQuote
My column is NOT distinct
Also - way back in my first post I said
1) With such an index I get the WRONG answer
2) Without the index I get the correct answer
Looks like the fix for the composite index problem broke my example
I have no other index on the table
--
Clive
Clive Eisen wrote:
> scottishpoet wrote:
>> the index in that article was not unique either
>>
>> does the workaround suggested resolve your problem?
> Quote--
> WORKAROUND
>
> Make the distinct column an index by itself.
>
> Example
> create index idx2 on table1(col1)
> --EndQuote>
> My column is NOT distinct
I've just had another cup of coffee and re-read this
Please ignore me regarding unique etc etc
The rest of the post however is correct
>
> Also - way back in my first post I said
> 1) With such an index I get the WRONG answer
> 2) Without the index I get the correct answer
>
> Looks like the fix for the composite index problem broke my example
>
> I have no other index on the table
>
--
Clive
We use strictly necessary cookies to make this site work. With your
consent we’d also use optional cookies for analytics and marketing. You can accept all,
reject all, or choose. Read our Cookie Policy.