on 09-04-2015 3:29 PM
Hello, I am trying to do a select with joins on a IQ16 server, the query is returning 0 rows when it should be returning 23 rows. If I use a subquery instead of a join, it correctly returns the 23 expected rows.
e.g.
select count(*) from t1, t2 where t1.ID = t2.ID and t2.misc = 'A'
returns 0 rows
select count(*) from t1 where t1.ID in (select t2.ID from t2 where t2.misc = 'A')
returns 23 rows
I can't explain this behaviour. I've checked the datatypes and and data match (thankfully these are very small tables), there are no hidden characters, i.e. I compared select len(ID) from t1 and select len(ID) from t2 and they match. ID is a varchar(30) in both tables. I don't understand.
Any help with this mystery would be appreciated!
Hi David,
- What is the exact IQ version (select @@version) ?
- Check tables consistency :
sp_iqcheckdb 'verify table t1' ;
sp_iqcheckdb 'verify table t2'
- Check current options : sp_iqcheckoptions ;
- If no HG indexes on t1.ID and t2.ID, add them and try again.
Regards,
Tayeb.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have seen this before. It is not clear from your other answers if you have an HG index on each individual column of the join.
e.g. create an HG index on each of T1.ID and T2.ID. Only if they are the only columns already identified as Pkey, Fkey or Akey do you not have to index them, as those are automatically indexed. If the column is part of a composite key, still HG index each separate column.
(You can also add an HG to your search argument if you like).
Can you post a query plan (HTML) with query_plan_after_run = 'off' to see the estimates?
Chris
Ok, finally getting somewhere, but still bewildered. This is what I did:
1. Dropped the primary key of table2 (primary key is a composite of two columns "A" and "B", "A" is used in the original join).
2. Dropped the foreign key constraint on "A"
3. Dropped HG index on "A"
4. Recreated HG index on "A"
5. Added the foreign key constraint on "A"
*Here's where it gets interesting! I RUN the original query, and it returns the expected records!
6. I add the primary key
*I run the original query, and it returns zero records!
I drop the primary key, and the original query returns expected records again.
So it is the existence of this composite primary key which is effecting whether the query works or not. I don't understand why, but at least I've located the issue.
Ok wait, it is working now with the primary key added. I may have confused myself (I was dropping and recreating primary keys, foreign keys, and indexes on two tables). So is the cause of all this because the original HG index on this column was implicitly created when the primary key was created. And when I dropped the primary key, the index, and then created the index, then primary key, the resulting HG index was explicitly created?
So is this a bug in IQ16 then? i.e. the original query should still have worked with implicitly created indexes right?
Yes, this appears to be a bug. We've had similar issues in the past versions (IQ 15) where results would vary based on whether an HG was on the columns or not. I thought we had cleared all this up some time ago.
The PK will likely not present an issue unless it is just a single column PK.
Mark
Have you tried any one field instead of * ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
95 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.