3-click count in graph

I work on a (not very) large graph that has about 380 Kb. I wrote a program to count the number of 3 clicks on a graph. Quick example:

List of edges:
A - B
B - C
C - A
C - D

List of cliques:
A - B - C

MySQL table structure:

+-------+------------+------+-----+---------+-------+
| Field | Type       | Null | Key | Default | Extra |
+-------+------------+------+-----+---------+-------+
| v1    | bigint(20) | YES  | MUL | NULL    |       | 
| v2    | bigint(20) | YES  | MUL | NULL    |       | 
+-------+------------+------+-----+---------+-------+

A 3-click is nothing more than a triangle in a graph. I am currently using PHP + MySQL. As expected, this is not fast enough. Is there a way to do this in pure MySQL? (maybe a way to insert all 3-clicks into a table?)

+3
source share
1 answer
SELECT T1.v1, T2.v1, T3.v1 FROM TableName T1, TableName T2, TableName T3
WHERE T1.v1 < T1.v2 AND T2.v1 < T2.v2 AND T3.v1 < T3.v2
AND T1.v1 = T3.v1 AND T1.v2 = T2.v1 AND T2.v2 = T3.v2

. , , , v1 , v2 , . / . .

, node node, .

EDIT: Legend. , , , T3, T1, ! T3.v1 > T3.v2 where, , , , !

+3

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


All Articles