d2g
Programmer
- Apr 10, 2005
- 32
Well we are week 3 in our conversion to mysql from mssql. This one we had to rewrite the mssql version to mysql. We are having issues with a few count statments.
this one works fine. and returns results right away.
SELECT DISTINCT iteminformation.slotid1,
iteminformation.slotid2,
iteminformation.slotid6,
iteminformation.defaultpic,
iteminformation.itemnumber,
iteminformation.stockupdated,
iteminformation.manufacturername,
iteminformation.conditionshort
FROM iteminformation, itemlocation
where iteminformation.itemnumber = itemlocation.itemnumber
and iteminformation.companyid = 26773049
and itemlocation.companyid = 26773049
and iteminformation.slottype = 'config'
and iteminformation.retired = 'false'
and (iteminformation.deleterec = 'false' or iteminformation.deleterec is Null)
and (itemlocation.deleterec = 'false' or itemlocation.deleterec is Null)
order by iteminformation.slotid1
As soon as we include our count statement to give us the total paid (as counterpaid)for each item returned performance drops to a crawl and the result takes forever to be returned.
SELECT DISTINCT iteminformation.slotid1,
iteminformation.slotid2,
iteminformation.slotid6,
iteminformation.defaultpic,
iteminformation.itemnumber,
iteminformation.stockupdated,
iteminformation.manufacturername,
iteminformation.conditionshort,
(Select Count(stockid) from itemlocation where iteminformation.companyid = itemlocation.companyid and itemlocation.itemnumber = iteminformation.itemnumber ) as counterpaid
FROM iteminformation, itemlocation
where iteminformation.itemnumber = itemlocation.itemnumber
and iteminformation.companyid = 26773049
and itemlocation.companyid = 26773049
and iteminformation.slottype = 'config'
and iteminformation.retired = 'false'
and (iteminformation.deleterec = 'false' or iteminformation.deleterec is Null)
and (itemlocation.deleterec = 'false' or itemlocation.deleterec is Null)
order by iteminformation.slotid1
I'm thinking it has something to do with the indexes setup in mysql for the itemlocation table. Please advise us to what we should be using for indexes to make this query work efficiently. right now we have the following indexes:
itemlocation indexes
PRIMARY STOCKID UNIQUE
LOTCODE LOTCODE
ASSIGNED ASSIGNED
ITEMNUMBERID COMPANYID,ITEMNUMBER
iteminformation indexes
PRIMARY ID UNIQUE
ID ID UNIQUE
ITEMNUMBERID COMPANYID,ITEMNUMBER
Any help / advice would be great! ~ this originally worked flawless and fast in MS SQL. without any additional indexes.
this one works fine. and returns results right away.
SELECT DISTINCT iteminformation.slotid1,
iteminformation.slotid2,
iteminformation.slotid6,
iteminformation.defaultpic,
iteminformation.itemnumber,
iteminformation.stockupdated,
iteminformation.manufacturername,
iteminformation.conditionshort
FROM iteminformation, itemlocation
where iteminformation.itemnumber = itemlocation.itemnumber
and iteminformation.companyid = 26773049
and itemlocation.companyid = 26773049
and iteminformation.slottype = 'config'
and iteminformation.retired = 'false'
and (iteminformation.deleterec = 'false' or iteminformation.deleterec is Null)
and (itemlocation.deleterec = 'false' or itemlocation.deleterec is Null)
order by iteminformation.slotid1
As soon as we include our count statement to give us the total paid (as counterpaid)for each item returned performance drops to a crawl and the result takes forever to be returned.
SELECT DISTINCT iteminformation.slotid1,
iteminformation.slotid2,
iteminformation.slotid6,
iteminformation.defaultpic,
iteminformation.itemnumber,
iteminformation.stockupdated,
iteminformation.manufacturername,
iteminformation.conditionshort,
(Select Count(stockid) from itemlocation where iteminformation.companyid = itemlocation.companyid and itemlocation.itemnumber = iteminformation.itemnumber ) as counterpaid
FROM iteminformation, itemlocation
where iteminformation.itemnumber = itemlocation.itemnumber
and iteminformation.companyid = 26773049
and itemlocation.companyid = 26773049
and iteminformation.slottype = 'config'
and iteminformation.retired = 'false'
and (iteminformation.deleterec = 'false' or iteminformation.deleterec is Null)
and (itemlocation.deleterec = 'false' or itemlocation.deleterec is Null)
order by iteminformation.slotid1
I'm thinking it has something to do with the indexes setup in mysql for the itemlocation table. Please advise us to what we should be using for indexes to make this query work efficiently. right now we have the following indexes:
itemlocation indexes
PRIMARY STOCKID UNIQUE
LOTCODE LOTCODE
ASSIGNED ASSIGNED
ITEMNUMBERID COMPANYID,ITEMNUMBER
iteminformation indexes
PRIMARY ID UNIQUE
ID ID UNIQUE
ITEMNUMBERID COMPANYID,ITEMNUMBER
Any help / advice would be great! ~ this originally worked flawless and fast in MS SQL. without any additional indexes.