相关疑难解决方法(0)

如何加快SQL查询?指标?

我有以下数据库结构:

create table Accounting
(
  Channel,
  Account
)

create table ChannelMapper
(
  AccountingChannel,
  ShipmentsMarketPlace,
  ShipmentsChannel
)

create table AccountMapper
(
  AccountingAccount,
  ShipmentsComponent
)

create table Shipments
(
   MarketPlace,
   Component,
   ProductGroup,
   ShipmentChannel,
   Amount
 )
Run Code Online (Sandbox Code Playgroud)

我在这些表上运行以下查询,并且我正在尝试优化查询以尽可能快地运行:

 select Accounting.Channel, Accounting.Account, Shipments.MarketPlace
 from Accounting join ChannelMapper on Accounting.Channel = ChannelMapper.AccountingChannel

 join AccountMapper on Accounting.Accounting = ChannelMapper.AccountingAccount
 join Shipments on 
 (
     ChannelMapper.ShipmentsMarketPlace = Shipments.MarketPlace
     and ChannelMapper.AccountingChannel = Shipments.ShipmentChannel
     and AccountMapper.ShipmentsComponent = Shipments.Component
 )
 join (select Component, sum(amount) from Shipment group by component) as Totals
    on …
Run Code Online (Sandbox Code Playgroud)

mysql sql database optimization

10
推荐指数
1
解决办法
3万
查看次数

REGEXP的Mysql优化

在我的慢查询日志中,此查询(使用不同的名称而不是"jack")多次发生.为什么?

Users表有很多字段(超过我选择的这三个字段)和大约40.000行.

select name,username,id from Users where ( name REGEXP '[[:<:]]jack[[:>:]]' ) or ( username REGEXP '[[:<:]]jack[[:>:]]' ) order by name limit 0,5;

id是主要的和自我增量.
name有一个索引.
username有一个独特的索引.

有时需要3秒钟!如果我解释MySQL上的选择,我得到了这个:

select type: SIMPLE
table: Users
type: index
possible keys: NULL
key: name
key len: 452
ref: NULL
rows: 5
extra: Using where
Run Code Online (Sandbox Code Playgroud)

这是我能做的最好的吗?我能解决什么?

regex mysql indexing optimization query-optimization

6
推荐指数
1
解决办法
9653
查看次数