Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Wrong results with SELECT COUNT(*) FROM t1 INNER JOIN t2
Message
From
28/01/2006 04:54:21
 
 
To
24/01/2006 03:46:17
Rolf Otto
C.I.P.-Kommunal Gmbh
Siegen, Germany
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01089647
Message ID:
01091141
Views:
11
Rolf,
this bug alive inside the code that builds the plan of execution.

If there is no WHERE the optimizer is wrong to build the JOIN condition "AND "
(it seems only uses the first one ?)
A workaround becomes very simple, add a WHERE .T.
CLEAR

*	SET COLLATE TO "DUTCH"
*	SET COLLATE TO "GERMAN"
*	...

* condition 1 : COLLATE not MACHINE
	SET COLLATE TO "GENERAL"

* condition 2 : SET DELETED() ON
SET DELETED ON

*-- Create Tables and Index
CREATE TABLE table1 (field1 C(1), field2 C(1))
INSERT INTO table1 (field1,field2) VALUES("A","1")
INSERT INTO table1 (field1,field2) VALUES("A","2")
INSERT INTO table1 (field1,field2) VALUES("A","3")

* condition 3 : first table can optimize WHERE DELETED()

*INDEX ON field1 FOR NOT DELETED() TAG FIELD1_1

INDEX ON DELETED() TAG deleted1 && BINARY

CREATE TABLE table2 (field1 C(1), field2 C(1))
INSERT INTO table2 (field1,field2) VALUES("A","1")
INSERT INTO table2 (field1,field2) VALUES("B","1")

* condition 4 : SECOND table can optimize  WHERE DELETED()

INDEX ON DELETED() TAG deleted2 BINARY

SYS(3054,11)

* condition 5 : none WHERE clause

*-- Expected recordCount = 1 ; result recordCount = 3  *** USES ONLY table1.field1=table2.field1
SELECT COUNT(*) recordCount FROM table1 INNER JOIN table2 ON ;
table1.field1=table2.field1 AND table1.field2=table2.field2

?
? "LOOK THE PARTIAL !!!!"
* WORKAROUND
SELECT COUNT(*) recordCount FROM table1 INNER JOIN table2 ON ;
table1.field1=table2.field1 AND table1.field2=table2.field2;
WHERE .T.

*-- Expected recordCount = 1 ; result recordCount = 2  *** USES ONLY table1.field2=table2.field2
SELECT COUNT(*) recordCount FROM table1 INNER JOIN table2 ON ;
table1.field2=table2.field2 AND table1.field1=table2.field1

?
? "LOOK THE PARTIAL !!!!"
* WORKAROUND
SELECT COUNT(*) recordCount FROM table1 INNER JOIN table2 ON ;
table1.field2=table2.field2 AND table1.field1=table2.field1;
WHERE .T.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform