Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Cartesian queries Expand / Collapse
Author
Message
Posted Thursday, June 17, 2004 3:05 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Monday, April 22, 2013 3:11 PM
Points: 33, Visits: 459

I have an application that regularly passes queries that are cartesian products.  I am trying to get some documentation together to send to the people who use this app so they will understand how bad this is.  I am trying to calculate the number of records that would be produced and want to make sure that I am correct.

For Example:  I see a query like ...

select  B.BANK_SETID, B.BANK_CD, B.BANK_ACCT_KEY, B.PROCESS_INSTANCE
from PS_BUS_UNIT_INTFC A, PS_PAYMENT_TBL B, PS_PYMNT_VCHR_XREF C, PS_VOUCHER D, PS_BANK_ACCT_TBL E, PS_BUS_UNIT_TBL_GL F, PS_BUS_UNIT_TBL_GL H, PS_BU_LED_AP_VW I

There is NO where clause!!  And, one table is referenced twice.  I have no idea why this was built this way.

Here are the number of records in each table:

PS_BUS_UNIT_INTFC has 4 records
PS_PAYMENT_TBL has 74740 records
PS_PYMNT_VCHR_XREF has 145521 records
PS_VOUCHER has 144263 records
PS_BANK_ACCT_TBL has 28 records
PS_BUS_UNIT_TBL_GL has 4 records
PS_BU_LED_AP_VW has 4 records

Since this would produce results of all records of all tables then this query would produce 28,362,348,734,709,280 records.  Correct??  That would be 4*74740*145521*144263*28*4*4=28,362,348,734,709,280

YIKES!!!

Post #121721
Posted Friday, June 18, 2004 1:29 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Thursday, December 20, 2012 12:35 AM
Points: 88, Visits: 29

yep, it's just multiply all the row counts

don't the users notice that their results don't make sense (I'm assuming they don't)?  actually, don't answer that one ...

i've seen in some apps a default behaviour of not allowing this (no on/where clauses) so the user has to deliberately say they want to do a cartesian product

o/w maybe give them prejoined views to work with?

 




Post #121762
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse