From e87960d346340e1674181dc1fc9686f9131c286e Mon Sep 17 00:00:00 2001 From: Andrew McDonnell Date: Fri, 2 Aug 2013 20:36:04 +0930 Subject: [PATCH] Fix for spurious result when searching for non-existing vertex --- mysql-test/suite/oqgraph/basic.result | 12 ------------ storage/oqgraph/oqgraph_shim.h | 9 +++++++++ 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/mysql-test/suite/oqgraph/basic.result b/mysql-test/suite/oqgraph/basic.result index c6786f0640a..1a9afef0d68 100644 --- a/mysql-test/suite/oqgraph/basic.result +++ b/mysql-test/suite/oqgraph/basic.result @@ -212,7 +212,6 @@ latch origid destid weight seq linkid breadth_first 7 NULL 0 1 7 SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 8; latch origid destid weight seq linkid -breadth_first 8 NULL 0 1 8 SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 9; latch origid destid weight seq linkid breadth_first 9 NULL 0 1 9 @@ -233,7 +232,6 @@ breadth_first 12 NULL 1 2 10 breadth_first 12 NULL 0 1 12 SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 666; latch origid destid weight seq linkid -breadth_first 666 NULL 0 1 666 SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 1 AND weight = 1; latch origid destid weight seq linkid breadth_first 1 NULL 1 3 3 @@ -447,7 +445,6 @@ latch origid destid weight seq linkid breadth_first NULL 7 0 1 7 SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 8; latch origid destid weight seq linkid -breadth_first NULL 8 0 1 8 SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 9; latch origid destid weight seq linkid breadth_first NULL 9 0 1 9 @@ -607,7 +604,6 @@ latch origid destid weight seq linkid 2 7 NULL 0 1 7 SELECT * FROM graph WHERE latch = '2' AND origid = 8; latch origid destid weight seq linkid -2 8 NULL 0 1 8 SELECT * FROM graph WHERE latch = '2' AND origid = 9; latch origid destid weight seq linkid 2 9 NULL 0 1 9 @@ -628,7 +624,6 @@ latch origid destid weight seq linkid 2 12 NULL 0 1 12 SELECT * FROM graph WHERE latch = '2' AND origid = 666; latch origid destid weight seq linkid -2 666 NULL 0 1 666 SELECT * FROM graph WHERE latch = '2' AND origid = 1 AND weight = 1; latch origid destid weight seq linkid 2 1 NULL 1 3 3 @@ -842,7 +837,6 @@ latch origid destid weight seq linkid 2 NULL 7 0 1 7 SELECT * FROM graph WHERE latch = '2' AND destid = 8; latch origid destid weight seq linkid -2 NULL 8 0 1 8 SELECT * FROM graph WHERE latch = '2' AND destid = 9; latch origid destid weight seq linkid 2 NULL 9 0 1 9 @@ -1061,7 +1055,6 @@ latch origid destid weight seq linkid dijkstras 7 NULL 0 1 7 SELECT * FROM graph WHERE latch='dijkstras' AND origid=8; latch origid destid weight seq linkid -dijkstras 8 NULL 0 1 8 SELECT * FROM graph WHERE latch='dijkstras' AND origid=9; latch origid destid weight seq linkid dijkstras 9 NULL 0 1 9 @@ -1082,7 +1075,6 @@ dijkstras 12 NULL 0 2 10 dijkstras 12 NULL 0 1 12 SELECT * FROM graph WHERE latch='dijkstras' AND origid=666; latch origid destid weight seq linkid -dijkstras 666 NULL 0 1 666 SELECT * FROM graph WHERE latch='dijkstras' AND destid=1; latch origid destid weight seq linkid dijkstras NULL 1 2 4 4 @@ -1122,7 +1114,6 @@ latch origid destid weight seq linkid dijkstras NULL 7 0 1 7 SELECT * FROM graph WHERE latch='dijkstras' AND destid=8; latch origid destid weight seq linkid -dijkstras NULL 8 0 1 8 SELECT * FROM graph WHERE latch='dijkstras' AND destid=9; latch origid destid weight seq linkid dijkstras NULL 9 0 1 9 @@ -1239,7 +1230,6 @@ latch origid destid weight seq linkid 1 7 NULL 0 1 7 SELECT * FROM graph WHERE latch='1' AND origid=8; latch origid destid weight seq linkid -1 8 NULL 0 1 8 SELECT * FROM graph WHERE latch='1' AND origid=9; latch origid destid weight seq linkid 1 9 NULL 0 1 9 @@ -1260,7 +1250,6 @@ latch origid destid weight seq linkid 1 12 NULL 0 1 12 SELECT * FROM graph WHERE latch='1' AND origid=666; latch origid destid weight seq linkid -1 666 NULL 0 1 666 SELECT * FROM graph WHERE latch='1' AND destid=1; latch origid destid weight seq linkid 1 NULL 1 2 4 4 @@ -1300,7 +1289,6 @@ latch origid destid weight seq linkid 1 NULL 7 0 1 7 SELECT * FROM graph WHERE latch='1' AND destid=8; latch origid destid weight seq linkid -1 NULL 8 0 1 8 SELECT * FROM graph WHERE latch='1' AND destid=9; latch origid destid weight seq linkid 1 NULL 9 0 1 9 diff --git a/storage/oqgraph/oqgraph_shim.h b/storage/oqgraph/oqgraph_shim.h index 8ccaa2d7617..742791aa006 100644 --- a/storage/oqgraph/oqgraph_shim.h +++ b/storage/oqgraph/oqgraph_shim.h @@ -479,6 +479,15 @@ namespace boost inline optional::vertex_descriptor> find_vertex(oqgraph3::vertex_id id, const oqgraph3::graph& g) { + // Fix for https://bugs.launchpad.net/oqgraph/+bug/1196020 returning vertex even when not in graph + // Psuedocode for fix: + // if count(*) from g->TABLE where source=id or target=id > 0 then return id else return null + oqgraph3::cursor* found = new oqgraph3::cursor(const_cast(&g)); + if (found->seek_to(id, boost::none) && + found->seek_to(boost::none, id)) { + // id is neither a from or a to in a link + return optional::vertex_descriptor>(); + } return id; }