SQL Server different query performance

I am trying to test the performance of various types of database projects, but I'm not sure if the results I get are correct.

I have two databases with different tables, but they are designed to store the same information.

  • In my first design, I put all my fields in one table.
  • In the second project, I have several tables and you want to use joins to search for my records.

See image for more details:

enter image description here

When I run the query below for the first database, it executes after 0.03 s.

SELECT 
    a.[idPerson], a.[Id], a.[Description], a.[LastName], a.[nme], 
    a.[Email], a.[Phone], a.[grp] 
FROM 
    [Student] a 
WHERE 
    a.[grp] = 'R3PU56' 
    AND a.[nme] = 'tZv5oxqSDEoXPnU' 
    AND a.[Email] = 'gyRpWWCopv'

When I run the query below for the second database, it also executes in 0.03 seconds.

SELECT 
    a.[Id], a.[grp], b.[Email], b.[Phone], 
    c.[Description], c.[LastName], c.[nme] 
FROM 
    [Student2] a 
JOIN 
    [AdvancedPerson2] AS b ON (a.[Id] = b.[Id]) 
JOIN 
    [Person2] AS c ON (a.[Id] = c.[Id]) 
WHERE 
    a.[grp] = 'R3PU56' 
    AND b.[Email] = 'gyRpWWCopv'
    AND c.[nme] = 'tZv5oxqSDEoXPnU' 

, , - . , - ? , ? , - , . Telerik ORM, #.

+4
4

, denormalize table, , DB , , . , , .

, , , Advanced Person 2, ?

+1

, . , .

, . ; , , -, .

+1

, , .

- :

Id (PK) 
PersonId (FK)

Student

Id (PK) 
PersonId (FK)

Person

, . , AdvancedPerson, 1 1.

Id (PK)
FirstName
LastName
Tel
Email
-- other contact type info

Subject

. , .

Id (PK)
TeacherId (FK)
SubjectName

StudentSubject

, .

StudentId (FK)
SubjectId (FK)
0

Which query has the best performance, you need to compare a little more than just the start time. A simple query can simply trigger a statistical update, and that’s not what you want to measure. execute the following code:

SET STATISTICS IO, TIME ON

and run your queries again. This gives you more information about the request.

0
source

Source: https://habr.com/ru/post/1606232/


All Articles