MySQL Forums
Forum List  »  Performance

Re: Slow query in mysql 5.7.20
Posted by: Øystein Grøvlen
Date: December 18, 2017 01:54AM

Hi,

What does EXPLAIN say if you do "EXPLAIN SELECT STRAIGHT_JOIN ...", and what is the execution time in that case? (STRAIGHT_JOIN will force the join order to be as given in the FROM clause.)

A combined index is better than individual indexes. Hence, an index on air_drs(VOUCHERBASEDR, REFILLPROFILEID) should be better than an index on each individual column.

If columns are arguments to functions, index may not be used. Is the UPPER call really necessary? Could you rather ensure on insert that only upper-case is used? Or could ENUM be used instead of VARCHAR here?

If functions are necessary, consider whether to add a virtual column that can be used for indexing. In your case:

ALTER TABLER table air_drs ADD COLUMN airdate DATE AS (date(airtimestamp)) VIRTUAL;
CREATE INDEX idx ON air_drs(voucherbasedr, refillprofileid, airdate);

This index will make it possible to both limit table access and avoid sorting since rows can be accessed in date order.

I see you use different collations on the two tables. This can often get you into troubles. Try to avoid that.

And why do you have three indexes on air_drs(accounteventid)? One should be enough.

Øystein Grøvlen,
Senior Principal Software Engineer,
MySQL Group, Oracle,
Trondheim, Norway

Options: ReplyQuote


Subject
Views
Written By
Posted
1016
December 17, 2017 07:42AM
512
December 17, 2017 09:51AM
610
December 17, 2017 11:55AM
546
December 17, 2017 01:36PM
520
December 18, 2017 12:33AM
510
December 18, 2017 10:09AM
559
December 17, 2017 11:02AM
Re: Slow query in mysql 5.7.20
828
December 18, 2017 01:54AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.