Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SQL:查找子图_Sql_Sql Server_Graph_Subgraph - Fatal编程技术网

SQL:查找子图

SQL:查找子图,sql,sql-server,graph,subgraph,Sql,Sql Server,Graph,Subgraph,我有一个存储在SQL server中的图形网络。图形网络(带标签的、无向的和连通的图形的集合)存储在顶点-边映射方案中(即有两个表..一个用于顶点,一个用于边): 顶点(graphID、vertexID、vertexLabel) 边(graphID、sourceVertex、destinationVertex、edgeLabel) 我正在寻找一种简单的方法来计算这个网络中的特定子图。例如:我想知道这个网络中有多少“A-B-C”的实例:“C-D-A-B-C-E-A-B-C-F”。对于java或C+

我有一个存储在SQL server中的图形网络。图形网络(带标签的、无向的和连通的图形的集合)存储在顶点-边映射方案中(即有两个表..一个用于顶点,一个用于边):

顶点(graphID、vertexID、vertexLabel)

边(graphID、sourceVertex、destinationVertex、edgeLabel)

我正在寻找一种简单的方法来计算这个网络中的特定子图。例如:我想知道这个网络中有多少“A-B-C”的实例:“C-D-A-B-C-E-A-B-C-F”。对于java或C++中如何做到这一点,我有一些想法……但是我不知道如何使用SQL来解决这个问题。有什么想法吗

一点背景:我不是学生……这是我想从事的一个小项目。我做了很多社交媒体分析(在内存中),但很少有针对SQL数据库挖掘图表的经验。

我的想法是创建一个存储过程,它的输入是一个类似于“a-B-C”的字符串或一个预先创建的表,表中的顶点按适当的顺序排列(“a”、“B”、“C”)。因此,你将有一个循环,你应该一步一步地通过路径“a-B-C”。为此,您需要当前步骤上顶点的临时表:
1) 步骤0

3) 循环后

您的结果将存储在#v。因此,子图的数量将为:

select count(*) from #v

谢谢@pkuderov的回答,我将不得不尝试验证它。很抱歉回复太晚!是的..我能够让它工作,但我想在一天结束时,在关系数据库中的图节点上枚举是昂贵的(joins!!)…但是这是一个很好的练习,可以展示关系数据库在处理大型图时的局限性。
@currentLabel = getNextVertexLabel(...)

insert #tempV
select
  vs.*
from #v v
join Edges e on
  e.SourceVertex = v.VertexID
  and e.graphID = v.graphID
join Vertices vs on
  e.destinationVertex = vs.VertexID
  and e.graphID = vs.graphID
where
  vs.vertexLabel = @currentLabel

truncate table #v
insert #v
select * from #tempV

truncate table #tempV
select count(*) from #v