How to speed up sql queries ? Indexes?

前端 未结 3 1345
隐瞒了意图╮
隐瞒了意图╮ 2020-12-01 15:02

I have the following database structure :

create table Accounting
(
  Channel,
  Account
)

create table ChannelMapper
(
  AccountingChannel,
  ShipmentsMark         


        
3条回答
  •  半阙折子戏
    2020-12-01 15:25

    Your JOINS should be the first place to look. The two most obvious candidates for indexes are AccountMapper.AccountingAccount and ChannelMapper.AccountingChannel.

    You should consider indexing Shipments.MarketPlace,Shipments.ShipmentChannel and Shipments.Component as well.

    However, adding indexes increases the workload in maintaining them. While they might give you a performance boost on this query, you might find that updating the tables becomes unacceptably slow. In any case, the MySQL optimiser might decide that a full scan of the table is quicker than accessing it by index.

    Really the only way to do this is to set up the indexes that would appear to give you the best result and then benchmark the system to make sure you're getting the results you want here, whilst not compromising the performance elsewhere. Make good use of the EXPLAIN statement to find out what's going on, and remember that optimisations made by yourself or the optimiser on small tables may not be the same optimisations you'd need on larger ones.

提交回复
热议问题