0

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;
6
  • Well those are totally different products and most likely neither of them have been optimized for searching modulo, which quite frankly sounds artificial and not a real case. Commented Apr 8, 2015 at 16:24
  • @JamesZ thanks for your reply, this is real table with 500-1000 million of rows. Commented Apr 8, 2015 at 16:31
  • 1
    If you need modulo a lot, it might be a better idea to calculate into the table, instead of doing it in the search. Commented Apr 8, 2015 at 16:43
  • @JamesZ where clause can be anything so I can't calculate them to a table. Commented Apr 8, 2015 at 16:48
  • 1
    Will you have enough RAM to cache the entire dataset? If not, then this test is bogus because it was cached. Commented Apr 8, 2015 at 20:56

1 Answer 1

1

SQL Server automatically implements parallelism for this type of query, whereas mysql does not. This basically means that SQL will divide up the table scan and analyze rows with multiple threads. I believe mysql requires the data to be partitioned in order to achieve this same functionality.

Sign up to request clarification or add additional context in comments.

1 Comment

Still, 0 seconds sounds fishy. No MySQL will not perform this query in parallel even if PARTITIONed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.