SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Cartesian queries


Cartesian queries

Author
Message
Lori B
Lori B
SSC-Enthusiastic
SSC-Enthusiastic (118 reputation)SSC-Enthusiastic (118 reputation)SSC-Enthusiastic (118 reputation)SSC-Enthusiastic (118 reputation)SSC-Enthusiastic (118 reputation)SSC-Enthusiastic (118 reputation)SSC-Enthusiastic (118 reputation)SSC-Enthusiastic (118 reputation)

Group: General Forum Members
Points: 118 Visits: 684

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!!!


Jonathan Tomkins
Jonathan Tomkins
SSC-Enthusiastic
SSC-Enthusiastic (146 reputation)SSC-Enthusiastic (146 reputation)SSC-Enthusiastic (146 reputation)SSC-Enthusiastic (146 reputation)SSC-Enthusiastic (146 reputation)SSC-Enthusiastic (146 reputation)SSC-Enthusiastic (146 reputation)SSC-Enthusiastic (146 reputation)

Group: General Forum Members
Points: 146 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?





Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search