samoht Posted September 4, 2007 Share Posted September 4, 2007 Hello All, I am noticing that some of my pages are taking a few seconds to load, and I have a hunch my queries could be written better to speed things up. One of my problems is that I have a ton of tables for many of my simple queries - here is an example: SELECT i.Name AS ItemName, pd.ItemId as Id, pd.ProductId, pd.Name, pd.PriceRetail, pp.PriceSell, i.ImagetnURL, QtyInStock, pack.PackageType, s.Name as Size FROM product pd, item i, productprice pp, itemfeatures itf, features f, packaging pack, size s, brands b WHERE f.Name = '$pageTitle' AND pd.PackageId = pack.PackageId AND itf.FeatureId = f.FeatureId AND itf.ItemId = i.ItemId AND i.BrandId = b.BrandId AND pd.SizeId = s.SizeId AND pd.ItemId = i.ItemId AND pd.ProductId = pp.ProductId AND ClientPriceCode = 'R1' ORDER BY pd.Name"; Do the multiple "AND" declarations slow things down?? what is a better/ faster way? Thanks for the help, Quote Link to comment https://forums.phpfreaks.com/topic/67910-faster-queries/ Share on other sites More sharing options...
cooldude832 Posted September 4, 2007 Share Posted September 4, 2007 A lot of it depends on your table structure two, what is the nature of this query because I see you are using a lot of constants for the where part. Quote Link to comment https://forums.phpfreaks.com/topic/67910-faster-queries/#findComment-341336 Share on other sites More sharing options...
samoht Posted September 4, 2007 Author Share Posted September 4, 2007 what is the nature of this query because I see you are using a lot of constants for the where part. I'm not sure what you're asking here? Quote Link to comment https://forums.phpfreaks.com/topic/67910-faster-queries/#findComment-341360 Share on other sites More sharing options...
cmgmyr Posted September 4, 2007 Share Posted September 4, 2007 did you try using JOIN's? ...that might help to speed it up. Quote Link to comment https://forums.phpfreaks.com/topic/67910-faster-queries/#findComment-341365 Share on other sites More sharing options...
sayedsohail Posted September 4, 2007 Share Posted September 4, 2007 user inner join, this will definately improve your queries performance. Quote Link to comment https://forums.phpfreaks.com/topic/67910-faster-queries/#findComment-341366 Share on other sites More sharing options...
samoht Posted September 4, 2007 Author Share Posted September 4, 2007 So what is the rule on inner joins? Whenever you pull from the same table with more than two conditionals? Quote Link to comment https://forums.phpfreaks.com/topic/67910-faster-queries/#findComment-341368 Share on other sites More sharing options...
samoht Posted September 4, 2007 Author Share Posted September 4, 2007 the mysql page says; "INNER JOIN and , (comma) are semantically equivalent in the absence of a join condition: both produce a Cartesian product between the specified tables (that is, each and every row in the first table is joined to each and every row in the second table)." So does that mean that I was using INNER JOINS and didn't know it?? Quote Link to comment https://forums.phpfreaks.com/topic/67910-faster-queries/#findComment-341407 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.