MySql性能问题与SQL-Server

时间:2015-04-08 16:17:57

标签: mysql sql-server performance database-performance query-performance

我在MSSQLServer 2008R2和MYSQL WorkBench 6.1上创建了一个包含5000万行的表。

我不确定为什么这个查询在MySql上采用16Sec而在SQL-Server采用0秒?

SELECT  avg(speed) FROM tm where RoadId%5=0 and time%3=0;

- 不同的where子句存在性能差异。

-SQL-Server和MySQL都安装在一台配备128 GB Ram和16核CPU的机器上。

ps:这是在SQL-Server上创建表的脚本

CREATE TABLE [dbo].[TM](
    [RoadId] [int] NOT NULL,
    [Date] [smallint] NOT NULL,
    [Time] [tinyint] NOT NULL,
    [VType] [tinyint] NOT NULL,
    [Speed] [tinyint] NOT NULL,
 CONSTRAINT [PK_TM_1] PRIMARY KEY CLUSTERED 
(
    [RoadId] ASC,
    [Date] ASC,
    [Time] ASC,
    [VType] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

和MySQL:

CREATE TABLE `tm` (
  `RoadId` int(11) NOT NULL,
  `Date` smallint(6) NOT NULL,
  `Time` tinyint(3) unsigned NOT NULL,
  `VType` tinyint(3) unsigned NOT NULL,
  `Speed` tinyint(3) unsigned NOT NULL,
  PRIMARY KEY (`RoadId`,`Date`,`Time`,`VType`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

1 个答案:

答案 0 :(得分:1)

SQL Server自动为这种类型的查询实现并行性,而mysql则不然。这基本上意味着SQL将分割表扫描并分析具有多个线程的行。我相信mysql需要对数据进行分区才能实现同样的功能。