Database Reference
In-Depth Information
Listing 1.1. SQL script defining tables for social network data
Table t_user contains columns with user information, while table t_user_friend simply has
two columns referencing table t_user using a foreign key relation. The primary key and
foreign key columns have indexes for quicker lookup operations, a strategy typically em-
ployed when modeling relational databases.
1.2.1. Querying graph data using MySQL
How would you go about querying relational data? Getting the count for direct friends of a
particularuserisquitestraightforward.Abasic select querysuchasthefollowingwould
do the trick:
select count(distinct uf.*) from t_user_friend uf where uf.user_1 = ?
Note
We're counting the friends in all examples, so we don't overload the CPU or memory by
loading the actual data.
 
Search WWH ::




Custom Search