I've created a table with 50 million rows on MSSQLServer 2008R2 and MYSQL WorkBench 6.1.
I'm not sure why this query take 16Sec on MySql but 0 Sec on SQL-Server?
SELECT avg(speed) FROM tm where RoadId%5=0 and time%3=0;
-Performance difference exists with different where clauses.
-SQL-Server and MySQL both installed in one machine with 128 GB of Ram and 16 core CPU.
ps: This is script to create table on 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]
and 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;