From d4185896f66658bd5ac916ed8e2321d7bdd267b0 Mon Sep 17 00:00:00 2001 From: Andrew McDonnell Date: Sat, 29 Jun 2013 23:27:17 +0930 Subject: [PATCH] Fix for djikstras not working on destid (because of #if 0) same as for bug 1196027 --- mysql-test/suite/oqgraph/basic.result | 245 ++++++++++++++++++++++++++ mysql-test/suite/oqgraph/basic.test | 38 +++- storage/oqgraph/graphcore.cc | 6 - 3 files changed, 278 insertions(+), 11 deletions(-) diff --git a/mysql-test/suite/oqgraph/basic.result b/mysql-test/suite/oqgraph/basic.result index 3aa7325aee7..c6786f0640a 100644 --- a/mysql-test/suite/oqgraph/basic.result +++ b/mysql-test/suite/oqgraph/basic.result @@ -1022,6 +1022,125 @@ latch origid destid weight seq linkid dijkstras 12 11 NULL 0 12 dijkstras 12 11 1 1 10 dijkstras 12 11 1 2 11 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=1; +latch origid destid weight seq linkid +dijkstras 1 NULL 0 4 4 +dijkstras 1 NULL 0 3 3 +dijkstras 1 NULL 0 2 2 +dijkstras 1 NULL 0 1 1 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=2; +latch origid destid weight seq linkid +dijkstras 2 NULL 0 4 4 +dijkstras 2 NULL 0 3 3 +dijkstras 2 NULL 0 2 1 +dijkstras 2 NULL 0 1 2 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=3; +latch origid destid weight seq linkid +dijkstras 3 NULL 0 4 2 +dijkstras 3 NULL 0 3 4 +dijkstras 3 NULL 0 2 1 +dijkstras 3 NULL 0 1 3 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=4; +latch origid destid weight seq linkid +dijkstras 4 NULL 0 4 2 +dijkstras 4 NULL 0 3 1 +dijkstras 4 NULL 0 2 3 +dijkstras 4 NULL 0 1 4 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=5; +latch origid destid weight seq linkid +dijkstras 5 NULL 0 3 7 +dijkstras 5 NULL 0 2 6 +dijkstras 5 NULL 0 1 5 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=6; +latch origid destid weight seq linkid +dijkstras 6 NULL 0 3 7 +dijkstras 6 NULL 0 2 5 +dijkstras 6 NULL 0 1 6 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=7; +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 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=10; +latch origid destid weight seq linkid +dijkstras 10 NULL 0 3 12 +dijkstras 10 NULL 0 2 11 +dijkstras 10 NULL 0 1 10 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=11; +latch origid destid weight seq linkid +dijkstras 11 NULL 0 3 10 +dijkstras 11 NULL 0 2 12 +dijkstras 11 NULL 0 1 11 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=12; +latch origid destid weight seq linkid +dijkstras 12 NULL 0 3 11 +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 +dijkstras NULL 1 1 3 3 +dijkstras NULL 1 1 2 2 +dijkstras NULL 1 0 1 1 +SELECT * FROM graph WHERE latch='dijkstras' AND destid=2; +latch origid destid weight seq linkid +dijkstras NULL 2 3 4 4 +dijkstras NULL 2 2 3 3 +dijkstras NULL 2 1 2 1 +dijkstras NULL 2 0 1 2 +SELECT * FROM graph WHERE latch='dijkstras' AND destid=3; +latch origid destid weight seq linkid +dijkstras NULL 3 2 4 2 +dijkstras NULL 3 1 3 4 +dijkstras NULL 3 1 2 1 +dijkstras NULL 3 0 1 3 +SELECT * FROM graph WHERE latch='dijkstras' AND destid=4; +latch origid destid weight seq linkid +dijkstras NULL 4 3 4 2 +dijkstras NULL 4 2 3 1 +dijkstras NULL 4 1 2 3 +dijkstras NULL 4 0 1 4 +SELECT * FROM graph WHERE latch='dijkstras' AND destid=5; +latch origid destid weight seq linkid +dijkstras NULL 5 1 3 7 +dijkstras NULL 5 1 2 6 +dijkstras NULL 5 0 1 5 +SELECT * FROM graph WHERE latch='dijkstras' AND destid=6; +latch origid destid weight seq linkid +dijkstras NULL 6 2 3 7 +dijkstras NULL 6 1 2 5 +dijkstras NULL 6 0 1 6 +SELECT * FROM graph WHERE latch='dijkstras' AND destid=7; +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 +SELECT * FROM graph WHERE latch='dijkstras' AND destid=10; +latch origid destid weight seq linkid +dijkstras NULL 10 2 3 12 +dijkstras NULL 10 1 2 11 +dijkstras NULL 10 0 1 10 +SELECT * FROM graph WHERE latch='dijkstras' AND destid=11; +latch origid destid weight seq linkid +dijkstras NULL 11 2 3 10 +dijkstras NULL 11 1 2 12 +dijkstras NULL 11 0 1 11 +SELECT * FROM graph WHERE latch='dijkstras' AND destid=12; +latch origid destid weight seq linkid +dijkstras NULL 12 2 3 11 +dijkstras NULL 12 1 2 10 +dijkstras NULL 12 0 1 12 # legacy string number SELECT * FROM graph WHERE latch='1' AND origid=1 AND destid=1; latch origid destid weight seq linkid @@ -1081,6 +1200,125 @@ latch origid destid weight seq linkid 1 12 11 NULL 0 12 1 12 11 1 1 10 1 12 11 1 2 11 +SELECT * FROM graph WHERE latch='1' AND origid=1; +latch origid destid weight seq linkid +1 1 NULL 0 4 4 +1 1 NULL 0 3 3 +1 1 NULL 0 2 2 +1 1 NULL 0 1 1 +SELECT * FROM graph WHERE latch='1' AND origid=2; +latch origid destid weight seq linkid +1 2 NULL 0 4 4 +1 2 NULL 0 3 3 +1 2 NULL 0 2 1 +1 2 NULL 0 1 2 +SELECT * FROM graph WHERE latch='1' AND origid=3; +latch origid destid weight seq linkid +1 3 NULL 0 4 2 +1 3 NULL 0 3 4 +1 3 NULL 0 2 1 +1 3 NULL 0 1 3 +SELECT * FROM graph WHERE latch='1' AND origid=4; +latch origid destid weight seq linkid +1 4 NULL 0 4 2 +1 4 NULL 0 3 1 +1 4 NULL 0 2 3 +1 4 NULL 0 1 4 +SELECT * FROM graph WHERE latch='1' AND origid=5; +latch origid destid weight seq linkid +1 5 NULL 0 3 7 +1 5 NULL 0 2 6 +1 5 NULL 0 1 5 +SELECT * FROM graph WHERE latch='1' AND origid=6; +latch origid destid weight seq linkid +1 6 NULL 0 3 7 +1 6 NULL 0 2 5 +1 6 NULL 0 1 6 +SELECT * FROM graph WHERE latch='1' AND origid=7; +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 +SELECT * FROM graph WHERE latch='1' AND origid=10; +latch origid destid weight seq linkid +1 10 NULL 0 3 12 +1 10 NULL 0 2 11 +1 10 NULL 0 1 10 +SELECT * FROM graph WHERE latch='1' AND origid=11; +latch origid destid weight seq linkid +1 11 NULL 0 3 10 +1 11 NULL 0 2 12 +1 11 NULL 0 1 11 +SELECT * FROM graph WHERE latch='1' AND origid=12; +latch origid destid weight seq linkid +1 12 NULL 0 3 11 +1 12 NULL 0 2 10 +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 +1 NULL 1 1 3 3 +1 NULL 1 1 2 2 +1 NULL 1 0 1 1 +SELECT * FROM graph WHERE latch='1' AND destid=2; +latch origid destid weight seq linkid +1 NULL 2 3 4 4 +1 NULL 2 2 3 3 +1 NULL 2 1 2 1 +1 NULL 2 0 1 2 +SELECT * FROM graph WHERE latch='1' AND destid=3; +latch origid destid weight seq linkid +1 NULL 3 2 4 2 +1 NULL 3 1 3 4 +1 NULL 3 1 2 1 +1 NULL 3 0 1 3 +SELECT * FROM graph WHERE latch='1' AND destid=4; +latch origid destid weight seq linkid +1 NULL 4 3 4 2 +1 NULL 4 2 3 1 +1 NULL 4 1 2 3 +1 NULL 4 0 1 4 +SELECT * FROM graph WHERE latch='1' AND destid=5; +latch origid destid weight seq linkid +1 NULL 5 1 3 7 +1 NULL 5 1 2 6 +1 NULL 5 0 1 5 +SELECT * FROM graph WHERE latch='1' AND destid=6; +latch origid destid weight seq linkid +1 NULL 6 2 3 7 +1 NULL 6 1 2 5 +1 NULL 6 0 1 6 +SELECT * FROM graph WHERE latch='1' AND destid=7; +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 +SELECT * FROM graph WHERE latch='1' AND destid=10; +latch origid destid weight seq linkid +1 NULL 10 2 3 12 +1 NULL 10 1 2 11 +1 NULL 10 0 1 10 +SELECT * FROM graph WHERE latch='1' AND destid=11; +latch origid destid weight seq linkid +1 NULL 11 2 3 10 +1 NULL 11 1 2 12 +1 NULL 11 0 1 11 +SELECT * FROM graph WHERE latch='1' AND destid=12; +latch origid destid weight seq linkid +1 NULL 12 2 3 11 +1 NULL 12 1 2 10 +1 NULL 12 0 1 12 INSERT INTO graph_base(from_id, to_id) VALUES (11,13); INSERT INTO graph_base(from_id, to_id) VALUES (10,14); INSERT INTO graph_base(from_id, to_id) VALUES (14,13); @@ -1146,6 +1384,13 @@ dijkstras 1 NULL 0 2 2 dijkstras 1 NULL 0 1 1 SELECT * FROM graph WHERE latch='dijkstras' AND destid=1; latch origid destid weight seq linkid +dijkstras NULL 1 4 7 18 +dijkstras NULL 1 3 6 17 +dijkstras NULL 1 3 5 16 +dijkstras NULL 1 2 4 4 +dijkstras NULL 1 1 3 3 +dijkstras NULL 1 1 2 2 +dijkstras NULL 1 0 1 1 # Now we add a connection from 4->6 INSERT INTO graph_base (from_id,to_id) VALUES (4,6); # And delete all references to node 5 diff --git a/mysql-test/suite/oqgraph/basic.test b/mysql-test/suite/oqgraph/basic.test index 86cb483d3e0..a02783bf01e 100644 --- a/mysql-test/suite/oqgraph/basic.test +++ b/mysql-test/suite/oqgraph/basic.test @@ -131,6 +131,7 @@ SELECT linkid as `from`, destid as `to` FROM graph where latch='0' and destid = #-- We include 'origid' in the set of reachable nodes i.e. as a 'loop', with weight 0 #-- 'seq' is the counted distance of the search, thus, the loop link will always have seq 1 #-- if there are two reachable neighbours, they will have seq 2,3 and so on +#-- linkid is the other end SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 1; SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 2; SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 3; @@ -500,6 +501,37 @@ SELECT * FROM graph WHERE latch='1' AND origid=11 AND destid=10; SELECT * FROM graph WHERE latch='1' AND origid=11 AND destid=12; SELECT * FROM graph WHERE latch='1' AND origid=12 AND destid=10; SELECT * FROM graph WHERE latch='1' AND origid=12 AND destid=11; +SELECT * FROM graph WHERE latch='1' AND origid=1; +SELECT * FROM graph WHERE latch='1' AND origid=2; +SELECT * FROM graph WHERE latch='1' AND origid=3; +SELECT * FROM graph WHERE latch='1' AND origid=4; +SELECT * FROM graph WHERE latch='1' AND origid=5; +SELECT * FROM graph WHERE latch='1' AND origid=6; +SELECT * FROM graph WHERE latch='1' AND origid=7; +#-- FIXME This is returning one result set, suspect this is a bug...? +#-- https://bugs.launchpad.net/oqgraph/+bug/1196020 +SELECT * FROM graph WHERE latch='1' AND origid=8; +SELECT * FROM graph WHERE latch='1' AND origid=9; +SELECT * FROM graph WHERE latch='1' AND origid=10; +SELECT * FROM graph WHERE latch='1' AND origid=11; +SELECT * FROM graph WHERE latch='1' AND origid=12; +#-- FIXME This is returning one result set, suspect this is a bug...? +#-- https://bugs.launchpad.net/oqgraph/+bug/1196020 +SELECT * FROM graph WHERE latch='1' AND origid=666; +SELECT * FROM graph WHERE latch='1' AND destid=1; +SELECT * FROM graph WHERE latch='1' AND destid=2; +SELECT * FROM graph WHERE latch='1' AND destid=3; +SELECT * FROM graph WHERE latch='1' AND destid=4; +SELECT * FROM graph WHERE latch='1' AND destid=5; +SELECT * FROM graph WHERE latch='1' AND destid=6; +SELECT * FROM graph WHERE latch='1' AND destid=7; +#-- FIXME This is returning one result set, suspect this is a bug...? +#-- https://bugs.launchpad.net/oqgraph/+bug/1196020 +SELECT * FROM graph WHERE latch='1' AND destid=8; +SELECT * FROM graph WHERE latch='1' AND destid=9; +SELECT * FROM graph WHERE latch='1' AND destid=10; +SELECT * FROM graph WHERE latch='1' AND destid=11; +SELECT * FROM graph WHERE latch='1' AND destid=12; #-- What if we add two equally valid two-hop paths? #-- @@ -525,10 +557,7 @@ INSERT INTO graph_base(from_id, to_id) VALUES (10,11); #-- We note is _appears_ to use the lowered valued node id if there are two equal paths SELECT * FROM graph WHERE latch='dijkstras' AND origid=10 AND destid=13; -#-- Unspecified arguments: -#-- If destid unspecified, it returns all possible destinations -#-- Destinations further away are returned first -#-- Note also, weight==0 (as opposed to 1 or NULL in all other cases) +#-- add some extra and check SELECT * FROM graph WHERE latch='dijkstras' AND origid=1; INSERT INTO graph_base(from_id, to_id) VALUES (21,22); SELECT * FROM graph WHERE latch='dijkstras' AND origid=21; @@ -539,7 +568,6 @@ INSERT INTO graph_base(from_id, to_id) VALUES (4,16); SELECT * FROM graph WHERE latch='dijkstras' AND origid=1; INSERT INTO graph_base(from_id, to_id) VALUES (17,18); SELECT * FROM graph WHERE latch='dijkstras' AND origid=1; -#-- If origid unspecified, it returns no result - i.e. origid is mandatory SELECT * FROM graph WHERE latch='dijkstras' AND destid=1; --echo # Now we add a connection from 4->6 diff --git a/storage/oqgraph/graphcore.cc b/storage/oqgraph/graphcore.cc index 7167c1683d5..4c9ae0b88aa 100644 --- a/storage/oqgraph/graphcore.cc +++ b/storage/oqgraph/graphcore.cc @@ -857,9 +857,7 @@ namespace open_query } break; case BREADTH_FIRST | HAVE_DEST: -#ifdef FIXME case DIJKSTRAS | HAVE_DEST: -#endif if ((cursor= new (std::nothrow) stack_cursor(share)) && (orig || dest)) { boost::unordered_map p; @@ -870,7 +868,6 @@ namespace open_query d[ *dest ] = EdgeWeight(); switch (ALGORITHM & op) { -#ifdef FIXME case DIJKSTRAS: dijkstra_shortest_paths_no_init(share->g, *dest, make_lazy_property_map(p, identity_initializer()), @@ -882,17 +879,14 @@ namespace open_query closed_plus(), EdgeWeight(), make_dijkstra_visitor( - make_dijkstra_visitor( make_oqgraph_visit_dist( boost::make_assoc_property_map(p), boost::make_assoc_property_map(d), static_cast(cursor) ) - ) ), make_two_bit_judy_map(get(vertex_index, share->g))); break; -#endif case BREADTH_FIRST: breadth_first_visit(share->g, *dest, Q, make_bfs_visitor(