Hi, I’m struggling to find a way to speed up this query"
SELECT DISTINCT hd.hotel AS hotelID, r1.contractName, r1.availToken, r1.contractOffice, r1.supplierDest, r1.hotelCurr, r1.hotel, r1.boardName AS boardName1, r1.roomName AS roomName1, r1.price AS price1, r1.roomCode AS roomCode1, r1.roomTypeCode AS roomTypeCode1, r1.roomTypeChar AS roomTypeChar1, r1.boardCode AS boardCode1, r2.boardName AS boardName2, r2.roomName AS roomName2, r2.price AS price2, r2.roomCode AS roomCode2, r2.roomTypeCode AS roomTypeCode2, r2.roomTypeChar AS roomTypeChar2, r2.boardCode AS boardCode2, r3.boardName AS boardName3, r3.roomName AS roomName3, r3.price AS price3, r3.roomCode AS roomCode3, r3.roomTypeCode AS roomTypeCode3, r3.roomTypeChar AS roomTypeChar3, r3.boardCode AS boardCode3
FROM searchRoomOptions r1
JOIN hotelDetails hd ON hd.code=r1.hotel AND hd.source=2
JOIN searchRoomOptions r2 ON r2.hotel=r1.hotel AND r2.search=r1.search AND r2.adults=2 AND r2.children=0
JOIN searchRoomOptions r3 ON r3.hotel=r1.hotel AND r3.search=r1.search AND r3.adults=2 AND r3.children=0
WHERE r1.search=498853 AND r1.adults=2 AND r1.children=0
ORDER BY r1.hotel
EXPLAIN returns this:
“id”,“select_type”,“table”,“type”,“possible_keys”,"key ",“key_len”,“ref”,“rows”,“Extra”
1,“SIMPLE”,“r1”,“index_merge”,“hotel,adults,children,search “,“search,adults,children”,“4,5,5”,””,94,“Using intersect(search,adults,children); Using where; Using temporary; Using filesort”
1,“SIMPLE”,“hd”,“ref”,“source,code”,“code”,“5”,"testdb.r1.hotel ",2,“Using where”
1,“SIMPLE”,“r3”,“ref”,“hotel,adults,children,search”, “hotel”,“5”,“testdb.hd.code”,7,“Using where”
1,“SIMPLE”,“r2”,“ref”,“hotel,adults,children,search”, “hotel”,“5”,“testdb.r3.hotel”,7,“Using where”
Table definition:
Code:
“Field”,“Type”,“Null”,“Key”,“Default”,“Extra”
“id”,“int(10) unsigned”,“NO”,“PRI”,“”,“auto_increment”
“search”,“int(10) unsigned”,“NO”,“MUL”,“”,“”
“boardName”,“varchar(50)”,“YES”,“”,“”,“”
“roomname”,“varchar(50)”,“YES”,“”,“”,“”
“price”,“float”,“YES”,“”,“0”,“”
“roomCode”,“varchar(40)”,“YES”,“”,“”,“”
“roomTypeChar”,“varchar(20)”,“YES”,“”,“”,“”
“roomTypeCode”,“varchar(20)”,“YES”,“”,“”,“”
“boardCode”,“varchar(20)”,“YES”,“”,“”,“”
“adults”,“int(10) unsigned”,“YES”,“MUL”,“0”,“”
“children”,“int(10) unsigned”,“YES”,“MUL”,“0”,“”
“minadults”,“int(10) unsigned”,“YES”,“”,“0”,“”
“maxadults”,“int(10) unsigned”,“YES”,“”,“0”,“”
“minchildren”,“int(10) unsigned”,“YES”,“”,“0”,“”
“maxchildren”,“int(10) unsigned”,“YES”,“”,“0”,“”
“occupancy”,“int(10) unsigned”,“YES”,“”,“0”,“”
“childage1”,“int(10) unsigned”,“YES”,“”,“0”,“”
“childage2”,“int(10) unsigned”,“YES”,“”,“0”,“”
“childage3”,“int(10) unsigned”,“YES”,“”,“0”,“”
“hotel”,“int(10) unsigned”,“YES”,“MUL”,“0”,“”
“contractName”,“varchar(20)”,“YES”,“”,“”,“”
“availToken”,“varchar(45)”,“YES”,“”,“”,“”
“supplierDest”,“varchar(10)”,“YES”,“”,“”,“”
“contractOffice”,“varchar(10)”,“YES”,“”,“”,“”
“hotelCurr”,“varchar(10)”,“YES”,“”,“”,“”
Any ideas?
P.S. It’s pretty difficult to explain the purpose of the query here, but suffice to say I’m expecting it to return thousands of results. I just need to ensure it’s as fast as it can be.