Database Reference
In-Depth Information
Note
Graph traversals perform significantly better than the equivalent MySQL queries (thou-
sands of times better with traversal depths of 4 and 5). At the same time, the traversal per-
formance does not decrease dramatically with the depth—the traversal at depth 5 is only
0.03 seconds slower than the traversal at depth 2. The performance of the most complex
MySQL queries is more than 10,000 times slower than the simple ones.
But how does this graphing approach scale? To get the answer, let's repeat the experiment
with a data set of 1 million users.
1.4. SQL joins versus graph traversal on a large scale
Forthisexperiment,weusedexactlythesamedatastructuresasbefore;theonlydifference
was the amount of data.
In MySQL we had 1,000,000 records in the t_user table, and approximately 1,000,000 ×
50 = 50,000,000 records in the t_user_friend table. We ran the same four queries against
this data set (friends at depths 2, 3, 4, and 5). Table 1.3 shows the collected results for the
performance of SQL queries in this case.
Table 1.3. The execution times for multiple join queries using a MySQL database engine on a data set of 1 million
users
Depth
Execution time (seconds) for 1 million users
Count result
2
0.016
~2,500
3
30.267
~125,000
4
1,543.505
~600,000
5
Not finished
Comparing these results to the MySQL results for a data set of 1,000 users, you can see
that the performance of the depth 2 query has stayed the same, which can be explained by
the design of the MySQL engine handling table joins efficiently using indexes. Queries at
depths3and4(whichuse3and4 join operations,respectively)demonstratemuchworse
 
Search WWH ::




Custom Search