블로그 이미지
LifeisSimple

calendar

1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31

Notice

2010. 12. 29. 14:23 Brain Trainning/NoSQL

출처 : http://blogs.lessthandot.com/index.php/DataMgmt/DBProgramming/mongodb-vs-sql-server-insert-comparison

내용을 보면 이전 비교에서는 단일 Transaction 으로 하지 않아서 SQL 서버가 느렸지만 하나의 단일 Transaction으로 묶게 되면 로그가 줄어들어 속도가 빨라진다라는 내용인 것 같습니다. 그렇지만 후자의 경우는 실 서비스에서는 일어나지 않죠. 따라서 아무래도 단순 Insert 의 경우는 NoSQL 이 압승인것 같습니다. 

Lee Everest created a post named MongoDB vs. SQL Server - INSERT comparison where he compared inserting 50001 rows with MongoDB vs. SQL Server. So he claims that MongoDB inserts 50001 rows in 30 seconds while the SQL Server one takes 1.5 minutes. Okay so I looked at this SQL Script and can make 2 improvements

First create this table

  1. CREATE TABLE MongoCompare
  2.     (guid UNIQUEIDENTIFIER
  3.     ,VALUE INT
  4.     )
  5. GO

Here is the script he used.

  1. DECLARE @id INT = 1
  2. WHILE (@id < 500001)
  3. BEGIN
  4.     INSERT INTO MongoCompare VALUES (newid(), @id)
  5.     SET @id+=1
  6. END
  7. GO

Now if I was to write that code I would write it with an explicit transaction and I would also use nocount on. So If we do this

  1. SET NOCOUNT ON
  2. BEGIN TRAN
  3. DECLARE @id INT = 1
  4. WHILE (@id < 500001)
  5. BEGIN
  6.     INSERT INTO MongoCompare VALUES (newid(), @id)
  7.     SET @id+=1
  8. END
  9. COMMIT

SQL Server now only takes 6 seconds and you have one atomic block of code, either all succeeds or nothing succeeds.


posted by LifeisSimple