diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 18:04:16 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 18:04:16 +0000 |
commit | a68fb2d8219f6bccc573009600e9f23e89226a5e (patch) | |
tree | d742d35d14ae816e99293d2b01face30e9f3a46b /storage/oqgraph | |
parent | Initial commit. (diff) | |
download | mariadb-10.6-a68fb2d8219f6bccc573009600e9f23e89226a5e.tar.xz mariadb-10.6-a68fb2d8219f6bccc573009600e9f23e89226a5e.zip |
Adding upstream version 1:10.6.11.upstream/1%10.6.11upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'storage/oqgraph')
82 files changed, 16484 insertions, 0 deletions
diff --git a/storage/oqgraph/CMakeLists.txt b/storage/oqgraph/CMakeLists.txt new file mode 100644 index 00000000..e725f971 --- /dev/null +++ b/storage/oqgraph/CMakeLists.txt @@ -0,0 +1,71 @@ +set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") + +SET(CPACK_RPM_oqgraph-engine_PACKAGE_SUMMARY "OQGraph storage engine for MariaDB" PARENT_SCOPE) +SET(CPACK_RPM_oqgraph-engine_PACKAGE_DESCRIPTION "The Open Query GRAPH computation engine, or OQGRAPH as the engine itself is called, +allows you to handle hierarchies (tree structures) and complex graphs +(nodes having many connections in several directions). +It is intended to be used for retrieving hierarchical information, such as those used for graphs, +routes or social relationships, in plain SQL." PARENT_SCOPE) + +MACRO(CHECK_OQGRAPH) +MESSAGE(STATUS "Configuring OQGraph") +FIND_PACKAGE(Boost 1.40.0) +SET_PACKAGE_PROPERTIES(Boost PROPERTIES + PURPOSE "Required for the OQGraph storage engine" + TYPE OPTIONAL +) +IF(NOT Boost_FOUND) + MESSAGE(STATUS "Boost not found. OQGraph will not be compiled") + SET(OQGRAPH_OK 0 CACHE INTERNAL "") + RETURN() +ENDIF() +INCLUDE_DIRECTORIES(BEFORE ${Boost_INCLUDE_DIRS}) + +FIND_PACKAGE(Judy) +SET_PACKAGE_PROPERTIES(Judy PROPERTIES + PURPOSE "Required for the OQGraph storage engine" + TYPE OPTIONAL +) +IF(NOT Judy_FOUND) + MESSAGE(STATUS "Judy not found. OQGraph will not be compiled") + SET(OQGRAPH_OK 0 CACHE INTERNAL "") + RETURN() +ENDIF() +INCLUDE_DIRECTORIES(${Judy_INCLUDE_DIR}) +SET(OQGRAPH_OK 1) +ENDMACRO() + +IF(PLUGIN_OQGRAPH STREQUAL "NO") + RETURN() +ENDIF() + +IF(NOT DEFINED OQGRAPH_OK) + CHECK_OQGRAPH() + IF (NOT OQGRAPH_OK) + MESSAGE(STATUS "Requisites for OQGraph not met. OQGraph will not be compiled") + ENDIF() +ENDIF() + +IF(NOT OQGRAPH_OK) + RETURN() +ENDIF() + +ADD_DEFINITIONS(-DHAVE_OQGRAPH) +IF(MSVC) + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc") + # Fix problem with judy not finding inttypes.h on Windows: + ADD_DEFINITIONS(-DJU_WIN) +ELSE(MSVC) + # Fix lp bug 1221555 with -fpermissive, so that errors in gcc 4.7 become warnings for the time being + STRING(REPLACE "-fno-exceptions" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated -fno-strict-aliasing -fpermissive") +ENDIF(MSVC) + +ADD_DEFINITIONS(-DBOOST_NO_RTTI=1 -DBOOST_NO_TYPEID=1 -DBOOST_DISABLE_ASSERTS=1) +MYSQL_ADD_PLUGIN(oqgraph ha_oqgraph.cc graphcore.cc graphcore-graph.cc + oqgraph_shim.cc oqgraph_thunk.cc oqgraph_judy.cc + STORAGE_ENGINE + MODULE_ONLY + RECOMPILE_FOR_EMBEDDED + COMPONENT oqgraph-engine + LINK_LIBRARIES ${Judy_LIBRARIES}) diff --git a/storage/oqgraph/README b/storage/oqgraph/README new file mode 100644 index 00000000..b92601ec --- /dev/null +++ b/storage/oqgraph/README @@ -0,0 +1,33 @@ +OQGraph storage engine v3 +Copyright (C) 2007-2014 Arjen G Lentz & Antony T Curtis for Open Query, & Andrew McDonnell + +The Open Query GRAPH engine (OQGRAPH) is a computation engine allowing +hierarchies and more complex graph structures to be handled in a +relational fashion. In a nutshell, tree structures and +friend-of-a-friend style searches can now be done using standard SQL +syntax, and results joined onto other tables. + +Based on a concept by Arjen Lentz +v3 implementation by Antony Curtis, Arjen Lentz, Andrew McDonnell +For more information, documentation, support, enhancement engineering, +see http://openquery.com/graph or contact graph@openquery.com + +INSTALLATION + +OQGraph requires at least version 1.40.0 of the Boost Graph library. To +obtain a copy of the Boost library, see http://www.boost.org/ +This can be obtained in Debian Wheezy by `apt-get install libboost-graph-dev` + +OQGraph requires libjudy - http://judy.sourceforge.net/ +This can be obtained in Debian Wheezy by `apt-get install libjudy-dev` + +BUILD (example) + +cd path/to/maria/source +mkdir build # use symlink to scratch +cd build +CONFIGURE="-DWITH_EXTRA_CHARSETS=complex -DWITH_PLUGIN_ARIA=1 -DWITH_READLINE=1 -DWITH_SSL=bundled -DWITH_MAX=1 -DWITH_EMBEDDED_SERVER=1" +cmake .. $CONFIGURE +make -j5 +mysql-test-run --suite oqgraph + diff --git a/storage/oqgraph/cmake/FindJudy.cmake b/storage/oqgraph/cmake/FindJudy.cmake new file mode 100644 index 00000000..d9ecfdc4 --- /dev/null +++ b/storage/oqgraph/cmake/FindJudy.cmake @@ -0,0 +1,67 @@ +# - Try to find Judy. +# +# Additionally, on Windows, this module reads hints about search locations from variables: +# JUDY_ROOT - Preferred installation prefix +# +# To build Judy on Windows: (Tested with judy-1.0.5) +# +# * Download the sources tarball from http://sourceforge.net/projects/judy/ +# * Extract the source +# * Win32: open the Visual Studio C++ Express 2010 command prompt and navigate to the src/ directory. +# Then execute: build.bat +# * Win64: open the Windows SDK 7.1 Command Prompt and navigate to the src/ directory +# Then execute: build.bat +# * Run the mariadb build with JUDY_ROOT=path\to\judy +# +# Once done this will define +# +# Judy_FOUND - system has Judy +# Judy_INCLUDE_DIR - the Judy include directory +# Judy_LIBRARIES - Link these to use Judy +# Judy_DEFINITIONS - Compiler switches required for using Judy + +IF(MSVC) + # For now, assume Judy built according to the above instructions + if (NOT "$ENV{JUDY_ROOT}" STREQUAL "") + # Avoid passing backslashes to _Boost_FIND_LIBRARY due to macro re-parsing. + string(REPLACE "\\" "/" Judy_INCLUDE_DIR_search $ENV{JUDY_ROOT}/src) + string(REPLACE "\\" "/" Judy_LIBRARIES_search $ENV{JUDY_ROOT}/src) + endif() +ELSE(MSVC) + IF (Judy_INCLUDE_DIR AND Judy_LIBRARIES) + SET(Judy_FIND_QUIETLY TRUE) + ENDIF (Judy_INCLUDE_DIR AND Judy_LIBRARIES) +ENDIF(MSVC) + +FIND_PATH(Judy_INCLUDE_DIR Judy.h PATHS ${Judy_INCLUDE_DIR_search}) +FIND_LIBRARY(Judy_LIBRARIES Judy PATHS ${Judy_LIBRARIES_search}) + +IF (Judy_INCLUDE_DIR AND Judy_LIBRARIES) + SET(Judy_FOUND TRUE) +ELSE (Judy_INCLUDE_DIR AND Judy_LIBRARIES) + SET(Judy_FOUND FALSE) + if (MSVC) + MESSAGE(STATUS "How to build Judy on Windows:") + MESSAGE(STATUS "1. Download the source tarball from http://sourceforge.net/projects/judy/") + IF (CMAKE_SIZEOF_VOID_P EQUAL 8) + MESSAGE(STATUS "2. Extract the source, open the Visual Studio command prompt and navigate to the src/ directory.") + ELSE (CMAKE_SIZEOF_VOID_P EQUAL 8) + MESSAGE(STATUS "2. Extract the source, open the Windows SDK 7.1 Command Prompt and navigate to the src/ directory.") + ENDIF (CMAKE_SIZEOF_VOID_P EQUAL 8) + MESSAGE(STATUS "3. Execute the command: 'build'") + MESSAGE(STATUS "4. Rerun this cmake with the environment variable: 'set JUDY_ROOT=x:\\path\\to\\judy'") + endif(MSVC) +ENDIF (Judy_INCLUDE_DIR AND Judy_LIBRARIES) + +IF (Judy_FOUND) + IF (NOT Judy_FIND_QUIETLY) + MESSAGE(STATUS "Found libjudy: ${Judy_LIBRARIES}") + ENDIF (NOT Judy_FIND_QUIETLY) +ELSE (Judy_FOUND) + IF (Judy_FIND_REQUIRED) + MESSAGE(FATAL_ERROR "Could NOT find libjudy") + ENDIF (Judy_FIND_REQUIRED) +ENDIF (Judy_FOUND) + +MARK_AS_ADVANCED(Judy_INCLUDE_DIR Judy_LIBRARIES) + diff --git a/storage/oqgraph/graphcore-config.h b/storage/oqgraph/graphcore-config.h new file mode 100644 index 00000000..01c4b8b2 --- /dev/null +++ b/storage/oqgraph/graphcore-config.h @@ -0,0 +1,40 @@ +/* Copyright (C) 2007-2013 Arjen G Lentz & Antony T Curtis for Open Query + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */ + +/* ====================================================================== + Open Query Graph Computation Engine, based on a concept by Arjen Lentz + v3 implementation by Antony Curtis, Arjen Lentz, Andrew McDonnell + For more information, documentation, support, enhancement engineering, + see http://openquery.com/graph or contact graph@openquery.com + ====================================================================== +*/ +#ifndef oq_graphcore_config_h_ +#define oq_graphcore_config_h_ + +#define BOOST_ALL_NO_LIB 1 +#define BOOST_NO_RTTI 1 +#define BOOST_NO_TYPEID 1 +#define BOOST_NO_HASH 1 +#define BOOST_NO_SLIST 1 + +#ifdef DBUG_OFF +#define NDEBUG 1 +#endif + +#include <boost/config.hpp> + +#endif + diff --git a/storage/oqgraph/graphcore-graph.cc b/storage/oqgraph/graphcore-graph.cc new file mode 100644 index 00000000..e82448c2 --- /dev/null +++ b/storage/oqgraph/graphcore-graph.cc @@ -0,0 +1,26 @@ +/* Copyright (C) 2007-2013 Arjen G Lentz & Antony T Curtis for Open Query + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */ + +/* ====================================================================== + Open Query Graph Computation Engine, based on a concept by Arjen Lentz + v3 implementation by Antony Curtis, Arjen Lentz, Andrew McDonnell + For more information, documentation, support, enhancement engineering, + see http://openquery.com/graph or contact graph@openquery.com + ====================================================================== +*/ + +#include "graphcore-graph.h" + diff --git a/storage/oqgraph/graphcore-graph.h b/storage/oqgraph/graphcore-graph.h new file mode 100644 index 00000000..1bed07e2 --- /dev/null +++ b/storage/oqgraph/graphcore-graph.h @@ -0,0 +1,166 @@ +/* Copyright (C) 2007-2013 Arjen G Lentz & Antony T Curtis for Open Query + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */ + +/* ====================================================================== + Open Query Graph Computation Engine, based on a concept by Arjen Lentz + v3 implementation by Antony Curtis, Arjen Lentz, Andrew McDonnell + For more information, documentation, support, enhancement engineering, + see http://openquery.com/graph or contact graph@openquery.com + ====================================================================== +*/ + +#ifndef oq_graphcore_graph_h_ +#define oq_graphcore_graph_h_ + +#include "oqgraph_shim.h" + +#include <boost/graph/two_bit_color_map.hpp> + +namespace boost +{ + typedef oqgraph3::graph Graph; + + template<typename IndexMap = identity_property_map> + struct two_bit_judy_map + { + typedef typename property_traits<IndexMap>::key_type key_type; + typedef two_bit_color_type value_type; + typedef void reference; + typedef read_write_property_map_tag category; + + open_query::judy_bitset msb; + open_query::judy_bitset lsb; + IndexMap index; + + two_bit_judy_map(const IndexMap& i) + : index(i) + { } + + friend two_bit_color_type get( + const two_bit_judy_map<IndexMap>& pm, + typename property_traits<IndexMap>::key_type key) + { + typename property_traits<IndexMap>::value_type i = get(pm.index, key); + return two_bit_color_type((2*int(pm.msb.test(i))) | int(pm.lsb.test(i))); + } + + friend void put( + two_bit_judy_map<IndexMap>& pm, + typename property_traits<IndexMap>::key_type key, + two_bit_color_type value) + { + typename property_traits<IndexMap>::value_type i = get(pm.index, key); + pm.msb.set(i, value & 2); + pm.lsb.set(i, value & 1); + } + }; + + template<typename IndexMap> + inline two_bit_judy_map<IndexMap> + make_two_bit_judy_map(const IndexMap& index) + { + return two_bit_judy_map<IndexMap>(index); + } + + + template <typename Type> + struct default_lazy_initializer + { + template <typename Key> + Type operator()(const Key&) const { return Type(); } + }; + + template <typename Type> + struct copy_initializer + { + copy_initializer(const Type& value) : _(value) { } + template <typename Key> + const Type& operator()(const Key&) const { return _; } + const Type& _; + }; + + template <typename Type> + copy_initializer<Type> make_copy_initializer(const Type& value) + { return copy_initializer<Type>(value); } + + + template <typename Type> + struct value_initializer + { + value_initializer(const Type& value) : _(value) { } + template <typename Key> + const Type& operator()(const Key&) const { return _; } + const Type _; + }; + + template <typename Type> + value_initializer<Type> make_value_initializer(const Type& value) + { return value_initializer<Type>(value); } + + + template <typename Key> + struct identity_initializer + { + const Key& operator()(const Key& _) const { return _; } + }; + + template <class Container, class Generator> + struct lazy_property_map + { + typedef lazy_property_map<Container, Generator> self; + typedef typename Container::key_type key_type; + typedef typename Container::value_type::second_type value_type; + typedef value_type& reference; + typedef lvalue_property_map_tag category; + + lazy_property_map(Container& m, Generator g= Generator()) + : _m(m) + , _g(g) + { } + + reference operator[](const key_type& k) const + { + typename Container::iterator found= _m.find(k); + if (_m.end() == found) + { + found= _m.insert(std::make_pair(k, _g(k))).first; + } + return found->second; + } + + void set(const key_type& k, const value_type& v) + { _m[k] = v; } + + friend reference get(const self& s, const key_type& k) + { + return s[k]; + } + + friend void put(self& s, const key_type& k, const value_type& v) + { s.set(k, v); } + + Container& _m; + Generator _g; + }; + + template <class Container, class Generator> + lazy_property_map<Container, Generator> + make_lazy_property_map(Container& c, Generator g) + { return lazy_property_map<Container, Generator>(c, g); } + +} + +#endif diff --git a/storage/oqgraph/graphcore-types.h b/storage/oqgraph/graphcore-types.h new file mode 100644 index 00000000..0032e859 --- /dev/null +++ b/storage/oqgraph/graphcore-types.h @@ -0,0 +1,42 @@ +/* Copyright (C) 2007-2013 Arjen G Lentz & Antony T Curtis for Open Query + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */ + +/* ====================================================================== + Open Query Graph Computation Engine, based on a concept by Arjen Lentz + v3 implementation by Antony Curtis, Arjen Lentz, Andrew McDonnell + For more information, documentation, support, enhancement engineering, + see http://openquery.com/graph or contact graph@openquery.com + ====================================================================== +*/ + +#ifndef oq_graphcore_types_h_ +#define oq_graphcore_types_h_ + +namespace open_query +{ + + typedef unsigned long long VertexID; + typedef double EdgeWeight; + +} + + +// Forward defs from mariadb itself! +class Field; +typedef struct TABLE TABLE; +class THD; + +#endif diff --git a/storage/oqgraph/graphcore.cc b/storage/oqgraph/graphcore.cc new file mode 100644 index 00000000..4554e092 --- /dev/null +++ b/storage/oqgraph/graphcore.cc @@ -0,0 +1,1227 @@ +/* Copyright (C) 2007-2013 Arjen G Lentz & Antony T Curtis for Open Query + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */ + +/* ====================================================================== + Open Query Graph Computation Engine, based on a concept by Arjen Lentz + v3 implementation by Antony Curtis, Arjen Lentz, Andrew McDonnell + For more information, documentation, support, enhancement engineering, + see http://openquery.com/graph or contact graph@openquery.com + ====================================================================== +*/ + +#include <string.h> +#include <cstdlib> + +#include "graphcore-graph.h" + +#include <set> +#include <stack> + +#include <boost/property_map/property_map.hpp> + +#include <boost/graph/breadth_first_search.hpp> +#include <boost/graph/dijkstra_shortest_paths.hpp> +#include <boost/graph/iteration_macros.hpp> +#include <boost/graph/reverse_graph.hpp> +#include <boost/graph/graph_utility.hpp> + +#include "graphcore.h" + +#include <boost/unordered_map.hpp> +#include <boost/version.hpp> + +using namespace open_query; +using namespace boost; + +static const row empty_row = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + +extern "C" const char* const oqgraph_boost_version= BOOST_LIB_VERSION; + +namespace open_query +{ + + typedef graph_traits<Graph>::vertex_descriptor Vertex; + typedef graph_traits<Graph>::edge_descriptor Edge; + + typedef std::list<std::pair<Vertex,optional<EdgeWeight> > > shortest_path_list; + typedef shortest_path_list::iterator shortest_path_iterator; + + template<typename ID, typename IDMap> + class id_equals_t + { + public: + id_equals_t(ID id, IDMap map) + : m_id(id), m_map(map) + { } + template<typename V> + bool operator()(V u) const + { + return m_map[u] == m_id; + } + private: + ID m_id; + IDMap m_map; + }; + + template<typename ID, typename IDMap> + inline id_equals_t<ID,IDMap> + id_equals(ID id, IDMap idmap) + { + return id_equals_t<ID,IDMap>(id, idmap); + } + + template<typename T, typename Graph> + class target_equals_t + { + public: + target_equals_t(T target, Graph &g) + : m_target(target), m_g(g) + { } + template<typename V> + bool operator()(V u) const + { + return target(u, m_g) == m_target; + } + private: + T m_target; + Graph &m_g; + }; + + template<typename T, typename Graph> + inline target_equals_t<T,Graph> + target_equals(T target, Graph &g) + { + return target_equals_t<T,Graph>(target, g); + } + + template<typename T, typename Graph> + class source_equals_t + { + public: + source_equals_t(T source, Graph &g) + : m_source(source), m_g(g) + { } + template<typename V> + bool operator()(V u) const + { + return source(u, m_g) == m_source; + } + private: + T m_source; + Graph &m_g; + }; + + template<typename T, typename Graph> + inline source_equals_t<T,Graph> + source_equals(T source, Graph &g) + { + return source_equals_t<T,Graph>(source, g); + } + + struct reference + { + int m_flags; + int m_sequence; + Vertex m_vertex; + Edge m_edge; + EdgeWeight m_weight; + + enum + { + HAVE_SEQUENCE = 1, + HAVE_WEIGHT = 2, + HAVE_EDGE = 4, + }; + + // Force assignment operator, so we can trace through in the debugger + inline reference& operator=(const reference& ref) + { + m_flags = ref.m_flags; + m_sequence = ref.m_sequence; + m_vertex = ref.m_vertex; + m_edge = ref.m_edge; + m_weight = ref.m_weight; + return *this; + } + + inline reference() + : m_flags(0), m_sequence(0), + m_vertex(graph_traits<Graph>::null_vertex()), + m_edge(), m_weight(0) + { } + + inline reference(int s, Edge e) + : m_flags(HAVE_SEQUENCE | HAVE_EDGE), m_sequence(s), + m_vertex(graph_traits<Graph>::null_vertex()), + m_edge(e), m_weight(0) + { } + + inline reference(int s, Vertex v, const optional<Edge> &e, + const optional<EdgeWeight> &w) + : m_flags(HAVE_SEQUENCE | (w ? HAVE_WEIGHT : 0) | (e ? HAVE_EDGE : 0)), + m_sequence(s), m_vertex(v), + m_edge(), m_weight(0) + { + if (w) m_weight= *w; + if (e) m_edge= *e; + } + + inline reference(int s, Vertex v, Edge e, EdgeWeight w) + : m_flags(HAVE_SEQUENCE | HAVE_WEIGHT | HAVE_EDGE), + m_sequence(s), m_vertex(v), m_edge(e), m_weight(w) + { } + + inline reference(int s, Vertex v, EdgeWeight w) + : m_flags(HAVE_SEQUENCE | HAVE_WEIGHT), + m_sequence(s), m_vertex(v), m_edge(), m_weight(w) + { } + + inline reference(int s, Vertex v) + : m_flags(HAVE_SEQUENCE), m_sequence(s), m_vertex(v), m_edge(), + m_weight(0) + { } + + optional<int> sequence() const + { + if (m_flags & HAVE_SEQUENCE) + { + return m_sequence; + } + return optional<int>(); + } + + optional<Vertex> vertex() const + { + if (m_vertex != graph_traits<Graph>::null_vertex()) + return m_vertex; + return optional<Vertex>(); + } + + optional<Edge> edge() const + { + if (m_flags & HAVE_EDGE) + return m_edge; + return optional<Edge>(); + }; + + optional<EdgeWeight> weight() const + { + if (m_flags & HAVE_WEIGHT) + return m_weight; + return optional<EdgeWeight>(); + } + }; +} + +namespace open_query { + class GRAPHCORE_INTERNAL oqgraph_share + { + public: + Graph g; + + optional<Vertex> find_vertex(VertexID id) const; + optional<Edge> find_edge(Vertex, Vertex) const; + + inline oqgraph_share( + TABLE* table, + Field* origid, + Field* destid, + Field* weight) throw() + : g(table, origid, destid, weight) + { } + inline ~oqgraph_share() + { } + }; + + class GRAPHCORE_INTERNAL oqgraph_cursor + { + public: + oqgraph_share *const share; + + inline oqgraph_cursor(oqgraph_share *arg) + : share(arg) + { } + virtual ~oqgraph_cursor() + { } + + virtual int fetch_row(const row &, row&) = 0; + virtual int fetch_row(const row &, row&, const reference&) = 0; + virtual void current(reference& ref) const = 0; + }; +} + +namespace open_query { + class GRAPHCORE_INTERNAL stack_cursor : public oqgraph_cursor + { + private: + optional<EdgeWeight> no_weight; + public: + int sequence; + std::stack<reference> results; + reference last; + + inline stack_cursor(oqgraph_share *arg) + : oqgraph_cursor(arg), no_weight(), sequence(0), results(), last() + { } + + int fetch_row(const row &, row&); + int fetch_row(const row &, row&, const reference&); + + void current(reference& ref) const + { + ref= last; + } + }; + + class GRAPHCORE_INTERNAL vertices_cursor : public oqgraph_cursor + { + typedef graph_traits<Graph>::vertex_iterator vertex_iterator; + + size_t position; + reference last; + public: + inline vertices_cursor(oqgraph_share *arg) + : oqgraph_cursor(arg), position(0) + { } + + int fetch_row(const row &, row&); + int fetch_row(const row &, row&, const reference&); + + void current(reference& ref) const + { + ref= last; + } + + }; + + class GRAPHCORE_INTERNAL edges_cursor : public oqgraph_cursor + { + typedef graph_traits<Graph>::edge_iterator edge_iterator; + typedef edge_iterator::difference_type edge_difference; + + edge_difference position; + reference last; + public: + inline edges_cursor(oqgraph_share *arg) + : oqgraph_cursor(arg), position(0), last() + { } + + int fetch_row(const row &, row&); + int fetch_row(const row &, row&, const reference&); + + void current(reference& ref) const + { + ref= last; + } + }; + + template <typename P, typename D> + struct GRAPHCORE_INTERNAL oqgraph_visit_leaves + : public base_visitor< oqgraph_visit_leaves<P,D> > + { + typedef on_finish_vertex event_filter; + + oqgraph_visit_leaves(const P& p, const D& d, + stack_cursor *cursor) + : seq(0), m_cursor(*cursor), m_p(p), m_d(d) + { assert(cursor); } + + template<class T, class Graph> + void operator()(T u, Graph &g) + { + typename graph_traits<Graph>::out_edge_iterator ei, ei_end; + boost::tuples::tie(ei, ei_end) = out_edges(u, g); + if (ei == ei_end) + { + m_cursor.results.push(reference(++seq, u, m_d[ u ])); + } + } + private: + int seq; + stack_cursor &m_cursor; + P m_p; + D m_d; + }; + + template <typename P, typename D> + oqgraph_visit_leaves<P,D> + make_oqgraph_visit_leaves(const P& p, const D& d, stack_cursor *cursor) + { return oqgraph_visit_leaves<P,D>(p, d, cursor); } + + + template <typename P, typename D> + struct GRAPHCORE_INTERNAL oqgraph_visit_dist + : public base_visitor< oqgraph_visit_dist<P,D> > + { + typedef on_finish_vertex event_filter; + + oqgraph_visit_dist(const P& p, const D& d, + stack_cursor *cursor) + : seq(0), m_cursor(*cursor), m_p(p), m_d(d) + { assert(cursor); } + + template<class T, class Graph> + void operator()(T u, Graph &g) + { + m_cursor.results.push(reference(++seq, u, m_d[ u ])); + } + private: + int seq; + stack_cursor &m_cursor; + P m_p; + D m_d; + }; + + template <typename P, typename D> + oqgraph_visit_dist<P,D> + make_oqgraph_visit_dist(const P& p, const D& d, stack_cursor *cursor) + { return oqgraph_visit_dist<P,D>(p, d, cursor); } + + + template<bool record_weight, typename goal_filter, typename P> + struct GRAPHCORE_INTERNAL oqgraph_goal + : public base_visitor<oqgraph_goal<record_weight,goal_filter,P> > + { + typedef goal_filter event_filter; + + oqgraph_goal(const Vertex& goal, const P& p, + stack_cursor *cursor) + : m_goal(goal), m_cursor(*cursor), m_p(p) + { assert(cursor); } + + template<class T, class Graph> + void operator()(T u, Graph &g) + { + if (u == m_goal) + { + int seq= 0; + + for (Vertex q, v= u;; v = q, seq++) + if ((q= m_p[ v ]) == v) + break; + + for (Vertex v= u;; u= v) + { + optional<Edge> edge; + optional<EdgeWeight> weight; + v= m_p[ u ]; + if (record_weight && u != v) + { + typename graph_traits<Graph>::out_edge_iterator ei, ei_end; + for (boost::tuples::tie(ei, ei_end)= out_edges(v, g); ei != ei_end; ++ei) + { + if (target(*ei, g) == u) + { + edge= *ei; + weight= get(boost::edge_weight, g, *ei); + break; + } + } + } + else if (u != v) + weight= 1; + m_cursor.results.push(reference(seq--, u, edge, weight)); + if (u == v) + break; + } + throw this; + } + } + + private: + Vertex m_goal; + stack_cursor &m_cursor; + P m_p; + }; + + template<bool record_weight, typename goal_filter, typename P> + oqgraph_goal<record_weight, goal_filter, P> + make_oqgraph_goal(const Vertex& goal, const P& p, stack_cursor *cursor) + { return oqgraph_goal<record_weight, goal_filter, P>(goal, p, cursor); } + +} + +namespace open_query +{ + inline oqgraph::oqgraph(oqgraph_share *arg) throw() + : share(arg), cursor(0), lastRetainedLatch(NULL) + { } + + inline oqgraph::~oqgraph() throw() + { + std::free(lastRetainedLatch); + delete cursor; + } + + unsigned oqgraph::edges_count() const throw() + { + return num_edges(share->g); + } + + unsigned oqgraph::vertices_count() const throw() + { + return num_vertices(share->g); + } + + THD* oqgraph::get_thd() { return share->g.get_table_thd(); } + void oqgraph::set_thd(THD* thd) { share->g.set_table_thd(thd); } + + oqgraph* oqgraph::create(oqgraph_share *share) throw() + { + assert(share != NULL); + return new (std::nothrow) oqgraph(share); + } + + oqgraph_share* oqgraph::create( + TABLE* table, + Field* origid, + Field* destid, + Field* weight) throw() + { + return new (std::nothrow) oqgraph_share( + table, origid, destid, weight); + } + + optional<Edge> + oqgraph_share::find_edge(Vertex orig, Vertex dest) const + { + if (in_degree(dest, g) >= out_degree(orig, g)) + { + graph_traits<Graph>::out_edge_iterator ei, ei_end; + tie(ei, ei_end)= out_edges(orig, g); + if ((ei= std::find_if(ei, ei_end, target_equals(dest, g))) != ei_end) + return *ei; + } + else + { + graph_traits<Graph>::in_edge_iterator ei, ei_end; + tie(ei, ei_end)= in_edges(dest, g); + if ((ei= std::find_if(ei, ei_end, source_equals(orig, g))) != ei_end) + return *ei; + } + return optional<Edge>(); + } + + optional<Vertex> + oqgraph_share::find_vertex(VertexID id) const + { + return oqgraph3::find_vertex(id, g); + } + +#if 0 + int oqgraph::delete_all() throw() + { + share->g.clear(); + return 0; + } + + int oqgraph::insert_edge( + VertexID orig_id, VertexID dest_id, EdgeWeight weight, bool replace) throw() + { + optional<Vertex> orig, dest; + optional<Edge> edge; + bool inserted= 0; + + if (weight < 0) + return INVALID_WEIGHT; + if (!(orig= share->find_vertex(orig_id))) + { + try + { + orig= add_vertex(VertexInfo(orig_id), share->g); + if (orig == graph_traits<Graph>::null_vertex()) + return CANNOT_ADD_VERTEX; + } + catch (...) + { + return CANNOT_ADD_VERTEX; + } + } + if (!(dest= share->find_vertex(dest_id))) + { + try + { + dest= add_vertex(VertexInfo(dest_id), share->g); + if (dest == graph_traits<Graph>::null_vertex()) + return CANNOT_ADD_VERTEX; + } + catch (...) + { + return CANNOT_ADD_VERTEX; + } + } + if (!(edge= share->find_edge(*orig, *dest))) + { + try + { + tie(edge, inserted)= add_edge(*orig, *dest, share->g); + if (!inserted) + return CANNOT_ADD_EDGE; + } + catch (...) + { + return CANNOT_ADD_EDGE; + } + } + else + { + if (!replace) + return DUPLICATE_EDGE; + } + share->weightmap[*edge]= weight; + return OK; + } + + int oqgraph::delete_edge(current_row_st) throw() + { + reference ref; + if (cursor) + return EDGE_NOT_FOUND; + cursor->current(ref); + optional<Edge> edge; + if (!(edge= ref.edge())) + return EDGE_NOT_FOUND; + Vertex orig= source(*edge, share->g); + Vertex dest= target(*edge, share->g); + remove_edge(*edge, share->g); + if (!degree(orig, share->g)) + remove_vertex(orig, share->g); + if (!degree(dest, share->g)) + remove_vertex(dest, share->g); + return OK; + } + + int oqgraph::modify_edge(current_row_st, + VertexID *orig_id, VertexID *dest_id, EdgeWeight *weight, + bool replace) throw() + { + if (!cursor) + return EDGE_NOT_FOUND; + reference ref; + cursor->current(ref); + optional<Edge> edge; + if (!(edge= ref.edge())) + return EDGE_NOT_FOUND; + if (weight && *weight < 0) + return INVALID_WEIGHT; + + optional<Vertex> orig= source(*edge, share->g), + dest= target(*edge, share->g); + + bool orig_neq= orig_id ? get(boost::vertex_index, share->g, *orig) != *orig_id : 0; + bool dest_neq= dest_id ? get(boost::vertex_index, share->g, *dest) != *dest_id : 0; + + if (orig_neq || dest_neq) + { + optional<Edge> new_edge; + if (orig_neq && !(orig= share->find_vertex(*orig_id))) + { + try + { + orig= add_vertex(VertexInfo(*orig_id), share->g); + if (orig == graph_traits<Graph>::null_vertex()) + return CANNOT_ADD_VERTEX; + } + catch (...) + { + return CANNOT_ADD_VERTEX; + } + } + if (dest_neq && !(dest= share->find_vertex(*dest_id))) + { + try + { + dest= add_vertex(VertexInfo(*dest_id), share->g); + if (dest == graph_traits<Graph>::null_vertex()) + return CANNOT_ADD_VERTEX; + } + catch (...) + { + return CANNOT_ADD_VERTEX; + } + } + if (!(new_edge= share->find_edge(*orig, *dest))) + { + try + { + bool inserted; + tie(new_edge, inserted)= add_edge(*orig, *dest, share->g); + if (!inserted) + return CANNOT_ADD_EDGE; + } + catch (...) + { + return CANNOT_ADD_EDGE; + } + } + else + { + if (!replace) + return DUPLICATE_EDGE; + } + share->weightmap[*new_edge]= share->weightmap[*edge]; + remove_edge(*edge, share->g); + edge= new_edge; + } + if (weight) + share->weightmap[*edge]= *weight; + return OK; + } + + int oqgraph::modify_edge( + VertexID orig_id, VertexID dest_id, EdgeWeight weight) throw() + { + optional<Vertex> orig, dest; + optional<Edge> edge; + + if (weight < 0) + return INVALID_WEIGHT; + if (!(orig= share->find_vertex(orig_id))) + return EDGE_NOT_FOUND; + if (!(dest= share->find_vertex(dest_id))) + return EDGE_NOT_FOUND; + if (!(edge= share->find_edge(*orig, *dest))) + return EDGE_NOT_FOUND; + share->weightmap[*edge]= weight; + return OK; + } + + int oqgraph::delete_edge(VertexID orig_id, VertexID dest_id) throw() + { + optional<Vertex> orig, dest; + optional<Edge> edge; + + if (!(orig= share->find_vertex(orig_id))) + return EDGE_NOT_FOUND; + if (!(dest= share->find_vertex(dest_id))) + return EDGE_NOT_FOUND; + if (!(edge= share->find_edge(*orig, *dest))) + return EDGE_NOT_FOUND; + remove_edge(*edge, share->g); + if (!degree(*orig, share->g)) + remove_vertex(*orig, share->g); + if (!degree(*dest, share->g)) + remove_vertex(*dest, share->g); + return OK; + } +#endif + + // THIS IS UGLY - refactor later + // Update the retained latch string value, for later retrieval by + // fetch_row() as a workaround for making sure we return the correct + // string to match the latch='' clause + // (This is a hack for mariadb mysql compatibility) + // IT SHOULD ONLY BE CALLED IMMEIDATELY BEFORE search)( + void oqgraph::retainLatchFieldValue(const char *retainedLatch) + { + // attempting to use std::string broke lots of stuff + // Probably more efficient to use mysql String class, FIXME later + if (lastRetainedLatch) { std::free(lastRetainedLatch); lastRetainedLatch = NULL; } + if (retainedLatch) { lastRetainedLatch = strdup(retainedLatch); } + } + + // Because otherwise things can happen and we havent freed a resource since the end of the last query... + void oqgraph::release_cursor() throw() { + if (share->g._cursor) { + // Make sure refs all freed before deleting share->g._cursor + share->g._rnd_cursor = 0; + delete cursor; cursor = 0; + delete share->g._cursor; + share->g._cursor = NULL; + } + row_info= empty_row; + } + + + int oqgraph::search(int *latch, VertexID *orig_id, VertexID *dest_id) throw() + { + optional<Vertex> orig, dest; + int op= 0, seq= 0; + + delete cursor; cursor= 0; + row_info= empty_row; + if ((row_info.latch_indicator= latch)) { + op= ALGORITHM & (row_info.latch= *latch); + row_info.latchStringValue = lastRetainedLatch; + row_info.latchStringValueLen = strlen(lastRetainedLatch); + } + if ((row_info.orig_indicator= orig_id) && (op|= HAVE_ORIG)) + orig= share->find_vertex((row_info.orig= *orig_id)); + if ((row_info.dest_indicator= dest_id) && (op|= HAVE_DEST)) + dest= share->find_vertex((row_info.dest= *dest_id)); + //try + //{ + switch (op) + { + case NO_SEARCH | HAVE_ORIG | HAVE_DEST: + case NO_SEARCH | HAVE_ORIG: + if ((cursor= new (std::nothrow) stack_cursor(share)) && orig) + { + graph_traits<Graph>::out_edge_iterator ei, ei_end; + for (boost::tuples::tie(ei, ei_end)= out_edges(*orig, share->g); ei != ei_end; ++ei) + { + Vertex v= target(*ei, share->g); + static_cast<stack_cursor*>(cursor)-> + results.push(reference(++seq, v, *ei, + get(boost::edge_weight, share->g, *ei))); + } + } + /* fall through */ + case NO_SEARCH | HAVE_DEST: + if ((op & HAVE_DEST) && + (cursor || (cursor= new (std::nothrow) stack_cursor(share))) && + dest) + { + graph_traits<Graph>::in_edge_iterator ei, ei_end; + for (boost::tuples::tie(ei, ei_end)= in_edges(*dest, share->g); ei != ei_end; ++ei) + { + Vertex v= source(*ei, share->g); + static_cast<stack_cursor*>(cursor)-> + results.push(reference(++seq, v, *ei, + get(boost::edge_weight, share->g, *ei))); + } + } + break; + + case NO_SEARCH: + cursor= new (std::nothrow) vertices_cursor(share); + break; + + case DIJKSTRAS | HAVE_ORIG | HAVE_DEST: + if ((cursor= new (std::nothrow) stack_cursor(share)) && orig && dest) + { + boost::unordered_map<Vertex, Vertex> p; + boost::unordered_map<Vertex, EdgeWeight> d; + p[ *orig ]= *orig; + d[ *orig ] = EdgeWeight(); + try + { + dijkstra_shortest_paths_no_init(share->g, *orig, + make_lazy_property_map(p, identity_initializer<Vertex>()), + make_lazy_property_map(d, value_initializer<EdgeWeight>( + (std::numeric_limits<EdgeWeight>::max)())), + get(edge_weight, share->g), + get(vertex_index, share->g), + std::less<EdgeWeight>(), + closed_plus<EdgeWeight>(), + EdgeWeight(), + make_dijkstra_visitor( + make_oqgraph_goal<true, on_finish_vertex>( + *dest, + boost::make_assoc_property_map(p), + static_cast<stack_cursor*>(cursor) + ) + ), + make_two_bit_judy_map(get(vertex_index, share->g))); + } + catch (...) + { /* printf("found\n"); */ } + } + break; + + case BREADTH_FIRST | HAVE_ORIG | HAVE_DEST: + if ((cursor= new (std::nothrow) stack_cursor(share)) && orig && dest) + { + boost::unordered_map<Vertex, Vertex> p; + boost::queue<Vertex> Q; + p[ *orig ]= *orig; + try + { + breadth_first_visit(share->g, *orig, Q, + make_bfs_visitor( + std::make_pair( + record_predecessors( + boost::make_assoc_property_map(p), + on_tree_edge() + ), + make_oqgraph_goal<false, on_discover_vertex>( + *dest, boost::make_assoc_property_map(p), + static_cast<stack_cursor*>(cursor) + ) + ) + ), + make_two_bit_judy_map(get(vertex_index, share->g))); + } + catch (...) + { /* printf("found\n"); */ } + } + break; + + case DIJKSTRAS | HAVE_ORIG: + case BREADTH_FIRST | HAVE_ORIG: + case LEAVES | HAVE_ORIG: + if ((cursor= new (std::nothrow) stack_cursor(share)) && (orig || dest)) + { + boost::unordered_map<Vertex, Vertex> p; + boost::unordered_map<Vertex, EdgeWeight> d; + boost::queue<Vertex> Q; + p[ *orig ]= *orig; + d[ *orig ] = EdgeWeight(); + switch (ALGORITHM & op) + { + case DIJKSTRAS: + dijkstra_shortest_paths_no_init(share->g, *orig, + make_lazy_property_map(p, identity_initializer<Vertex>()), + make_lazy_property_map(d, value_initializer<EdgeWeight>( + (std::numeric_limits<EdgeWeight>::max)())), + get(edge_weight, share->g), + get(vertex_index, share->g), + std::less<EdgeWeight>(), + closed_plus<EdgeWeight>(), + EdgeWeight(), + make_dijkstra_visitor( + make_oqgraph_visit_dist( + boost::make_assoc_property_map(p), + boost::make_assoc_property_map(d), + static_cast<stack_cursor*>(cursor) + ) + ), + make_two_bit_judy_map(get(vertex_index, share->g))); + break; + case BREADTH_FIRST: + breadth_first_visit(share->g, *orig, Q, + make_bfs_visitor( + std::make_pair( + record_predecessors( + boost::make_assoc_property_map(p), + on_tree_edge() + ), + std::make_pair( + record_distances( + boost::make_assoc_property_map(d), + on_tree_edge() + ), + make_oqgraph_visit_dist( + boost::make_assoc_property_map(p), + boost::make_assoc_property_map(d), + static_cast<stack_cursor*>(cursor) + ) + )) + ), + make_two_bit_judy_map(get(vertex_index, share->g))); + break; + case LEAVES: + breadth_first_visit(share->g, *orig, Q, + make_bfs_visitor( + std::make_pair( + record_predecessors( + boost::make_assoc_property_map(p), + on_tree_edge() + ), + std::make_pair( + record_distances( + boost::make_assoc_property_map(d), + on_tree_edge() + ), + make_oqgraph_visit_leaves( + boost::make_assoc_property_map(p), + boost::make_assoc_property_map(d), + static_cast<stack_cursor*>(cursor) + ) + )) + ), + make_two_bit_judy_map(get(vertex_index, share->g))); + break; + default: + abort(); + } + } + break; + case BREADTH_FIRST | HAVE_DEST: + case DIJKSTRAS | HAVE_DEST: + case LEAVES | HAVE_DEST: + if ((cursor= new (std::nothrow) stack_cursor(share)) && (orig || dest)) + { + boost::unordered_map<Vertex, Vertex> p; + boost::unordered_map<Vertex, EdgeWeight> d; + boost::queue<Vertex> Q; + const reverse_graph<Graph> r(share->g); + p[ *dest ]= *dest; + d[ *dest ] = EdgeWeight(); + switch (ALGORITHM & op) + { + case DIJKSTRAS: + dijkstra_shortest_paths_no_init(r, *dest, + make_lazy_property_map(p, identity_initializer<Vertex>()), + make_lazy_property_map(d, value_initializer<EdgeWeight>( + (std::numeric_limits<EdgeWeight>::max)())), + get(edge_weight, r), + get(vertex_index, r), + std::less<EdgeWeight>(), + closed_plus<EdgeWeight>(), + EdgeWeight(), + make_dijkstra_visitor( + make_oqgraph_visit_dist( + boost::make_assoc_property_map(p), + boost::make_assoc_property_map(d), + static_cast<stack_cursor*>(cursor) + ) + ), + make_two_bit_judy_map(get(vertex_index, r))); + break; + case BREADTH_FIRST: + breadth_first_visit(r, *dest, Q, + make_bfs_visitor( + std::make_pair( + record_predecessors( + boost::make_assoc_property_map(p), + on_tree_edge() + ), + std::make_pair( + record_distances( + boost::make_assoc_property_map(d), + on_tree_edge() + ), + make_oqgraph_visit_dist( + boost::make_assoc_property_map(p), + boost::make_assoc_property_map(d), + static_cast<stack_cursor*>(cursor) + ) + )) + ), + make_two_bit_judy_map(get(vertex_index, r))); + break; + case LEAVES: + breadth_first_visit(r, *dest, Q, + make_bfs_visitor( + std::make_pair( + record_predecessors( + boost::make_assoc_property_map(p), + on_tree_edge() + ), + std::make_pair( + record_distances( + boost::make_assoc_property_map(d), + on_tree_edge() + ), + make_oqgraph_visit_leaves( + boost::make_assoc_property_map(p), + boost::make_assoc_property_map(d), + static_cast<stack_cursor*>(cursor) + ) + )) + ), + make_two_bit_judy_map(get(vertex_index, r))); + break; + default: + abort(); + } + } + break; + default: + break; + } + return 0; + //} + //catch (...) + //{ + // return MISC_FAIL; + //} + } + + int oqgraph::fetch_row(row& result) throw() + { + if (!cursor) + return NO_MORE_DATA; + return cursor->fetch_row(row_info, result); + } + + int oqgraph::fetch_row(row& result, const void* ref_ptr) throw() + { + const reference &ref= *(const reference*) ref_ptr; + if (!cursor) + return NO_MORE_DATA; + return cursor->fetch_row(row_info, result, ref); + } + + void oqgraph::row_ref(void *ref_ptr) throw() + { + reference &ref= *(reference*) ref_ptr; + if (cursor) + cursor->current(ref); + else + // Beware: internally this eventually causes a swap by intrusive_ptr, so ref must be initialised to sane on all cases + ref = reference(); + } + + void oqgraph::init_row_ref(void *ref_ptr) throw() + { + // Placement new will cause a constructor to be called avoiding the assignment operator of intrusive_ptr + // This doesnt allocate any memory, assumes ref_ptr is the correct size(!) + new (ref_ptr) reference(); + } + + int oqgraph::random(bool scan) throw() + { + if (scan || !cursor) + { + delete cursor; cursor= 0; + if (!(cursor= new (std::nothrow) edges_cursor(share))) + return MISC_FAIL; + } + row_info= empty_row; + return OK; + } + + void oqgraph::free(oqgraph *graph) throw() + { + delete graph; + } + + void oqgraph::free(oqgraph_share *graph) throw() + { + delete graph; + } + + const size_t oqgraph::sizeof_ref= sizeof(reference); +} + +int stack_cursor::fetch_row(const row &row_info, row &result) +{ + if (!results.empty()) + { + if (int res= fetch_row(row_info, result, results.top())) + return res; + results.pop(); + return oqgraph::OK; + } + else + { + last= reference(); + return oqgraph::NO_MORE_DATA; + } +} + +int stack_cursor::fetch_row(const row &row_info, row &result, + const reference &ref) +{ + last= ref; + if (last.vertex()) + { + optional<int> seq; + optional<EdgeWeight> w; + optional<Vertex> v; + result= row_info; + if ((result.seq_indicator= static_cast<bool>(seq= last.sequence()))) + result.seq= *seq; + if ((result.link_indicator= static_cast<bool>(v= last.vertex()))) + result.link= get(boost::vertex_index, share->g, *v); + if ((result.weight_indicator= static_cast<bool>(w= last.weight()))) + result.weight= *w; + return oqgraph::OK; + } + else + return oqgraph::NO_MORE_DATA; +} + + +int vertices_cursor::fetch_row(const row &row_info, row &result) +{ + vertex_iterator it, end; + reference ref; + size_t count= position; + for (tie(it, end)= vertices(share->g); count && it != end; ++it, --count) + ; + if (it != end) + ref= reference(position+1, *it); + if (int res= fetch_row(row_info, result, ref)) + return res; + position++; + return oqgraph::OK; +} + +int vertices_cursor::fetch_row(const row &row_info, row &result, + const reference &ref) +{ + last= ref; + optional<Vertex> v= last.vertex(); + result= row_info; + if (v) + { + result.link_indicator= 1; + result.link= get(boost::vertex_index, share->g, *v); +#ifdef DISPLAY_VERTEX_INFO + result.seq_indicator= 1; + if ((result.seq= degree(*v, share->g))) + { + EdgeWeight weight= 0; + graph_traits<Graph>::in_edge_iterator iei, iei_end; + for (tie(iei, iei_end)= in_edges(*v, share->g); iei != iei_end; ++iei) + weight+= get(boost::edge_weight, share->g, *iei); + graph_traits<Graph>::out_edge_iterator oei, oei_end; + for (tie(oei, oei_end)= out_edges(*v, share->g); oei != oei_end; ++oei) + weight+= get(boost::edge_weight, share->g, *oei); + result.weight_indicator= 1; + result.weight= weight / result.seq; + } +#endif + return oqgraph::OK; + } + else + return oqgraph::NO_MORE_DATA; +} + +int edges_cursor::fetch_row(const row &row_info, row &result) +{ + edge_iterator it, end; + reference ref; + tie(it, end)= edges(share->g); + it+= position; + if (it != end) + ref= reference(position+1, *it); + if (int res= fetch_row(row_info, result, ref)) + return res; + ++position; + return oqgraph::OK; +} + +int edges_cursor::fetch_row(const row &row_info, row &result, + const reference &ref) +{ + optional<Edge> edge; + if ((edge= (last= ref).edge())) + { + result= row_info; + result.orig_indicator= result.dest_indicator= result.weight_indicator= 1; + + oqgraph3::vertex_id orig = get(boost::vertex_index, share->g, source( *edge, share->g ) ); + oqgraph3::vertex_id dest = get(boost::vertex_index, share->g, target( *edge, share->g ) ); + + // bug 796647c - may be symptomatic of a bigger problem with representation + // but origid and destid can be -1 indicating no such record, NULL? but oqgraph3::vertex_id + // seems to resolve to VertexID (unsigned) in row + // in any case we should check for errors (-1) in origid... because all edges have at least one vertex by definition + if (orig == (oqgraph3::vertex_id)-1 && dest == (oqgraph3::vertex_id)-1) { + // Select * from graph; -- when backing store is empty (bug MDEV-5891) + return oqgraph::NO_MORE_DATA; + } + // assert( ! ((size_t)orig == (size_t)-1 && (size_t)dest == (size_t)-1)); + // indicates we havent handle a HA_ERR_RECORD_DELETED somewhere + + result.orig= orig; + result.dest= dest; + result.weight= get(boost::edge_weight, share->g, *edge); + return oqgraph::OK; + } + return oqgraph::NO_MORE_DATA; +} + +namespace boost { + GRAPHCORE_INTERNAL void throw_exception(std::exception const&) + { + abort(); + } +} diff --git a/storage/oqgraph/graphcore.h b/storage/oqgraph/graphcore.h new file mode 100644 index 00000000..3414cb24 --- /dev/null +++ b/storage/oqgraph/graphcore.h @@ -0,0 +1,144 @@ +/* Copyright (C) 2007-2013 Arjen G Lentz & Antony T Curtis for Open Query + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */ + +/* ====================================================================== + Open Query Graph Computation Engine, based on a concept by Arjen Lentz + v3 implementation by Antony Curtis, Arjen Lentz, Andrew McDonnell + For more information, documentation, support, enhancement engineering, + see http://openquery.com/graph or contact graph@openquery.com + ====================================================================== +*/ + +#ifndef oq_graphcore_h_ +#define oq_graphcore_h_ + +/* #define GRAPHCORE_INTERNAL __attribute__((visibility("hidden"))) */ +#define GRAPHCORE_INTERNAL + +#include "graphcore-types.h" + +namespace open_query +{ + class oqgraph_share; + class oqgraph_cursor; + + struct row + { + bool latch_indicator; + bool orig_indicator; + bool dest_indicator; + bool weight_indicator; + bool seq_indicator; + bool link_indicator; + + int latch; + const char* latchStringValue; // workaround for when latch is a Varchar + int latchStringValueLen; + VertexID orig; + VertexID dest; + EdgeWeight weight; + unsigned seq; + VertexID link; + }; + + class oqgraph + { + oqgraph_share *const share; + oqgraph_cursor *cursor; + row row_info; + + inline oqgraph(oqgraph_share*) throw(); + inline ~oqgraph() throw(); + public: + + // Integer operation flags + enum { + NO_SEARCH = 0, + DIJKSTRAS = 1, + BREADTH_FIRST = 2, + NUM_SEARCH_OP = 3, + LEAVES = 4, + + ALGORITHM = 0x0ffff, + HAVE_ORIG = 0x10000, + HAVE_DEST = 0x20000, + }; + + enum error_code + { + OK= 0, + NO_MORE_DATA, + EDGE_NOT_FOUND, + INVALID_WEIGHT, + DUPLICATE_EDGE, + CANNOT_ADD_VERTEX, + CANNOT_ADD_EDGE, + MISC_FAIL + }; + + struct current_row_st {}; + static inline current_row_st current_row() + { return current_row_st(); } + + unsigned vertices_count() const throw(); + unsigned edges_count() const throw(); + + int delete_all(void) throw(); + + int insert_edge(VertexID, VertexID, EdgeWeight, bool=0) throw(); + int modify_edge(VertexID, VertexID, EdgeWeight) throw(); + int delete_edge(VertexID, VertexID) throw(); + + int modify_edge(current_row_st, + VertexID*, VertexID*, EdgeWeight*, bool=0) throw(); + int delete_edge(current_row_st) throw(); + + int replace_edge(VertexID orig, VertexID dest, EdgeWeight weight) throw() + { return insert_edge(orig, dest, weight, true); } + + // Update the retained latch string value, for later retrieval by + // fetch_row() as a workaround for making sure we return the correct + // string to match the latch='' clause + // (This is a hack for mariadb mysql compatibility) + // IT SHOULD ONLY BE CALLED IMMEIDATELY BEFORE search)( + void retainLatchFieldValue(const char *retainedLatch); + + int search(int*, VertexID*, VertexID*) throw(); + int random(bool) throw(); + + int fetch_row(row&) throw(); + int fetch_row(row&, const void*) throw(); + void row_ref(void*) throw(); + void init_row_ref(void*) throw(); + + static oqgraph* create(oqgraph_share*) throw(); + static oqgraph_share *create(TABLE*,Field*,Field*,Field*) throw(); + + THD* get_thd(); + void set_thd(THD*); + + static void free(oqgraph*) throw(); + static void free(oqgraph_share*) throw(); + + void release_cursor() throw(); + + static const size_t sizeof_ref; + private: + char *lastRetainedLatch; + }; + +} +#endif diff --git a/storage/oqgraph/ha_oqgraph.cc b/storage/oqgraph/ha_oqgraph.cc new file mode 100644 index 00000000..9bc4b333 --- /dev/null +++ b/storage/oqgraph/ha_oqgraph.cc @@ -0,0 +1,1389 @@ +/* Copyright (C) 2007-2015 Arjen G Lentz & Antony T Curtis for Open Query + Copyright (C) 2013-2015 Andrew McDonnell + Copyright (C) 2014 Sergei Golubchik + Portions of this file copyright (C) 2000-2006 MySQL AB + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */ + +/* ====================================================================== + Open Query Graph Computation Engine, based on a concept by Arjen Lentz + v3 implementation by Antony Curtis, Arjen Lentz, Andrew McDonnell + For more information, documentation, support, enhancement engineering, + see http://openquery.com/graph or contact graph@openquery.com + ====================================================================== +*/ + +/* + Changelog since 10.0.13 + ----------------------- + * Removed compatibility hacks for 5.5.32 and 10.0.4. + I expect no issues building oqgraph into Mariadb 5.5.40 but I think the better approach is maintain a separate fork / patches. + * Added status variable to report if verbose debug is on + * Fixed handling of connection thread changed, the apparent root cause of + MDEV-6282, MDEV-6345 and MDEV-6784 + +*/ + +#ifdef USE_PRAGMA_IMPLEMENTATION +#pragma implementation // gcc: Class implementation +#endif + +#include <my_global.h> +#define MYSQL_SERVER 1 // to have THD +/* For the moment, include code to deal with integer latches. + * I have wrapped it with this #ifdef to make it easier to find and remove in the future. + */ +#define RETAIN_INT_LATCH_COMPATIBILITY // for the time being, recognise integer latches to simplify upgrade. + +#include <mysql/plugin.h> +#include <mysql_version.h> +#include "ha_oqgraph.h" +#include "graphcore.h" +#include <sql_error.h> +#include <sql_class.h> +#include <table.h> +#include <field.h> +#include <key.h> +#include <unireg.h> +#include <my_dbug.h> + +// Uncomment this for extra debug, but expect a performance hit in large queries +//#define VERBOSE_DEBUG +#ifdef VERBOSE_DEBUG +#else +#undef DBUG_PRINT +#define DBUG_PRINT(x,y) +#endif + +#ifdef RETAIN_INT_LATCH_COMPATIBILITY +/* In normal operation, no new tables using an integer latch can be created, + * but they can still be used if they already exist, to allow for upgrades. + * + * However to ensure the legacy function is properly tested, we add a + * server variable "oggraph_allow_create_integer_latch" which if set to TRUE + * allows new engine tables to be created with integer latches. + */ + +static my_bool g_allow_create_integer_latch = FALSE; +#endif + +using namespace open_query; + +static const LEX_CSTRING empty_lex_cstring= {"", 0}; + +// Table of varchar latch operations. +// In the future this needs to be refactactored to live somewhere else +struct oqgraph_latch_op_table { const char *key; int latch; }; +static const oqgraph_latch_op_table latch_ops_table[] = { + { "", oqgraph::NO_SEARCH } , // suggested by Arjen, use empty string instead of no_search + { "dijkstras", oqgraph::DIJKSTRAS } , + { "breadth_first", oqgraph::BREADTH_FIRST } , + { "leaves", oqgraph::LEAVES }, + { NULL, -1 } +}; + +static uint32 findLongestLatch() { + int len = 0; + for (const oqgraph_latch_op_table* k=latch_ops_table; k && k->key; k++) { + int s = strlen(k->key); + if (s > len) { + len = s; + } + } + return len; +} + +const char *oqlatchToCode(int latch) { + for (const oqgraph_latch_op_table* k=latch_ops_table; k && k->key; k++) { + if (k->latch == latch) { + return k->key; + } + } + return "unknown"; +} + +struct ha_table_option_struct +{ + const char *table_name; + const char *origid; // name of the origin id column + const char *destid; // name of the target id column + const char *weight; // name of the weight column (optional) +}; + +static const ha_create_table_option oqgraph_table_option_list[]= +{ + HA_TOPTION_STRING("data_table", table_name), + HA_TOPTION_STRING("origid", origid), + HA_TOPTION_STRING("destid", destid), + HA_TOPTION_STRING("weight", weight), + HA_TOPTION_END +}; + +static bool oqgraph_init_done= 0; + +static handler* oqgraph_create_handler(handlerton *hton, TABLE_SHARE *table, + MEM_ROOT *mem_root) +{ + DBUG_PRINT( "oq-debug", ("oqgraph_create_handler")); + return new (mem_root) ha_oqgraph(hton, table); +} + +#define OQGRAPH_CREATE_TABLE \ +" CREATE TABLE oq_graph ( "\ +" latch VARCHAR(32) NULL, "\ +" origid BIGINT UNSIGNED NULL, "\ +" destid BIGINT UNSIGNED NULL, "\ +" weight DOUBLE NULL, "\ +" seq BIGINT UNSIGNED NULL, "\ +" linkid BIGINT UNSIGNED NULL, "\ +" KEY (latch, origid, destid) USING HASH, "\ +" KEY (latch, destid, origid) USING HASH "\ +" ) " + +#define append_opt(NAME,VAL) \ + if (share->option_struct->VAL) \ + { \ + const char *val= share->option_struct->VAL; \ + sql.append(STRING_WITH_LEN(" " NAME "='")); \ + sql.append_for_single_quote(val, strlen(val)); \ + sql.append('\''); \ + } + +int oqgraph_discover_table_structure(handlerton *hton, THD* thd, + TABLE_SHARE *share, HA_CREATE_INFO *info) +{ + StringBuffer<1024> sql(system_charset_info); + sql.copy(STRING_WITH_LEN(OQGRAPH_CREATE_TABLE), system_charset_info); + append_opt("data_table", table_name); + append_opt("origid", origid); + append_opt("destid", destid); + append_opt("weight", weight); + + return + share->init_from_sql_statement_string(thd, true, sql.ptr(), sql.length()); +} + +int oqgraph_close_connection(handlerton *hton, THD *thd); + +static int oqgraph_init(void *p) +{ + handlerton *hton= (handlerton *)p; + DBUG_PRINT( "oq-debug", ("oqgraph_init")); + + hton->db_type= DB_TYPE_AUTOASSIGN; + hton->create= oqgraph_create_handler; + hton->flags= HTON_ALTER_NOT_SUPPORTED; + // Prevent ALTER, because the core crashes when the user provides a + // non-existing backing store field for ORIGID, etc + // 'Fixes' bug 1134355 + // HTON_NO_FLAGS; + + hton->table_options= (ha_create_table_option*)oqgraph_table_option_list; + + hton->discover_table_structure= oqgraph_discover_table_structure; + + hton->close_connection = oqgraph_close_connection; + hton->drop_table= [](handlerton *, const char*) { return -1; }; + + oqgraph_init_done= TRUE; + return 0; +} + +static int oqgraph_fini(void *) +{ + DBUG_PRINT( "oq-debug", ("oqgraph_fini")); + oqgraph_init_done= FALSE; + return 0; +} + +static int error_code(int res) +{ + switch (res) + { + case oqgraph::OK: + return 0; + case oqgraph::NO_MORE_DATA: + return HA_ERR_END_OF_FILE; + case oqgraph::EDGE_NOT_FOUND: + return HA_ERR_KEY_NOT_FOUND; + case oqgraph::INVALID_WEIGHT: + return HA_ERR_AUTOINC_ERANGE; + case oqgraph::DUPLICATE_EDGE: + return HA_ERR_FOUND_DUPP_KEY; + case oqgraph::CANNOT_ADD_VERTEX: + case oqgraph::CANNOT_ADD_EDGE: + return HA_ERR_RECORD_FILE_FULL; + case oqgraph::MISC_FAIL: + default: + return HA_ERR_CRASHED_ON_USAGE; + } +} + +/** + * Check if table complies with our designated structure + * + * ColName Type Attributes + * ======= ======== ============= + * latch VARCHAR NULL + * origid BIGINT UNSIGNED NULL + * destid BIGINT UNSIGNED NULL + * weight DOUBLE NULL + * seq BIGINT UNSIGNED NULL + * linkid BIGINT UNSIGNED NULL + * ================================= + * + + The latch may be a varchar of any length, however if it is too short to + hold the longest latch value, table creation is aborted. + + CREATE TABLE foo ( + latch VARCHAR(32) NULL, + origid BIGINT UNSIGNED NULL, + destid BIGINT UNSIGNED NULL, + weight DOUBLE NULL, + seq BIGINT UNSIGNED NULL, + linkid BIGINT UNSIGNED NULL, + KEY (latch, origid, destid) USING HASH, + KEY (latch, destid, origid) USING HASH + ) ENGINE=OQGRAPH + DATA_TABLE=bar + ORIGID=src_id + DESTID=tgt_id + + Previously latch could be an integer. + We no longer allow new integer tables to be created, but we need to support + them if in use and this module is upgraded. + So when the table is opened we need to see whether latch is a varchar or + integer and change behaviour accordingly. + Note that if a table was constructed with varchar and an attempt is made to + select with latch=(some integer number) then MYSQL will autocast + and no data will be returned... so retaining compatibility does not and cannot + extend to making old queries work with new style tables. + + This method is only called on table creation, so here we ensure new tables + can only be created with varchar. + + This does present a small problem with regression testing; + so we work around that by using an system variable to allow + integer latch tables to be created. + + */ +int ha_oqgraph::oqgraph_check_table_structure (TABLE *table_arg) +{ + // Changed from static so we can do decent error reporting. + + int i; + struct { const char *colname; int coltype; } skel[] = { + { "latch" , MYSQL_TYPE_VARCHAR }, + { "origid", MYSQL_TYPE_LONGLONG }, + { "destid", MYSQL_TYPE_LONGLONG }, + { "weight", MYSQL_TYPE_DOUBLE }, + { "seq" , MYSQL_TYPE_LONGLONG }, + { "linkid", MYSQL_TYPE_LONGLONG }, + { NULL , 0} + }; + + DBUG_ENTER("oqgraph_check_table_structure"); + + DBUG_PRINT( "oq-debug", ("Checking structure.")); + + Field **field= table_arg->field; + for (i= 0; *field && skel[i].colname; i++, field++) { + DBUG_PRINT( "oq-debug", ("Column %d: name='%s', expected '%s'; type=%d, expected %d.", i, (*field)->field_name.str, skel[i].colname, (*field)->type(), skel[i].coltype)); + bool badColumn = false; + bool isLatchColumn = strcmp(skel[i].colname, "latch")==0; + bool isStringLatch = true; + +#ifdef RETAIN_INT_LATCH_COMPATIBILITY + if (g_allow_create_integer_latch && isLatchColumn && ((*field)->type() == MYSQL_TYPE_SHORT)) + { + DBUG_PRINT( "oq-debug", ("Allowing integer latch anyway!")); + isStringLatch = false; + /* Make a warning */ + push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN, + ER_WARN_DEPRECATED_SYNTAX, ER(ER_WARN_DEPRECATED_SYNTAX), + "latch SMALLINT UNSIGNED NULL", "'latch VARCHAR(32) NULL'"); + } else +#endif + if (isLatchColumn && ((*field)->type() == MYSQL_TYPE_SHORT)) + { + DBUG_PRINT( "oq-debug", ("Allowing integer no more!")); + badColumn = true; + push_warning_printf( current_thd, Sql_condition::WARN_LEVEL_WARN, HA_WRONG_CREATE_OPTION, "Integer latch is not supported for new tables.", i); + } else + /* Check Column Type */ + if ((*field)->type() != skel[i].coltype) { + badColumn = true; + push_warning_printf( current_thd, Sql_condition::WARN_LEVEL_WARN, HA_WRONG_CREATE_OPTION, "Column %d is wrong type.", i); + } + + // Make sure latch column is large enough for all possible latch values + if (isLatchColumn && isStringLatch) { + if ((*field)->char_length() < findLongestLatch()) { + badColumn = true; + push_warning_printf( current_thd, Sql_condition::WARN_LEVEL_WARN, HA_WRONG_CREATE_OPTION, "Column %d is too short.", i); + } + } + + if (!badColumn) if (skel[i].coltype != MYSQL_TYPE_DOUBLE && (!isLatchColumn || !isStringLatch)) { + /* Check Is UNSIGNED */ + if ( (!((*field)->flags & UNSIGNED_FLAG ))) { + badColumn = true; + push_warning_printf( current_thd, Sql_condition::WARN_LEVEL_WARN, HA_WRONG_CREATE_OPTION, "Column %d must be UNSIGNED.", i); + } + } + /* Check THAT NOT NULL isn't set */ + if (!badColumn) if ((*field)->flags & NOT_NULL_FLAG) { + badColumn = true; + push_warning_printf( current_thd, Sql_condition::WARN_LEVEL_WARN, HA_WRONG_CREATE_OPTION, "Column %d must be NULL.", i); + } + /* Check the column name */ + if (!badColumn) if (strcmp(skel[i].colname,(*field)->field_name.str)) { + badColumn = true; + push_warning_printf( current_thd, Sql_condition::WARN_LEVEL_WARN, HA_WRONG_CREATE_OPTION, "Column %d must be named '%s'.", i, skel[i].colname); + } + if (badColumn) { + DBUG_RETURN(-1); + } + } + + if (skel[i].colname) { + push_warning_printf( current_thd, Sql_condition::WARN_LEVEL_WARN, HA_WRONG_CREATE_OPTION, "Not enough columns."); + DBUG_RETURN(-1); + } + if (*field) { + push_warning_printf( current_thd, Sql_condition::WARN_LEVEL_WARN, HA_WRONG_CREATE_OPTION, "Too many columns."); + DBUG_RETURN(-1); + } + + if (!table_arg->key_info || !table_arg->s->keys) { + push_warning_printf( current_thd, Sql_condition::WARN_LEVEL_WARN, HA_WRONG_CREATE_OPTION, "No valid key specification."); + DBUG_RETURN(-1); + } + + DBUG_PRINT( "oq-debug", ("Checking keys.")); + + KEY *key= table_arg->key_info; + for (uint i= 0; i < table_arg->s->keys; ++i, ++key) + { + Field **field= table_arg->field; + /* check that the first key part is the latch and it is a hash key */ + if (!(field[0] == key->key_part[0].field && + HA_KEY_ALG_HASH == key->algorithm)) { + push_warning_printf( current_thd, Sql_condition::WARN_LEVEL_WARN, HA_WRONG_CREATE_OPTION, "Incorrect keys algorithm on key %d.", i); + DBUG_RETURN(-1); + } + if (key->user_defined_key_parts == 3) + { + /* KEY (latch, origid, destid) USING HASH */ + /* KEY (latch, destid, origid) USING HASH */ + if (!(field[1] == key->key_part[1].field && + field[2] == key->key_part[2].field) && + !(field[1] == key->key_part[2].field && + field[2] == key->key_part[1].field)) + { + push_warning_printf( current_thd, Sql_condition::WARN_LEVEL_WARN, HA_WRONG_CREATE_OPTION, "Keys parts mismatch on key %d.", i); + DBUG_RETURN(-1); + } + } + else { + push_warning_printf( current_thd, Sql_condition::WARN_LEVEL_WARN, HA_WRONG_CREATE_OPTION, "Too many key parts on key %d.", i); + DBUG_RETURN(-1); + } + } + + DBUG_RETURN(0); +} + +/***************************************************************************** +** OQGRAPH tables +*****************************************************************************/ + +int oqgraph_close_connection(handlerton *hton, THD *thd) +{ + DBUG_PRINT( "oq-debug", ("thd: 0x%lx; oqgraph_close_connection.", (long) thd)); + // close_thread_tables(thd); // maybe this? + return 0; +} + + +ha_oqgraph::ha_oqgraph(handlerton *hton, TABLE_SHARE *table_arg) + : handler(hton, table_arg) + , have_table_share(false) + , origid(NULL) + , destid(NULL) + , weight(NULL) + , graph_share(0) + , graph(0) + , error_message("", 0, &my_charset_latin1) +{ +} + +ha_oqgraph::~ha_oqgraph() +{ } + +static const char *ha_oqgraph_exts[] = +{ + NullS +}; + +const char **ha_oqgraph::bas_ext() const +{ + return ha_oqgraph_exts; +} + +ulonglong ha_oqgraph::table_flags() const +{ + return (HA_NO_BLOBS | HA_NULL_IN_KEY | + HA_REC_NOT_IN_SEQ | HA_CAN_INSERT_DELAYED | + HA_BINLOG_STMT_CAPABLE | HA_BINLOG_ROW_CAPABLE); +} + +ulong ha_oqgraph::index_flags(uint inx, uint part, bool all_parts) const +{ + return HA_ONLY_WHOLE_INDEX | HA_KEY_SCAN_NOT_ROR; +} + +bool ha_oqgraph::get_error_message(int error, String* buf) +{ + if (error < 0) + { + buf->append(error_message); + buf->c_ptr_safe(); + error_message.length(0); + } + return false; +} + +void ha_oqgraph::fprint_error(const char* fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + error_message.reserve(256); + size_t len = error_message.length(); + len += vsnprintf(&error_message[len], 255, fmt, ap); + error_message.length(len); + va_end(ap); +} + +/** + * Check that the currently referenced OQGRAPH table definition, on entry to open(), has sane OQGRAPH options. + * (This does not check the backing store, but the OQGRAPH virtual table options) + * + * @return true if OK, or false if an option is invalid. + */ +bool ha_oqgraph::validate_oqgraph_table_options() +{ + // Note when called from open(), we should not expect this method to fail except in the case of bugs; the fact that it does is + // could be construed as a bug. I think in practice however, this is because CREATE TABLE calls both create() and open(), + // and it is possible to do something like ALTER TABLE x DESTID='y' to _change_ the options. + // Thus we need to sanity check from open() until and unless we get around to extending ha_oqgraph to properly handle ALTER TABLE, + // after which we could change things to call this method from create() and the ALTER TABLE handling code instead. + // It may still be sensible to call this from open() anyway, in case someone somewhere upgrades from a broken table definition... + + ha_table_option_struct *options = table->s->option_struct; + // Catch cases where table was not constructed properly + // Note - need to return -1 so our error text gets reported + if (!options) { + // This should only happen if there is a bug elsewhere in the storage engine, because ENGINE itself is an attribute + fprint_error("Invalid OQGRAPH backing store (null attributes)"); + } + else if (!options->table_name || !*options->table_name) { + // The first condition indicates no DATA_TABLE option, the second if the user specified DATA_TABLE='' + fprint_error("Invalid OQGRAPH backing store description (unspecified or empty data_table attribute)"); + // if table_name option is present but doesn't actually exist, we will fail later + } + else if (!options->origid || !*options->origid) { + // The first condition indicates no ORIGID option, the second if the user specified ORIGID='' + fprint_error("Invalid OQGRAPH backing store description (unspecified or empty origid attribute)"); + // if ORIGID option is present but doesn't actually exist, we will fail later + } + else if (!options->destid || !*options->destid) { + // The first condition indicates no DESTID option, the second if the user specified DESTID='' + fprint_error("Invalid OQGRAPH backing store description (unspecified or empty destid attribute)"); + // if DESTID option is present but doesn't actually exist, we will fail later + } else { + // weight is optional... + return true; + } + // Fault + return false; +} + +/** + * Open the OQGRAPH engine 'table'. + * + * An OQGRAPH table is effectively similar to a view over the underlying backing table, attribute 'data_table', but where the + * result returned by a query depends on the value of the 'latch' column specified to the query. + * Therefore, when mysqld opens us, we need to open the corresponding backing table 'data_table'. + * + * Conceptually, the backing store could be any kind of object having queryable semantics, including a SQL VIEW. + * However, for that to work in practice would require us to hook into the right level of the MYSQL API. + * Presently, only objects that can be opened using the internal mechanisms can be used: INNODB, MYISAM, etc. + * The intention is to borrow from ha_connect and use the mysql client library to access the backing store. + * + */ +int ha_oqgraph::open(const char *name, int mode, uint test_if_locked) +{ + DBUG_ENTER("ha_oqgraph::open"); + DBUG_PRINT( "oq-debug", ("thd: 0x%lx; open(name=%s,mode=%d,test_if_locked=%u)", (long) current_thd, name, mode, test_if_locked)); + + // So, we took a peek inside handler::ha_open() and learned a few things: + // * this->table is set by handler::ha_open() before calling open(). + // Note that from this we can only assume that MariaDB knows what it is doing and wont call open() other anything else + // relying on this-0>table, re-entrantly... + // * this->table_share should never be set back to NULL, an assertion checks for this in ha_open() after open() + // * this->table_share is initialised in the constructor of handler + // * this->table_share is only otherwise changed by this->change_table_ptr()) + // We also discovered that an assertion is raised if table->s is not table_share before calling open()) + + DBUG_ASSERT(!have_table_share); + DBUG_ASSERT(graph == NULL); + + // Before doing anything, make sure we have DATA_TABLE, ORIGID and DESTID not empty + if (!validate_oqgraph_table_options()) { DBUG_RETURN(-1); } + + ha_table_option_struct *options= table->s->option_struct; + + + error_message.length(0); + origid= destid= weight= 0; + + // Here we're abusing init_tmp_table_share() which is normally only works for thread-local shares. + THD* thd = current_thd; + init_tmp_table_share( thd, share, table->s->db.str, table->s->db.length, options->table_name, ""); + // because of that, we need to reinitialize the memroot (to reset MY_THREAD_SPECIFIC flag) + DBUG_ASSERT(share->mem_root.used == NULL); // it's still empty + init_sql_alloc(PSI_INSTRUMENT_ME, &share->mem_root, TABLE_ALLOC_BLOCK_SIZE, 0, MYF(0)); + + // What I think this code is doing: + // * Our OQGRAPH table is `database_blah/name` + // * We point p --> /name (or if table happened to be simply `name`, to `name`, don't know if this is possible) + // * plen seems to be then set to length of `database_blah/options_data_table_name` + // * then we set share->normalized_path.str and share->path.str to `database_blah/options_data_table_name` + // * I assume that this verbiage is needed so the memory used by share->path.str is set in the share mem root + // * because otherwise one could simply build the string more simply using malloc and pass it instead of "" above + const char* p= strend(name)-1; + while (p > name && *p != '\\' && *p != '/') + --p; + size_t tlen= strlen(options->table_name); + size_t plen= (int)(p - name) + tlen + 1; + + share->path.str= (char*)alloc_root(&share->mem_root, plen + 1); + strmov(strnmov((char*) share->path.str, name, (int)(p - name) + 1), + options->table_name); + DBUG_ASSERT(strlen(share->path.str) == plen); + share->normalized_path.str= share->path.str; + share->path.length= share->normalized_path.length= plen; + + DBUG_PRINT( "oq-debug", ("share:(normalized_path=%s,path.length=%zu)", + share->normalized_path.str, share->path.length)); + + int open_def_flags = 0; + open_def_flags = GTS_TABLE; + + // We want to open the definition for the given backing table + // Once can assume this loop exists because sometimes open_table_def() fails for a reason other than not exist + // and not 'exist' is valid, because we use ha_create_table_from_engine() to force it to 'exist' + // But, ha_create_table_from_engine() is removed in MariaDB 10.0.4 (?) + // Looking inside most recent ha_create_table_from_engine(), it also calls open_table_def() so maybe this whole thing is redundant... + // Or perhaps it is needed if the backing store is a temporary table or maybe if has no records as yet...? + // Lets try without this, and see if all the tests pass... + while (open_table_def(thd, share, open_def_flags)) + { + open_table_error(share, OPEN_FRM_OPEN_ERROR, ENOENT); + free_table_share(share); + if (thd->is_error()) + DBUG_RETURN(thd->get_stmt_da()->sql_errno()); + DBUG_RETURN(HA_ERR_NO_SUCH_TABLE); + } + + + if (int err= share->error) + { + open_table_error(share, share->error, share->open_errno); + free_table_share(share); + DBUG_RETURN(err); + } + + if (share->is_view) + { + free_table_share(share); + fprint_error("VIEWs are not supported for an OQGRAPH backing store."); + DBUG_RETURN(-1); + } + + if (enum open_frm_error err= open_table_from_share(thd, share, + &empty_lex_cstring, + (uint) (HA_OPEN_KEYFILE | HA_TRY_READ_ONLY), + EXTRA_RECORD, + thd->open_options, edges, FALSE)) + { + open_table_error(share, err, EMFILE); // NOTE - EMFILE is probably bogus, it reports as too many open files (!) + free_table_share(share); + DBUG_RETURN(-1); + } + + + if (!edges->file) + { + fprint_error("Some error occurred opening table '%s'", options->table_name); + free_table_share(share); + DBUG_RETURN(-1); + } + + edges->reginfo.lock_type= TL_READ; + + edges->tablenr= thd->current_tablenr++; + edges->status= STATUS_NO_RECORD; + edges->file->ft_handler= 0; + edges->pos_in_table_list= 0; + edges->clear_column_bitmaps(); + bfill(table->record[0], table->s->null_bytes, 255); + bfill(table->record[1], table->s->null_bytes, 255); + + // We expect fields origid, destid and optionally weight + origid= destid= weight= 0; + + for (Field **field= edges->field; *field; ++field) + { + if (strcmp(options->origid, (*field)->field_name.str)) + continue; + if ((*field)->cmp_type() != INT_RESULT || + !((*field)->flags & NOT_NULL_FLAG)) + { + fprint_error("Column '%s.%s' (origid) is not a not-null integer type", + options->table_name, options->origid); + closefrm(edges); + free_table_share(share); + DBUG_RETURN(-1); + } + origid = *field; + break; + } + + if (!origid) { + fprint_error("Invalid OQGRAPH backing store ('%s.origid' attribute not set to a valid column of '%s')", p+1, options->table_name); + closefrm(edges); + free_table_share(share); + DBUG_RETURN(-1); + } + + + for (Field **field= edges->field; *field; ++field) + { + if (strcmp(options->destid, (*field)->field_name.str)) + continue; + if ((*field)->type() != origid->type() || + !((*field)->flags & NOT_NULL_FLAG)) + { + fprint_error("Column '%s.%s' (destid) is not a not-null integer type or is a different type to origid attribute.", + options->table_name, options->destid); + closefrm(edges); + free_table_share(share); + DBUG_RETURN(-1); + } + destid = *field; + break; + } + + if (!destid) { + fprint_error("Invalid OQGRAPH backing store ('%s.destid' attribute not set to a valid column of '%s')", p+1, options->table_name); + closefrm(edges); + free_table_share(share); + DBUG_RETURN(-1); + } + + // Make sure origid column != destid column + if (strcmp( origid->field_name.str, destid->field_name.str)==0) { + fprint_error("Invalid OQGRAPH backing store ('%s.destid' attribute set to same column as origid attribute)", p+1, options->table_name); + closefrm(edges); + free_table_share(share); + DBUG_RETURN(-1); + } + + for (Field **field= edges->field; options->weight && *field; ++field) + { + if (strcmp(options->weight, (*field)->field_name.str)) + continue; + if ((*field)->result_type() != REAL_RESULT || + !((*field)->flags & NOT_NULL_FLAG)) + { + fprint_error("Column '%s.%s' (weight) is not a not-null real type", + options->table_name, options->weight); + closefrm(edges); + free_table_share(share); + DBUG_RETURN(-1); + } + weight = *field; + break; + } + + if (!weight && options->weight) { + fprint_error("Invalid OQGRAPH backing store ('%s.weight' attribute not set to a valid column of '%s')", p+1, options->table_name); + closefrm(edges); + free_table_share(share); + DBUG_RETURN(-1); + } + + if (!(graph_share = oqgraph::create(edges, origid, destid, weight))) + { + fprint_error("Unable to create graph instance."); + closefrm(edges); + free_table_share(share); + DBUG_RETURN(-1); + } + ref_length= oqgraph::sizeof_ref; + + graph = oqgraph::create(graph_share); + have_table_share = true; + + DBUG_RETURN(0); +} + +int ha_oqgraph::close(void) +{ + DBUG_PRINT( "oq-debug", ("close()")); + if (graph->get_thd() != current_thd) { + DBUG_PRINT( "oq-debug", ("index_next_same g->table->in_use: 0x%lx <-- current_thd 0x%lx", (long) graph->get_thd(), (long) current_thd)); + graph->set_thd(current_thd); + } + oqgraph::free(graph); graph= 0; + oqgraph::free(graph_share); graph_share= 0; + + if (have_table_share) + { + if (edges->file) + closefrm(edges); + free_table_share(share); + have_table_share = false; + } + return 0; +} + +void ha_oqgraph::update_key_stats() +{ + DBUG_PRINT( "oq-debug", ("update_key_stats()")); + for (uint i= 0; i < table->s->keys; i++) + { + KEY *key=table->key_info+i; + if (!key->rec_per_key) + continue; + if (key->algorithm != HA_KEY_ALG_BTREE) + { + if (key->flags & HA_NOSAME) + key->rec_per_key[key->user_defined_key_parts-1]= 1; + else + { + //unsigned vertices= graph->vertices_count(); + //unsigned edges= graph->edges_count(); + //uint no_records= vertices ? 2 * (edges + vertices) / vertices : 2; + //if (no_records < 2) + uint + no_records= 2; + key->rec_per_key[key->user_defined_key_parts-1]= no_records; + } + } + } + /* At the end of update_key_stats() we can proudly claim they are OK. */ + //skey_stat_version= share->key_stat_version; +} + + +int ha_oqgraph::write_row(const byte * buf) +{ + return HA_ERR_TABLE_READONLY; +} + +int ha_oqgraph::update_row(const uchar * old, const uchar * buf) +{ + return HA_ERR_TABLE_READONLY; +} + +int ha_oqgraph::delete_row(const byte * buf) +{ + return HA_ERR_TABLE_READONLY; +} + +int ha_oqgraph::index_read(byte * buf, const byte * key, uint key_len, enum ha_rkey_function find_flag) +{ + DBUG_ASSERT(inited==INDEX); + // reset before we have a cursor, so the memory is not junk, avoiding the sefgault in position() when select with order by (bug #1133093) + graph->init_row_ref(ref); + return index_read_idx(buf, active_index, key, key_len, find_flag); +} + +int ha_oqgraph::index_next_same(byte *buf, const byte *key, uint key_len) +{ + if (graph->get_thd() != current_thd) { + DBUG_PRINT( "oq-debug", ("index_next_same g->table->in_use: 0x%lx <-- current_thd 0x%lx", (long) graph->get_thd(), (long) current_thd)); + graph->set_thd(current_thd); + } + int res; + open_query::row row; + DBUG_ASSERT(inited==INDEX); + if (!(res= graph->fetch_row(row))) + res= fill_record(buf, row); + return error_code(res); +} + +#define LATCH_WAS CODE 0 +#define LATCH_WAS_NUMBER 1 + +/** + * This function parse the VARCHAR(n) latch specification into an integer operation specification compatible with + * v1-v3 oqgraph::search(). + * + * If the string contains a number, this is directly converted from a decimal integer. + * + * Otherwise, a lookup table is used to convert from a string constant. + * + * It is anticipated that this function (and this file and class oqgraph) will be refactored to do this in a nicer way. + * + * FIXME: For the time being, only handles latin1 character set. + * @return false if parsing fails. + */ +static int parse_latch_string_to_legacy_int(const String& value, int &latch) +{ + // Attempt to parse as exactly an integer first. + + // Note: we are strict about not having whitespace, or garbage characters, + // so that the query result gets returned properly: + // Because of the way the result is built and used in fill_result, + // we have to exactly return in the latch column what was in the latch= clause + // otherwise the rows get filtered out by the query optimiser. + + // For the same reason, we cant simply treat latch='' as NO_SEARCH either. + + String latchValue = value; + char *eptr; + unsigned long int v = strtoul( latchValue.c_ptr_safe(), &eptr, 10); + if (!*eptr) { + // we had an unsigned number; remember 0 is valid too ('vertices' aka 'no_search')) + if (v < oqgraph::NUM_SEARCH_OP) { + latch = v; + return true; + } + // fall through and test as a string (although it is unlikely we might have an operator starting with a number) + } + + const oqgraph_latch_op_table* entry = latch_ops_table; + for ( ; entry->key ; entry++) { + if (0 == strncmp(entry->key, latchValue.c_ptr_safe(), latchValue.length())) { + latch = entry->latch; + return true; + } + } + return false; +} + +int ha_oqgraph::index_read_idx(byte * buf, uint index, const byte * key, + uint key_len, enum ha_rkey_function find_flag) +{ + if (graph->get_thd() != current_thd) { + DBUG_PRINT( "oq-debug", ("index_read_idx g->table->in_use: 0x%lx <-- current_thd 0x%lx", (long) graph->get_thd(), (long) current_thd)); + graph->set_thd(current_thd); + } + + Field **field= table->field; + KEY *key_info= table->key_info + index; + int res; + VertexID orig_id, dest_id; + int latch; + VertexID *orig_idp=0, *dest_idp=0; + int* latchp=0; + open_query::row row; + + DBUG_PRINT("oq-debug", ("thd: 0x%lx; index_read_idx()", (long) current_thd)); + + bmove_align(buf, table->s->default_values, table->s->reclength); + key_restore(buf, (byte*) key, key_info, key_len); + + MY_BITMAP *old_map= dbug_tmp_use_all_columns(table, &table->read_set); + my_ptrdiff_t ptrdiff= buf - table->record[0]; + + if (ptrdiff) + { + field[0]->move_field_offset(ptrdiff); + field[1]->move_field_offset(ptrdiff); + field[2]->move_field_offset(ptrdiff); + } + + String latchFieldValue; + if (!field[0]->is_null()) + { +#ifdef RETAIN_INT_LATCH_COMPATIBILITY + if (field[0]->type() == MYSQL_TYPE_SHORT) { + latch= (int) field[0]->val_int(); + } else +#endif + { + field[0]->val_str(&latchFieldValue, &latchFieldValue); + if (!parse_latch_string_to_legacy_int(latchFieldValue, latch)) { + // Invalid, so warn & fail + push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN, ER_WRONG_ARGUMENTS, ER(ER_WRONG_ARGUMENTS), "OQGRAPH latch"); + if (ptrdiff) /* fixes debug build assert - should be a tidier way to do this */ + { + field[0]->move_field_offset(-ptrdiff); + field[1]->move_field_offset(-ptrdiff); + field[2]->move_field_offset(-ptrdiff); + } + dbug_tmp_restore_column_map(&table->read_set, old_map); + return error_code(oqgraph::NO_MORE_DATA); + } + } + latchp= &latch; + } + + if (!field[1]->is_null()) + { + orig_id= (VertexID) field[1]->val_int(); + orig_idp= &orig_id; + } + + if (!field[2]->is_null()) + { + dest_id= (VertexID) field[2]->val_int(); + dest_idp= &dest_id; + } + + if (ptrdiff) + { + field[0]->move_field_offset(-ptrdiff); + field[1]->move_field_offset(-ptrdiff); + field[2]->move_field_offset(-ptrdiff); + } + dbug_tmp_restore_column_map(&table->read_set, old_map); + + // Keep the latch around so we can use it in the query result later - + // See fill_record(). + // at the moment our best option is to associate it with the graph + // so we pass the string now. + // In the future we should refactor parse_latch_string_to_legacy_int() + // into oqgraph instead. + if (latchp) + graph->retainLatchFieldValue(latchFieldValue.c_ptr_safe()); + else + graph->retainLatchFieldValue(NULL); + + + DBUG_PRINT( "oq-debug", ("index_read_idx ::>> search(latch:%s,%ld,%ld)", + oqlatchToCode(latch), orig_idp?(long)*orig_idp:-1, dest_idp?(long)*dest_idp:-1)); + + res= graph->search(latchp, orig_idp, dest_idp); + + DBUG_PRINT( "oq-debug", ("search() = %d", res)); + + if (!res && !(res= graph->fetch_row(row))) { + res= fill_record(buf, row); + } + return error_code(res); +} + +int ha_oqgraph::fill_record(byte *record, const open_query::row &row) +{ + Field **field= table->field; + + bmove_align(record, table->s->default_values, table->s->reclength); + + MY_BITMAP *old_map= dbug_tmp_use_all_columns(table, &table->write_set); + my_ptrdiff_t ptrdiff= record - table->record[0]; + + if (ptrdiff) + { + field[0]->move_field_offset(ptrdiff); + field[1]->move_field_offset(ptrdiff); + field[2]->move_field_offset(ptrdiff); + field[3]->move_field_offset(ptrdiff); + field[4]->move_field_offset(ptrdiff); + field[5]->move_field_offset(ptrdiff); + } + + DBUG_PRINT( "oq-debug", ("fill_record() ::>> %s,%ld,%ld,%lf,%ld,%ld", + row.latch_indicator ? oqlatchToCode((int)row.latch) : "-", + row.orig_indicator ? (long)row.orig : -1, + row.dest_indicator ? (long)row.dest : -1, + row.weight_indicator ? (double)row.weight : -1, + row.seq_indicator ? (long)row.seq : -1, + row.link_indicator ? (long)row.link : -1)); + + // just each field specifically, no sense iterating + if (row.latch_indicator) + { + field[0]->set_notnull(); + // Convert the latch back to a varchar32 + if (field[0]->type() == MYSQL_TYPE_VARCHAR) { + field[0]->store(row.latchStringValue, row.latchStringValueLen, &my_charset_latin1); + } +#ifdef RETAIN_INT_LATCH_COMPATIBILITY + else if (field[0]->type() == MYSQL_TYPE_SHORT) { + field[0]->store((longlong) row.latch, 0); + } +#endif + + } + + if (row.orig_indicator) + { + field[1]->set_notnull(); + field[1]->store((longlong) row.orig, 0); + } + + if (row.dest_indicator) + { + field[2]->set_notnull(); + field[2]->store((longlong) row.dest, 0); + } + + if (row.weight_indicator) + { + field[3]->set_notnull(); + field[3]->store((double) row.weight); + } + + if (row.seq_indicator) + { + field[4]->set_notnull(); + field[4]->store((longlong) row.seq, 0); + } + + if (row.link_indicator) + { + field[5]->set_notnull(); + field[5]->store((longlong) row.link, 0); + } + + if (ptrdiff) + { + field[0]->move_field_offset(-ptrdiff); + field[1]->move_field_offset(-ptrdiff); + field[2]->move_field_offset(-ptrdiff); + field[3]->move_field_offset(-ptrdiff); + field[4]->move_field_offset(-ptrdiff); + field[5]->move_field_offset(-ptrdiff); + } + dbug_tmp_restore_column_map(&table->write_set, old_map); + + return 0; +} + +int ha_oqgraph::rnd_init(bool scan) +{ + edges->file->info(HA_STATUS_VARIABLE|HA_STATUS_CONST); // Fix for bug 1195735, hang after truncate table - ensure we operate with up to date count + edges->prepare_for_position(); + return error_code(graph->random(scan)); +} + +int ha_oqgraph::rnd_next(byte *buf) +{ + if (graph->get_thd() != current_thd) { + DBUG_PRINT( "oq-debug", ("rnd_next g->table->in_use: 0x%lx <-- current_thd 0x%lx", (long) graph->get_thd(), (long) current_thd)); + graph->set_thd(current_thd); + } + int res; + open_query::row row = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + if (!(res= graph->fetch_row(row))) + res= fill_record(buf, row); + return error_code(res); +} + +int ha_oqgraph::rnd_pos(byte * buf, byte *pos) +{ + if (graph->get_thd() != current_thd) { + DBUG_PRINT( "oq-debug", ("rnd_pos g->table->in_use: 0x%lx <-- current_thd 0x%lx", (long) graph->get_thd(), (long) current_thd)); + graph->set_thd(current_thd); + } + int res; + open_query::row row; + if (!(res= graph->fetch_row(row, pos))) + res= fill_record(buf, row); + return error_code(res); +} + +void ha_oqgraph::position(const byte *record) +{ + graph->row_ref((void*) ref); // Ref is aligned +} + +int ha_oqgraph::cmp_ref(const byte *ref1, const byte *ref2) +{ + return memcmp(ref1, ref2, oqgraph::sizeof_ref); +} + +int ha_oqgraph::info(uint flag) +{ + stats.records = graph->edges_count(); + + /* + If info() is called for the first time after open(), we will still + have to update the key statistics. Hoping that a table lock is now + in place. + */ +// if (key_stat_version != share->key_stat_version) + // update_key_stats(); + return 0; +} + +int ha_oqgraph::extra(enum ha_extra_function operation) +{ + if (graph->get_thd() != ha_thd()) { + DBUG_PRINT( "oq-debug", ("rnd_pos g->table->in_use: 0x%lx <-- current_thd 0x%lx", (long) graph->get_thd(), (long) current_thd)); + graph->set_thd(current_thd); + } + return edges->file->extra(operation); +} + +int ha_oqgraph::delete_all_rows() +{ + return HA_ERR_TABLE_READONLY; +} + +int ha_oqgraph::external_lock(THD *thd, int lock_type) +{ + // This method is also called to _unlock_ (lock_type == F_UNLCK) + // Which means we need to release things before we let the underlying backing table lock go... + if (lock_type == F_UNLCK) { + // If we have an index open on the backing table, we need to close it out here + // this means destroying any open cursor first. + // Then we can let the unlock go through to the backing table + graph->release_cursor(); + } + + return edges->file->ha_external_lock(thd, lock_type); +} + + +THR_LOCK_DATA **ha_oqgraph::store_lock(THD *thd, THR_LOCK_DATA **to, enum thr_lock_type lock_type) +{ + return edges->file->store_lock(thd, to, lock_type); +} + +/* + We have to ignore ENOENT entries as the HEAP table is created on open and + not when doing a CREATE on the table. +*/ + +int ha_oqgraph::delete_table(const char *) +{ + DBUG_PRINT( "oq-debug", ("delete_table()")); + return 0; +} + +int ha_oqgraph::rename_table(const char *, const char *) +{ + DBUG_PRINT( "oq-debug", ("rename_table()")); + return 0; +} + + +ha_rows ha_oqgraph::records_in_range(uint inx, + const key_range *min_key, + const key_range *max_key, + page_range *pages) +{ + if (graph->get_thd() != current_thd) { + DBUG_PRINT( "oq-debug", ("g->table->in_use: 0x%lx <-- current_thd 0x%lx", (long) graph->get_thd(), (long) current_thd)); + graph->set_thd(current_thd); + } + + KEY *key=table->key_info+inx; +#ifdef VERBOSE_DEBUG + { + String temp; + key->key_part[0].field->val_str(&temp); + temp.c_ptr_safe(); + DBUG_PRINT( "oq-debug", ("thd: 0x%lx; records_in_range ::>> inx=%u", (long) current_thd, inx)); + DBUG_PRINT( "oq-debug", ("records_in_range ::>> key0=%s.", temp.c_ptr())); // for some reason when I had ...inx=%u key=%s", inx, temp.c_ptr_safe()) it printed nothing ... + } +#endif + + if (!min_key || !max_key || + min_key->length != max_key->length || + min_key->length < key->key_length - key->key_part[2].store_length || + min_key->flag != HA_READ_KEY_EXACT || + max_key->flag != HA_READ_AFTER_KEY) + { + if (min_key && min_key->length == key->key_part[0].store_length && !key->key_part[0].field->is_null()) /* ensure select * from x where latch is null is consistent with no latch */ + { + // If latch is not null and equals 0, return # nodes + + // How to decode the key, For VARCHAR(32), from empirical observation using the debugger + // and information gleaned from: + // http://grokbase.com/t/mysql/internals/095h6ch1q7/parsing-key-information + // http://dev.mysql.com/doc/internals/en/support-for-indexing.html#parsing-key-information + // comments in opt_range.cc + // POSSIBLY ONLY VALID FOR INNODB! + + // For a the following query: + // SELECT * FROM graph2 WHERE latch = 'breadth_first' AND origid = 123 AND weight = 1; + // key->key_part[0].field->ptr is the value of latch, which is a 1-byte string length followed by the value ('breadth_first') + // key->key_part[2].field->ptr is the value of origid (123) + // key->key_part[1].field->ptr is the value of destid which is not specified in the query so we ignore it in this case + // so given this ordering we seem to be using the second key specified in create table (aka KEY (latch, destid, origid) USING HASH )) + + // min_key->key[0] is the 'null' bit and contains 0 in this instance + // min_key->key[1..2] seems to be 16-bit string length + // min_key->key[3..34] hold the varchar(32) value which is that specified in the query + // min_key->key[35] is the null bit of origid + // min_key->key[36..43] is the value in the query (123) + + // max_key->key[0] is the ;null' bit and contains 0 in this instance + // max_key->key[1..2] seems to be 16-bit string length + // max_key->key[3..34] hold the varchar(32) value which is that specified in the query + // max_key->key[35] is the null bit of origid + // max_key->key[36..43] is the value in the query (123) + + // But after knowing all that, all we care about is the latch value + + // First draft - ignore most of the stuff, but will likely break if query altered + + // It turns out there is a better way though, to access the string, + // as demonstrated in key_unpack() of sql/key.cc + String latchCode; + int latch = -1; + if (key->key_part[0].field->type() == MYSQL_TYPE_VARCHAR) { + + key->key_part[0].field->val_str(&latchCode); + + parse_latch_string_to_legacy_int( latchCode, latch); + } + + // what if someone did something dumb, like mismatching the latches? + +#ifdef RETAIN_INT_LATCH_COMPATIBILITY + else if (key->key_part[0].field->type() == MYSQL_TYPE_SHORT) { + // If not null, and zero ... + // Note, the following code relies on the fact that the three bytes + // at beginning of min_key just happen to be the null indicator and the + // 16-bit value of the latch ... + // this will fall through if the user alter-tabled to not null + if (key->key_part[0].null_bit && !min_key->key[0] && + !min_key->key[1] && !min_key->key[2]) { + latch = oqgraph::NO_SEARCH; + } + } +#endif + if (latch != oqgraph::NO_SEARCH) { + // Invalid key type... + // Don't assert, in case the user used alter table on us + return HA_POS_ERROR; // Can only use exact keys + } + unsigned N = graph->vertices_count(); + DBUG_PRINT( "oq-debug", ("records_in_range ::>> N=%u (vertices)", N)); + return N; + } + return HA_POS_ERROR; // Can only use exact keys + } + + if (stats.records <= 1) { + DBUG_PRINT( "oq-debug", ("records_in_range ::>> N=%u (stats)", (unsigned)stats.records)); + return stats.records; + } + + /* Assert that info() did run. We need current statistics here. */ + //DBUG_ASSERT(key_stat_version == share->key_stat_version); + //ha_rows result= key->rec_per_key[key->user_defined_key_parts-1]; + ha_rows result= 10; + DBUG_PRINT( "oq-debug", ("records_in_range ::>> N=%u", (unsigned)result)); + + return result; +} + + +int ha_oqgraph::create(const char *name, TABLE *table_arg, HA_CREATE_INFO *create_info) +{ + DBUG_ENTER("ha_oqgraph::create"); + DBUG_PRINT( "oq-debug", ("create(name=%s)", name)); + + if (oqgraph_check_table_structure(table_arg)) { + DBUG_RETURN(HA_WRONG_CREATE_OPTION); + } + + DBUG_RETURN(0); +} + + +void ha_oqgraph::update_create_info(HA_CREATE_INFO *create_info) +{ + table->file->info(HA_STATUS_AUTO); +} + +// -------------------- +// Handler description. +// -------------------- + + +static const char oqgraph_description[]= + "Open Query Graph Computation Engine " + "(http://openquery.com/graph)"; + +struct st_mysql_storage_engine oqgraph_storage_engine= +{ MYSQL_HANDLERTON_INTERFACE_VERSION }; + +extern "C" const char* const oqgraph_boost_version; + +static const char *oqgraph_status_verbose_debug = +#ifdef VERBOSE_DEBUG + "Verbose Debug is enabled. Performance may be adversely impacted."; +#else + "Verbose Debug is not enabled."; +#endif + +static const char *oqgraph_status_latch_compat_mode = +#ifdef RETAIN_INT_LATCH_COMPATIBILITY + "Legacy tables with integer latches are supported."; +#else + "Legacy tables with integer latches are not supported."; +#endif + +static struct st_mysql_show_var oqgraph_status[]= +{ + { "OQGraph_Boost_Version", (char*) &oqgraph_boost_version, SHOW_CHAR_PTR }, + /* We thought about reporting the Judy version, but there seems to be no way to get that from code in the first place. */ + { "OQGraph_Verbose_Debug", (char*) &oqgraph_status_verbose_debug, SHOW_CHAR_PTR }, + { "OQGraph_Compat_mode", (char*) &oqgraph_status_latch_compat_mode, SHOW_CHAR_PTR }, + { 0, 0, SHOW_UNDEF } +}; + +#ifdef RETAIN_INT_LATCH_COMPATIBILITY +static MYSQL_SYSVAR_BOOL( allow_create_integer_latch, g_allow_create_integer_latch, PLUGIN_VAR_RQCMDARG, + "Allow creation of integer latches so the upgrade logic can be tested. Not for normal use.", + NULL, NULL, FALSE); +#endif + +static struct st_mysql_sys_var* oqgraph_sysvars[]= { +#ifdef RETAIN_INT_LATCH_COMPATIBILITY + MYSQL_SYSVAR(allow_create_integer_latch), +#endif + 0 +}; + +maria_declare_plugin(oqgraph) +{ + MYSQL_STORAGE_ENGINE_PLUGIN, + &oqgraph_storage_engine, + "OQGRAPH", + "Arjen Lentz & Antony T Curtis, Open Query, and Andrew McDonnell", + oqgraph_description, + PLUGIN_LICENSE_GPL, + oqgraph_init, /* Plugin Init */ + oqgraph_fini, /* Plugin Deinit */ + 0x0300, /* Version: 3s.0 */ + oqgraph_status, /* status variables */ + oqgraph_sysvars, /* system variables */ + "3.0", + MariaDB_PLUGIN_MATURITY_GAMMA +} +maria_declare_plugin_end; diff --git a/storage/oqgraph/ha_oqgraph.h b/storage/oqgraph/ha_oqgraph.h new file mode 100644 index 00000000..c8e175df --- /dev/null +++ b/storage/oqgraph/ha_oqgraph.h @@ -0,0 +1,143 @@ +/* Copyright (C) 2007-2013 Arjen G Lentz & Antony T Curtis for Open Query + Portions of this file copyright (C) 2000-2006 MySQL AB + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */ + +/* ====================================================================== + Open Query Graph Computation Engine, based on a concept by Arjen Lentz + v3 implementation by Antony Curtis, Arjen Lentz, Andrew McDonnell + For more information, documentation, support, enhancement engineering, + see http://openquery.com/graph or contact graph@openquery.com + ====================================================================== +*/ + +#ifdef USE_PRAGMA_INTERFACE +#pragma interface /* gcc class implementation */ +#endif + +#include "handler.h" +#include "table.h" + +typedef struct oqgraph_info_st OQGRAPH_INFO; +typedef uchar byte; + +namespace open_query +{ + struct row; + class oqgraph; + class oqgraph_share; +} + +/* class for the the Open Query Graph handler */ + +class ha_oqgraph: public handler +{ + TABLE_SHARE share[1]; + bool have_table_share; + TABLE edges[1]; + Field *origid; + Field *destid; + Field *weight; + + open_query::oqgraph_share *graph_share; + open_query::oqgraph *graph; + + int fill_record(byte*, const open_query::row&); + +public: +#if MYSQL_VERSION_ID >= 50100 + ha_oqgraph(handlerton *hton, TABLE_SHARE *table); + ulonglong table_flags() const; +#else + ha_oqgraph(TABLE *table); + Table_flags table_flags() const; +#endif + virtual ~ha_oqgraph(); + const char *index_type(uint inx) + { + return "HASH"; + } + /* Rows also use a fixed-size format */ + enum row_type get_row_type() const { return ROW_TYPE_FIXED; } + ulong index_flags(uint inx, uint part, bool all_parts) const; + const char **bas_ext() const; + uint max_supported_keys() const { return MAX_KEY; } + uint max_supported_key_part_length() const { return MAX_KEY_LENGTH; } + double scan_time() { return (double) 1000000000; } + double read_time(uint index, uint ranges, ha_rows rows) + { return 1; } + + // Doesn't make sense to change the engine on a virtual table. + virtual bool can_switch_engines() { return false; } + + int open(const char *name, int mode, uint test_if_locked); + int close(void); + int write_row(const byte * buf); + int update_row(const uchar * old_data, const uchar * new_data); + int delete_row(const byte * buf); + int index_read(byte * buf, const byte * key, + uint key_len, enum ha_rkey_function find_flag); + int index_read_idx(byte * buf, uint idx, const byte * key, + uint key_len, enum ha_rkey_function find_flag); + int index_next_same(byte * buf, const byte * key, uint key_len); + int rnd_init(bool scan); + int rnd_next(byte *buf); + int rnd_pos(byte * buf, byte *pos); + void position(const byte *record); + int info(uint); + int extra(enum ha_extra_function operation); + int external_lock(THD *thd, int lock_type); + int delete_all_rows(void); + ha_rows records_in_range(uint inx, const key_range *min_key, + const key_range *max_key, page_range *pages); + int delete_table(const char *from); + int rename_table(const char * from, const char * to); + int create(const char *name, TABLE *form, HA_CREATE_INFO *create_info); + void update_create_info(HA_CREATE_INFO *create_info); + + THR_LOCK_DATA **store_lock(THD *thd, THR_LOCK_DATA **to, + enum thr_lock_type lock_type); + int cmp_ref(const byte *ref1, const byte *ref2); + + bool get_error_message(int error, String* buf); + + void fprint_error(const char* fmt, ...); + +#if MYSQL_VERSION_ID < 100000 + // Allow compatibility for build with 5.5.32 + virtual const char *table_type() const { return hton_name(ht)->str; } +#endif + + my_bool register_query_cache_table(THD *thd, const char *table_key, + uint key_length, + qc_engine_callback + *engine_callback, + ulonglong *engine_data) + { + /* + Do not put data from OQGRAPH tables into query cache (because there + is no way to tell whether the data in the backing table has changed or + not) + */ + return FALSE; + } + +private: + + // Various helper functions + int oqgraph_check_table_structure (TABLE *table_arg); + bool validate_oqgraph_table_options(); + void update_key_stats(); + String error_message; +}; diff --git a/storage/oqgraph/mysql-test/oqgraph/boundary_conditions.result b/storage/oqgraph/mysql-test/oqgraph/boundary_conditions.result new file mode 100644 index 00000000..de8362c1 --- /dev/null +++ b/storage/oqgraph/mysql-test/oqgraph/boundary_conditions.result @@ -0,0 +1,215 @@ +DROP TABLE IF EXISTS graph_base; +DROP TABLE IF EXISTS graph; +DROP TABLE IF EXISTS graph2; +call mtr.add_suppression("graph_base is open on delete"); +CREATE TABLE graph2 ( +latch VARCHAR(32) NULL, +origid BIGINT UNSIGNED NULL, +destid BIGINT UNSIGNED NULL, +weight DOUBLE NULL, +seq BIGINT UNSIGNED NULL, +linkid BIGINT UNSIGNED NULL, +KEY (latch, origid, destid) USING HASH, +KEY (latch, destid, origid) USING HASH +) ENGINE=OQGRAPH DATA_TABLE='graph_base' ORIGID='from_id', DESTID='to_id'; +SELECT * FROM graph2 WHERE latch='dijkstras' AND origid=1 AND destid=6; +ERROR 42S02: Table 'test.graph_base' doesn't exist +DROP TABLE graph2; +CREATE TABLE graph_base ( +from_id INT UNSIGNED NOT NULL, +to_id INT UNSIGNED NOT NULL, +PRIMARY KEY (from_id,to_id), +INDEX (to_id) +) ENGINE=MyISAM; +CREATE TABLE graph ( +latch VARCHAR(32) NULL, +origid BIGINT UNSIGNED NULL, +destid BIGINT UNSIGNED NULL, +weight DOUBLE NULL, +seq BIGINT UNSIGNED NULL, +linkid BIGINT UNSIGNED NULL, +KEY (latch, origid, destid) USING HASH, +KEY (latch, destid, origid) USING HASH +) ENGINE=OQGRAPH DATA_TABLE='graph_base' ORIGID='from_id', DESTID='to_id'; +INSERT INTO graph_base(from_id, to_id) VALUES (1,2), (2,1); +INSERT INTO graph_base(from_id, to_id) VALUES (1,3), (3,1); +INSERT INTO graph_base(from_id, to_id) VALUES (3,4), (4,3); +INSERT INTO graph_base(from_id, to_id) VALUES (5,6), (6,5); +# Expect no result, because of autocast +SELECT * FROM graph WHERE latch=0 ; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch=0 and destid=2 and origid=1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch=0 and origid=1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch=0 and destid=1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch=0 and origid=666; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch=0 and origid is NULL; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch=1 ; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch=1 and destid=2 and origid=1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch=1 and origid=1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch=1 and destid=1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch=1 and origid=666; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch=1 and origid is NULL; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch=2 ; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch=2 and destid=2 and origid=1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch=2 and origid=1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch=2 and destid=1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch=2 and origid=666; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch=2 and origid is NULL; +latch origid destid weight seq linkid +# Should this return an error? it seems we treat it as just another bogus latch +SELECT * FROM graph WHERE latch='ThisExceeds32Characters456789012'; +latch origid destid weight seq linkid +# Expect no result, because of invalid latch +SELECT * FROM graph WHERE latch='bogus'; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch='bogus' and destid=2 and origid=1; +latch origid destid weight seq linkid +Warnings: +Warning 1210 Incorrect arguments to OQGRAPH latch +SELECT * FROM graph WHERE latch='bogus' and origid=1; +latch origid destid weight seq linkid +Warnings: +Warning 1210 Incorrect arguments to OQGRAPH latch +SELECT * FROM graph WHERE latch='bogus' and destid=1; +latch origid destid weight seq linkid +Warnings: +Warning 1210 Incorrect arguments to OQGRAPH latch +SELECT * FROM graph WHERE latch='bogus' and origid=666; +latch origid destid weight seq linkid +Warnings: +Warning 1210 Incorrect arguments to OQGRAPH latch +SELECT * FROM graph WHERE latch='bogus' and origid is NULL; +latch origid destid weight seq linkid +Warnings: +Warning 1210 Incorrect arguments to OQGRAPH latch +SELECT * FROM graph WHERE latch='666'; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch='666' and destid=2 and origid=1; +latch origid destid weight seq linkid +Warnings: +Warning 1210 Incorrect arguments to OQGRAPH latch +SELECT * FROM graph WHERE latch='666' and origid=1; +latch origid destid weight seq linkid +Warnings: +Warning 1210 Incorrect arguments to OQGRAPH latch +SELECT * FROM graph WHERE latch='666' and destid=1; +latch origid destid weight seq linkid +Warnings: +Warning 1210 Incorrect arguments to OQGRAPH latch +SELECT * FROM graph WHERE latch='666' and origid=666; +latch origid destid weight seq linkid +Warnings: +Warning 1210 Incorrect arguments to OQGRAPH latch +SELECT * FROM graph WHERE latch='666' and origid is NULL; +latch origid destid weight seq linkid +Warnings: +Warning 1210 Incorrect arguments to OQGRAPH latch +SELECT * FROM graph WHERE latch='-1'; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch='-1' and destid=2 and origid=1; +latch origid destid weight seq linkid +Warnings: +Warning 1210 Incorrect arguments to OQGRAPH latch +SELECT * FROM graph WHERE latch='-1' and origid=1; +latch origid destid weight seq linkid +Warnings: +Warning 1210 Incorrect arguments to OQGRAPH latch +SELECT * FROM graph WHERE latch='-1' and destid=1; +latch origid destid weight seq linkid +Warnings: +Warning 1210 Incorrect arguments to OQGRAPH latch +SELECT * FROM graph WHERE latch='-1' and origid=666; +latch origid destid weight seq linkid +Warnings: +Warning 1210 Incorrect arguments to OQGRAPH latch +SELECT * FROM graph WHERE latch='-1' and origid is NULL; +latch origid destid weight seq linkid +Warnings: +Warning 1210 Incorrect arguments to OQGRAPH latch +# Make sure we don't crash if someone passed in a UTF string +SELECT * FROM graph WHERE latch='Ω Ohms Tennis Ball 〄'; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch='Ω Ohms Tennis Ball 〄' and destid=2 and origid=1; +latch origid destid weight seq linkid +Warnings: +Warning 1210 Incorrect arguments to OQGRAPH latch +SELECT * FROM graph WHERE latch='Ω Ohms Tennis Ball 〄' and origid=1; +latch origid destid weight seq linkid +Warnings: +Warning 1210 Incorrect arguments to OQGRAPH latch +SELECT * FROM graph WHERE latch='Ω Ohms Tennis Ball 〄' and destid=1; +latch origid destid weight seq linkid +Warnings: +Warning 1210 Incorrect arguments to OQGRAPH latch +SELECT * FROM graph WHERE latch='Ω Ohms Tennis Ball 〄' and origid=666; +latch origid destid weight seq linkid +Warnings: +Warning 1210 Incorrect arguments to OQGRAPH latch +SELECT * FROM graph WHERE latch='Ω Ohms Tennis Ball 〄' and origid is NULL; +latch origid destid weight seq linkid +Warnings: +Warning 1210 Incorrect arguments to OQGRAPH latch +# Return all edges when latch is NULL +SELECT * FROM graph WHERE latch is NULL; +latch origid destid weight seq linkid +NULL 1 2 1 NULL NULL +NULL 2 1 1 NULL NULL +NULL 1 3 1 NULL NULL +NULL 3 1 1 NULL NULL +NULL 3 4 1 NULL NULL +NULL 4 3 1 NULL NULL +NULL 5 6 1 NULL NULL +NULL 6 5 1 NULL NULL +SELECT * FROM graph WHERE latch is NULL and destid=2 and origid=1; +latch origid destid weight seq linkid +NULL 1 2 1 3 1 +NULL 1 2 1 2 3 +NULL 1 2 1 1 2 +SELECT * FROM graph WHERE latch is NULL and origid=1; +latch origid destid weight seq linkid +NULL 1 NULL 1 2 3 +NULL 1 NULL 1 1 2 +SELECT * FROM graph WHERE latch is NULL and destid=1; +latch origid destid weight seq linkid +NULL NULL 1 1 2 3 +NULL NULL 1 1 1 2 +SELECT * FROM graph WHERE latch is NULL and origid=666; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch is NULL and origid is NULL; +latch origid destid weight seq linkid +NULL NULL NULL NULL NULL 1 +NULL NULL NULL NULL NULL 2 +NULL NULL NULL NULL NULL 3 +NULL NULL NULL NULL NULL 4 +NULL NULL NULL NULL NULL 5 +NULL NULL NULL NULL NULL 6 +INSERT INTO graph_base(from_id, to_id) VALUES (1,2); +ERROR 23000: Duplicate entry '1-2' for key 'PRIMARY' +DELETE FROM graph_base; +SELECT * FROM graph; +latch origid destid weight seq linkid +FLUSH TABLES; +TRUNCATE TABLE graph_base; +SELECT * FROM graph; +latch origid destid weight seq linkid +DROP TABLE graph_base; +FLUSH TABLES; +SELECT * FROM graph WHERE latch='dijkstras' AND origid=1 AND destid=6; +ERROR 42S02: Table 'test.graph_base' doesn't exist +DROP TABLE graph; diff --git a/storage/oqgraph/mysql-test/oqgraph/boundary_conditions.test b/storage/oqgraph/mysql-test/oqgraph/boundary_conditions.test new file mode 100644 index 00000000..9eea290c --- /dev/null +++ b/storage/oqgraph/mysql-test/oqgraph/boundary_conditions.test @@ -0,0 +1,139 @@ +--disable_warnings +DROP TABLE IF EXISTS graph_base; +DROP TABLE IF EXISTS graph; +DROP TABLE IF EXISTS graph2; +--enable_warnings + +call mtr.add_suppression("graph_base is open on delete"); + +CREATE TABLE graph2 ( + latch VARCHAR(32) NULL, + origid BIGINT UNSIGNED NULL, + destid BIGINT UNSIGNED NULL, + weight DOUBLE NULL, + seq BIGINT UNSIGNED NULL, + linkid BIGINT UNSIGNED NULL, + KEY (latch, origid, destid) USING HASH, + KEY (latch, destid, origid) USING HASH + ) ENGINE=OQGRAPH DATA_TABLE='graph_base' ORIGID='from_id', DESTID='to_id'; +# Because the backing store graph_base doesnt exist yet, the select should fail +--error S42S02 +SELECT * FROM graph2 WHERE latch='dijkstras' AND origid=1 AND destid=6; +DROP TABLE graph2; + +# Create the backing store +CREATE TABLE graph_base ( + from_id INT UNSIGNED NOT NULL, + to_id INT UNSIGNED NOT NULL, + PRIMARY KEY (from_id,to_id), + INDEX (to_id) + ) ENGINE=MyISAM; + + +CREATE TABLE graph ( + latch VARCHAR(32) NULL, + origid BIGINT UNSIGNED NULL, + destid BIGINT UNSIGNED NULL, + weight DOUBLE NULL, + seq BIGINT UNSIGNED NULL, + linkid BIGINT UNSIGNED NULL, + KEY (latch, origid, destid) USING HASH, + KEY (latch, destid, origid) USING HASH + ) ENGINE=OQGRAPH DATA_TABLE='graph_base' ORIGID='from_id', DESTID='to_id'; + + +INSERT INTO graph_base(from_id, to_id) VALUES (1,2), (2,1); +INSERT INTO graph_base(from_id, to_id) VALUES (1,3), (3,1); +INSERT INTO graph_base(from_id, to_id) VALUES (3,4), (4,3); +INSERT INTO graph_base(from_id, to_id) VALUES (5,6), (6,5); + +--echo # Expect no result, because of autocast +SELECT * FROM graph WHERE latch=0 ; +SELECT * FROM graph WHERE latch=0 and destid=2 and origid=1; +SELECT * FROM graph WHERE latch=0 and origid=1; +SELECT * FROM graph WHERE latch=0 and destid=1; +SELECT * FROM graph WHERE latch=0 and origid=666; +SELECT * FROM graph WHERE latch=0 and origid is NULL; +SELECT * FROM graph WHERE latch=1 ; +SELECT * FROM graph WHERE latch=1 and destid=2 and origid=1; +SELECT * FROM graph WHERE latch=1 and origid=1; +SELECT * FROM graph WHERE latch=1 and destid=1; +SELECT * FROM graph WHERE latch=1 and origid=666; +SELECT * FROM graph WHERE latch=1 and origid is NULL; +SELECT * FROM graph WHERE latch=2 ; +SELECT * FROM graph WHERE latch=2 and destid=2 and origid=1; +SELECT * FROM graph WHERE latch=2 and origid=1; +SELECT * FROM graph WHERE latch=2 and destid=1; +SELECT * FROM graph WHERE latch=2 and origid=666; +SELECT * FROM graph WHERE latch=2 and origid is NULL; + +--echo # Should this return an error? it seems we treat it as just another bogus latch +SELECT * FROM graph WHERE latch='ThisExceeds32Characters456789012'; +--echo # Expect no result, because of invalid latch +SELECT * FROM graph WHERE latch='bogus'; +SELECT * FROM graph WHERE latch='bogus' and destid=2 and origid=1; +SELECT * FROM graph WHERE latch='bogus' and origid=1; +SELECT * FROM graph WHERE latch='bogus' and destid=1; +SELECT * FROM graph WHERE latch='bogus' and origid=666; +SELECT * FROM graph WHERE latch='bogus' and origid is NULL; +#-- Note the next line couter-intuitively produces no warning +SELECT * FROM graph WHERE latch='666'; +SELECT * FROM graph WHERE latch='666' and destid=2 and origid=1; +SELECT * FROM graph WHERE latch='666' and origid=1; +SELECT * FROM graph WHERE latch='666' and destid=1; +SELECT * FROM graph WHERE latch='666' and origid=666; +#-- Note the next line couter-intuitively produces no warning +SELECT * FROM graph WHERE latch='666' and origid is NULL; +SELECT * FROM graph WHERE latch='-1'; +SELECT * FROM graph WHERE latch='-1' and destid=2 and origid=1; +SELECT * FROM graph WHERE latch='-1' and origid=1; +SELECT * FROM graph WHERE latch='-1' and destid=1; +SELECT * FROM graph WHERE latch='-1' and origid=666; +SELECT * FROM graph WHERE latch='-1' and origid is NULL; + +--echo # Make sure we don't crash if someone passed in a UTF string +#-- Note the next line couter-intuitively produces no warning +SELECT * FROM graph WHERE latch='Ω Ohms Tennis Ball 〄'; +SELECT * FROM graph WHERE latch='Ω Ohms Tennis Ball 〄' and destid=2 and origid=1; +SELECT * FROM graph WHERE latch='Ω Ohms Tennis Ball 〄' and origid=1; +SELECT * FROM graph WHERE latch='Ω Ohms Tennis Ball 〄' and destid=1; +SELECT * FROM graph WHERE latch='Ω Ohms Tennis Ball 〄' and origid=666; +#-- Note the next line couter-intuitively produces no warning +SELECT * FROM graph WHERE latch='Ω Ohms Tennis Ball 〄' and origid is NULL; + +#--echo # Expect no result, because of NULL latch +#-- FIXME - in v2 according to http://openquery.com/graph/doc NULL latch should +#-- FIXME - return same as select * from graph; +#--https://bugs.launchpad.net/oqgraph/+bug/1196021 +--echo # Return all edges when latch is NULL +SELECT * FROM graph WHERE latch is NULL; +SELECT * FROM graph WHERE latch is NULL and destid=2 and origid=1; +SELECT * FROM graph WHERE latch is NULL and origid=1; +SELECT * FROM graph WHERE latch is NULL and destid=1; +SELECT * FROM graph WHERE latch is NULL and origid=666; +SELECT * FROM graph WHERE latch is NULL and origid is NULL; + +#-- what happens if we have two links the same? primay key violation... +--error 1062 +INSERT INTO graph_base(from_id, to_id) VALUES (1,2); + +DELETE FROM graph_base; +#-- Uncomment the following after fixing https://bugs.launchpad.net/oqgraph/+bug/1195735 +SELECT * FROM graph; + +FLUSH TABLES; + +TRUNCATE TABLE graph_base; +#-- Uncomment the following after fixing https://bugs.launchpad.net/oqgraph/+bug/xxxxxxx - Causes the later select to not fail! +#-- For now don't report a separate bug as it may be a manifestation of https://bugs.launchpad.net/oqgraph/+bug/1195735 +SELECT * FROM graph; + +#-- Expect error if we pull the table out from under +DROP TABLE graph_base; +FLUSH TABLES; + +--error S42S02 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=1 AND destid=6; + +DROP TABLE graph; + diff --git a/storage/oqgraph/mysql-test/oqgraph/connections_mdev5748.result b/storage/oqgraph/mysql-test/oqgraph/connections_mdev5748.result new file mode 100644 index 00000000..3b71112d --- /dev/null +++ b/storage/oqgraph/mysql-test/oqgraph/connections_mdev5748.result @@ -0,0 +1,35 @@ +connect con1,localhost,root,,; +CREATE TABLE oq_backing ( +origid INT UNSIGNED NOT NULL, +destid INT UNSIGNED NOT NULL, +weight DOUBLE NOT NULL, +PRIMARY KEY (origid, destid), +KEY (destid) +); +CREATE TABLE oq_table ( +latch VARCHAR(32) NULL, +origid BIGINT UNSIGNED NULL, +destid BIGINT UNSIGNED NULL, +weight DOUBLE NULL, +seq BIGINT UNSIGNED NULL, +linkid BIGINT UNSIGNED NULL, +KEY (latch, origid, destid) USING HASH, +KEY (latch, destid, origid) USING HASH +) ENGINE=OQGRAPH +data_table='oq_backing' origid='origid' destid='destid' weight='weight'; +flush tables; +show fields in oq_table; +Field Type Null Key Default Extra +latch varchar(32) YES MUL NULL +origid bigint(20) unsigned YES NULL +destid bigint(20) unsigned YES NULL +weight double YES NULL +seq bigint(20) unsigned YES NULL +linkid bigint(20) unsigned YES NULL +disconnect con1; +connection default; +show tables; +Tables_in_test +oq_backing +oq_table +drop table oq_table, oq_backing; diff --git a/storage/oqgraph/mysql-test/oqgraph/connections_mdev5748.test b/storage/oqgraph/mysql-test/oqgraph/connections_mdev5748.test new file mode 100644 index 00000000..9d7fab72 --- /dev/null +++ b/storage/oqgraph/mysql-test/oqgraph/connections_mdev5748.test @@ -0,0 +1,37 @@ +# +# MDEV-5748 Assertion `status_var.memory_used == 0' fails on disconnect after opening an OQGRAPH table +# + +# try to open oqgraph table in one connection and use in another: + +--connect (con1,localhost,root,,) + +CREATE TABLE oq_backing ( + origid INT UNSIGNED NOT NULL, + destid INT UNSIGNED NOT NULL, + weight DOUBLE NOT NULL, + PRIMARY KEY (origid, destid), + KEY (destid) +); + +CREATE TABLE oq_table ( + latch VARCHAR(32) NULL, + origid BIGINT UNSIGNED NULL, + destid BIGINT UNSIGNED NULL, + weight DOUBLE NULL, + seq BIGINT UNSIGNED NULL, + linkid BIGINT UNSIGNED NULL, + KEY (latch, origid, destid) USING HASH, + KEY (latch, destid, origid) USING HASH +) ENGINE=OQGRAPH +data_table='oq_backing' origid='origid' destid='destid' weight='weight'; + +flush tables; +show fields in oq_table; +--disconnect con1 + +--connection default +show tables; + +drop table oq_table, oq_backing; + diff --git a/storage/oqgraph/mysql-test/oqgraph/create_attr.result b/storage/oqgraph/mysql-test/oqgraph/create_attr.result new file mode 100644 index 00000000..c7c4b068 --- /dev/null +++ b/storage/oqgraph/mysql-test/oqgraph/create_attr.result @@ -0,0 +1,127 @@ +DROP TABLE IF EXISTS not_backing; +DROP TABLE IF EXISTS backing; +DROP TABLE IF EXISTS oqtable; +CREATE TABLE `not_backing` ( +id int(10) unsigned NOT NULL DEFAULT '0', +id2 int(10) unsigned NOT NULL DEFAULT '0', +info varchar(20) DEFAULT NULL, +KEY name (info) +) DEFAULT CHARSET=latin1; +CREATE TABLE backing ( +id int(10) unsigned NOT NULL DEFAULT '0', +id2 int(10) unsigned NOT NULL DEFAULT '0', +parent int(10) unsigned DEFAULT NULL, +weight real(10,4) NOT NULL DEFAULT 0.0, +info varchar(20) DEFAULT NULL, +not_id_type varchar(20) DEFAULT NULL, +not_weight_type varchar(20) DEFAULT NULL, +PRIMARY KEY (id), +KEY name (info) +) DEFAULT CHARSET=latin1; +CREATE TABLE oqtable ( latch varchar(32) NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH; +# Expect: 'Invalid OQGRAPH backing store description (unspecified or empty data_table attribute)' +DESCRIBE oqtable; +ERROR HY000: Got error -1 'Invalid OQGRAPH backing store description (unspecified or empty data_table attribute)' from OQGRAPH +DROP TABLE IF EXISTS oqtable; +CREATE TABLE oqtable ( latch varchar(32) NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, ORIGID='id', DESTID='id2'; +# Expect: 'Invalid OQGRAPH backing store description (unspecified or empty data_table attribute)' +DESCRIBE oqtable; +ERROR HY000: Got error -1 'Invalid OQGRAPH backing store description (unspecified or empty data_table attribute)' from OQGRAPH +DROP TABLE IF EXISTS oqtable; +CREATE TABLE oqtable ( latch varchar(32) NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='', ORIGID='id', DESTID='id2'; +# Expect: 'Invalid OQGRAPH backing store description (unspecified or empty data_table attribute)' +DESCRIBE oqtable; +ERROR HY000: Got error -1 'Invalid OQGRAPH backing store description (unspecified or empty data_table attribute)' from OQGRAPH +DROP TABLE IF EXISTS oqtable; +CREATE TABLE oqtable ( latch varchar(32) NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='', ORIGID='id'; +# Expect: 'Invalid OQGRAPH backing store description (unspecified or empty data_table attribute)' +DESCRIBE oqtable; +ERROR HY000: Got error -1 'Invalid OQGRAPH backing store description (unspecified or empty data_table attribute)' from OQGRAPH +DROP TABLE IF EXISTS oqtable; +CREATE TABLE oqtable ( latch varchar(32) NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='', DESTID='id2'; +# Expect: 'Invalid OQGRAPH backing store description (unspecified or empty data_table attribute)' +DESCRIBE oqtable; +ERROR HY000: Got error -1 'Invalid OQGRAPH backing store description (unspecified or empty data_table attribute)' from OQGRAPH +DROP TABLE IF EXISTS oqtable; +CREATE TABLE oqtable ( latch varchar(32) NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='bogus', ORIGID='id', DESTID='id2'; +# Expect: 'Table 'test.bogus' doesn't exist'' +DESCRIBE oqtable; +ERROR 42S02: Table 'test.bogus' doesn't exist +DROP TABLE IF EXISTS oqtable; +CREATE TABLE oqtable ( latch varchar(32) NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='not_backing'; +# Expect 'Invalid OQGRAPH backing store description (unspecified or empty origid attribute)' +DESCRIBE oqtable; +ERROR HY000: Got error -1 'Invalid OQGRAPH backing store description (unspecified or empty origid attribute)' from OQGRAPH +DROP TABLE IF EXISTS oqtable; +CREATE TABLE oqtable ( latch varchar(32) NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='backing', DESTID='id2'; +# Expect 'Invalid OQGRAPH backing store description (unspecified or empty origid attribute)' +DESCRIBE oqtable; +ERROR HY000: Got error -1 'Invalid OQGRAPH backing store description (unspecified or empty origid attribute)' from OQGRAPH +DROP TABLE IF EXISTS oqtable; +CREATE TABLE oqtable ( latch varchar(32) NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='backing',ORIGID='', DESTID='id2'; +# Expect 'Invalid OQGRAPH backing store description (unspecified or empty origid attribute)' +DESCRIBE oqtable; +ERROR HY000: Got error -1 'Invalid OQGRAPH backing store description (unspecified or empty origid attribute)' from OQGRAPH +DROP TABLE IF EXISTS oqtable; +CREATE TABLE oqtable ( latch varchar(32) NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='backing',ORIGID='bogus', DESTID='id2'; +# Expect Invalid OQGRAPH backing store ('/oqtable'.origid attribute not set to a valid column of 'backing')' +DESCRIBE oqtable; +ERROR HY000: Got error -1 'Invalid OQGRAPH backing store ('oqtable.origid' attribute not set to a valid column of 'backing')' from OQGRAPH +DROP TABLE IF EXISTS oqtable; +CREATE TABLE oqtable ( latch varchar(32) NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='backing',ORIGID='not_id_type', DESTID='id2'; +# Expect 'Column 'backing.not_id_type' is not a not-null integer type' +DESCRIBE oqtable; +ERROR HY000: Got error -1 'Column 'backing.not_id_type' (origid) is not a not-null integer type' from OQGRAPH +DROP TABLE IF EXISTS oqtable; +CREATE TABLE oqtable ( latch varchar(32) NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='backing',ORIGID='id'; +# Expect 'Invalid OQGRAPH backing store description (unspecified or empty destid attribute)' +DESCRIBE oqtable; +ERROR HY000: Got error -1 'Invalid OQGRAPH backing store description (unspecified or empty destid attribute)' from OQGRAPH +DROP TABLE IF EXISTS oqtable; +CREATE TABLE oqtable ( latch varchar(32) NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='backing',ORIGID='id',DESTID=''; +# Expect 'Invalid OQGRAPH backing store description (unspecified or empty destid attribute)' +DESCRIBE oqtable; +ERROR HY000: Got error -1 'Invalid OQGRAPH backing store description (unspecified or empty destid attribute)' from OQGRAPH +DROP TABLE IF EXISTS oqtable; +CREATE TABLE oqtable ( latch varchar(32) NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='backing',ORIGID='id',DESTID='bogus'; +# Expect Invalid OQGRAPH backing store ('/oqtable'.destid attribute not set to a valid column of 'backing')' +DESCRIBE oqtable; +ERROR HY000: Got error -1 'Invalid OQGRAPH backing store ('oqtable.destid' attribute not set to a valid column of 'backing')' from OQGRAPH +DROP TABLE IF EXISTS oqtable; +CREATE TABLE oqtable ( latch varchar(32) NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='backing',ORIGID='id',DESTID='not_id_type'; +# Expect 'Column 'backing.not_id_type' is not a not-null integer type' +DESCRIBE oqtable; +ERROR HY000: Got error -1 'Column 'backing.not_id_type' (destid) is not a not-null integer type or is a different type to origid attribute.' from OQGRAPH +DROP TABLE IF EXISTS oqtable; +CREATE TABLE oqtable ( latch varchar(32) NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='backing',ORIGID='id',DESTID='id'; +# Expect 'Invalid OQGRAPH backing store ('/oqtable'.destid attribute set to same column as origid attribute)' +DESCRIBE oqtable; +ERROR HY000: Got error -1 'Invalid OQGRAPH backing store ('oqtable.destid' attribute set to same column as origid attribute)' from OQGRAPH +DROP TABLE IF EXISTS oqtable; +CREATE TABLE oqtable ( latch varchar(32) NULL NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='backing',ORIGID='id',DESTID='id2',WEIGHT=''; +# Expect 'Invalid OQGRAPH backing store ('/oqtable'.weight attribute not set to a valid column of 'backing')' +DESCRIBE oqtable; +ERROR HY000: Got error -1 'Invalid OQGRAPH backing store ('oqtable.weight' attribute not set to a valid column of 'backing')' from OQGRAPH +DROP TABLE IF EXISTS oqtable; +CREATE TABLE oqtable ( latch varchar(32) NULL NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='backing',ORIGID='id',DESTID='id2',WEIGHT='bogus'; +# Expect 'Invalid OQGRAPH backing store ('/oqtable'.weight attribute not set to a valid column of 'backing')' +DESCRIBE oqtable; +ERROR HY000: Got error -1 'Invalid OQGRAPH backing store ('oqtable.weight' attribute not set to a valid column of 'backing')' from OQGRAPH +DROP TABLE IF EXISTS oqtable; +CREATE TABLE oqtable ( latch varchar(32) NULL NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='backing',ORIGID='id',DESTID='id2',WEIGHT='not_weight_type'; +# Expect 'Column 'backing.not_weight_type' is not a not-null real type' +DESCRIBE oqtable; +ERROR HY000: Got error -1 'Column 'backing.not_weight_type' (weight) is not a not-null real type' from OQGRAPH +DROP TABLE IF EXISTS oqtable; +CREATE TABLE oqtable ( latch varchar(32) NULL NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='backing',ORIGID='id',DESTID='id2',WEIGHT='weight'; +DESCRIBE oqtable; +Field Type Null Key Default Extra +latch varchar(32) YES MUL NULL +origid bigint(20) unsigned YES NULL +destid bigint(20) unsigned YES NULL +weight double YES NULL +seq bigint(20) unsigned YES NULL +linkid bigint(20) unsigned YES NULL +DROP TABLE IF EXISTS oqtable; +DROP TABLE IF EXISTS backing; +DROP TABLE IF EXISTS not_backing; diff --git a/storage/oqgraph/mysql-test/oqgraph/create_attr.test b/storage/oqgraph/mysql-test/oqgraph/create_attr.test new file mode 100644 index 00000000..c2ca4816 --- /dev/null +++ b/storage/oqgraph/mysql-test/oqgraph/create_attr.test @@ -0,0 +1,220 @@ +--disable_warnings +DROP TABLE IF EXISTS not_backing; +DROP TABLE IF EXISTS backing; +DROP TABLE IF EXISTS oqtable; +--enable_warnings + + +CREATE TABLE `not_backing` ( + id int(10) unsigned NOT NULL DEFAULT '0', + id2 int(10) unsigned NOT NULL DEFAULT '0', + info varchar(20) DEFAULT NULL, + KEY name (info) +) DEFAULT CHARSET=latin1; + +CREATE TABLE backing ( + id int(10) unsigned NOT NULL DEFAULT '0', + id2 int(10) unsigned NOT NULL DEFAULT '0', + parent int(10) unsigned DEFAULT NULL, + weight real(10,4) NOT NULL DEFAULT 0.0, + info varchar(20) DEFAULT NULL, + not_id_type varchar(20) DEFAULT NULL, + not_weight_type varchar(20) DEFAULT NULL, + PRIMARY KEY (id), + KEY name (info) +) DEFAULT CHARSET=latin1; + + +# oqgraph v2 create table should fail (missing attributes) +CREATE TABLE oqtable ( latch varchar(32) NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH; +--echo # Expect: 'Invalid OQGRAPH backing store description (unspecified or empty data_table attribute)' +--error 1296 +DESCRIBE oqtable; + + +# no table reference +--disable_warnings +DROP TABLE IF EXISTS oqtable; +--enable_warnings +CREATE TABLE oqtable ( latch varchar(32) NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, ORIGID='id', DESTID='id2'; +--echo # Expect: 'Invalid OQGRAPH backing store description (unspecified or empty data_table attribute)' +--error 1296 +DESCRIBE oqtable; + +# empty table reference +--disable_warnings +DROP TABLE IF EXISTS oqtable; +--enable_warnings +CREATE TABLE oqtable ( latch varchar(32) NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='', ORIGID='id', DESTID='id2'; +--echo # Expect: 'Invalid OQGRAPH backing store description (unspecified or empty data_table attribute)' +--error 1296 +DESCRIBE oqtable; + +# empty table reference +--disable_warnings +DROP TABLE IF EXISTS oqtable; +--enable_warnings +CREATE TABLE oqtable ( latch varchar(32) NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='', ORIGID='id'; +--echo # Expect: 'Invalid OQGRAPH backing store description (unspecified or empty data_table attribute)' +--error 1296 +DESCRIBE oqtable; + + +# empty table reference +--disable_warnings +DROP TABLE IF EXISTS oqtable; +--enable_warnings +CREATE TABLE oqtable ( latch varchar(32) NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='', DESTID='id2'; +--echo # Expect: 'Invalid OQGRAPH backing store description (unspecified or empty data_table attribute)' +--error 1296 +DESCRIBE oqtable; + +# non-existent table reference +--disable_warnings +DROP TABLE IF EXISTS oqtable; +--enable_warnings +CREATE TABLE oqtable ( latch varchar(32) NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='bogus', ORIGID='id', DESTID='id2'; +--echo # Expect: 'Table 'test.bogus' doesn't exist'' +--disable_warnings +--error 1146 +DESCRIBE oqtable; +--enable_warnings + +# Table exists but no orig or dest specified +--disable_warnings +DROP TABLE IF EXISTS oqtable; +--enable_warnings +CREATE TABLE oqtable ( latch varchar(32) NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='not_backing'; +--echo # Expect 'Invalid OQGRAPH backing store description (unspecified or empty origid attribute)' +--error 1296 +DESCRIBE oqtable; + +# missing origid +--disable_warnings +DROP TABLE IF EXISTS oqtable; +--enable_warnings +CREATE TABLE oqtable ( latch varchar(32) NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='backing', DESTID='id2'; +--echo # Expect 'Invalid OQGRAPH backing store description (unspecified or empty origid attribute)' +--error 1296 +DESCRIBE oqtable; + +# empty origid +--disable_warnings +DROP TABLE IF EXISTS oqtable; +--enable_warnings +CREATE TABLE oqtable ( latch varchar(32) NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='backing',ORIGID='', DESTID='id2'; +--echo # Expect 'Invalid OQGRAPH backing store description (unspecified or empty origid attribute)' +--error 1296 +DESCRIBE oqtable; + +# invalid origid reference +--disable_warnings +DROP TABLE IF EXISTS oqtable; +--enable_warnings +CREATE TABLE oqtable ( latch varchar(32) NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='backing',ORIGID='bogus', DESTID='id2'; +--echo # Expect Invalid OQGRAPH backing store ('/oqtable'.origid attribute not set to a valid column of 'backing')' +--error 1296 +DESCRIBE oqtable; + +# wrong type origid +--disable_warnings +DROP TABLE IF EXISTS oqtable; +--enable_warnings +CREATE TABLE oqtable ( latch varchar(32) NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='backing',ORIGID='not_id_type', DESTID='id2'; +--echo # Expect 'Column 'backing.not_id_type' is not a not-null integer type' +--error 1296 +DESCRIBE oqtable; + +# missing destid +--disable_warnings +DROP TABLE IF EXISTS oqtable; +--enable_warnings +CREATE TABLE oqtable ( latch varchar(32) NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='backing',ORIGID='id'; +--echo # Expect 'Invalid OQGRAPH backing store description (unspecified or empty destid attribute)' +--error 1296 +DESCRIBE oqtable; + +# empty destid +--disable_warnings +DROP TABLE IF EXISTS oqtable; +--enable_warnings +CREATE TABLE oqtable ( latch varchar(32) NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='backing',ORIGID='id',DESTID=''; +--echo # Expect 'Invalid OQGRAPH backing store description (unspecified or empty destid attribute)' +--error 1296 +DESCRIBE oqtable; + +# invalid destid reference +--disable_warnings +DROP TABLE IF EXISTS oqtable; +--enable_warnings +CREATE TABLE oqtable ( latch varchar(32) NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='backing',ORIGID='id',DESTID='bogus'; +--echo # Expect Invalid OQGRAPH backing store ('/oqtable'.destid attribute not set to a valid column of 'backing')' +--error 1296 +DESCRIBE oqtable; + +# wrong type destid +--disable_warnings +DROP TABLE IF EXISTS oqtable; +--enable_warnings +CREATE TABLE oqtable ( latch varchar(32) NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='backing',ORIGID='id',DESTID='not_id_type'; +--echo # Expect 'Column 'backing.not_id_type' is not a not-null integer type' +--error 1296 +DESCRIBE oqtable; + +# same origid and destid +--disable_warnings +DROP TABLE IF EXISTS oqtable; +--enable_warnings +CREATE TABLE oqtable ( latch varchar(32) NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='backing',ORIGID='id',DESTID='id'; +--echo # Expect 'Invalid OQGRAPH backing store ('/oqtable'.destid attribute set to same column as origid attribute)' +--error 1296 +DESCRIBE oqtable; + +# invalid weight reference +--disable_warnings +DROP TABLE IF EXISTS oqtable; +--enable_warnings +CREATE TABLE oqtable ( latch varchar(32) NULL NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='backing',ORIGID='id',DESTID='id2',WEIGHT=''; +--echo # Expect 'Invalid OQGRAPH backing store ('/oqtable'.weight attribute not set to a valid column of 'backing')' +--error 1296 +DESCRIBE oqtable; + +# invalid weight reference +--disable_warnings +DROP TABLE IF EXISTS oqtable; +--enable_warnings +CREATE TABLE oqtable ( latch varchar(32) NULL NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='backing',ORIGID='id',DESTID='id2',WEIGHT='bogus'; +--echo # Expect 'Invalid OQGRAPH backing store ('/oqtable'.weight attribute not set to a valid column of 'backing')' +--error 1296 +DESCRIBE oqtable; + +# wrong type weight +--disable_warnings +DROP TABLE IF EXISTS oqtable; +--enable_warnings +CREATE TABLE oqtable ( latch varchar(32) NULL NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='backing',ORIGID='id',DESTID='id2',WEIGHT='not_weight_type'; +--echo # Expect 'Column 'backing.not_weight_type' is not a not-null real type' +--error 1296 +DESCRIBE oqtable; + +# all valid +--disable_warnings +DROP TABLE IF EXISTS oqtable; +--enable_warnings +CREATE TABLE oqtable ( latch varchar(32) NULL NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='backing',ORIGID='id',DESTID='id2',WEIGHT='weight'; +DESCRIBE oqtable; + +#-- Expect an error if we attempt to use a view as the backing store +#-- 'VIEWs are not supported for an OQGRAPH backing store.' +#-- TODO + +#-- TODO - what happens if we make two tables with the same backing store? + +#-- TODO - what happens if data_table is a TEMPORARY table? + +# cleanup +--disable_warnings +DROP TABLE IF EXISTS oqtable; +DROP TABLE IF EXISTS backing; +DROP TABLE IF EXISTS not_backing; +--enable_warnings diff --git a/storage/oqgraph/mysql-test/oqgraph/create_attr_legacy.result b/storage/oqgraph/mysql-test/oqgraph/create_attr_legacy.result new file mode 100644 index 00000000..d3e22b4f --- /dev/null +++ b/storage/oqgraph/mysql-test/oqgraph/create_attr_legacy.result @@ -0,0 +1,150 @@ +DROP TABLE IF EXISTS not_backing; +DROP TABLE IF EXISTS backing; +DROP TABLE IF EXISTS oqtable; +CREATE TABLE `not_backing` ( +id int(10) unsigned NOT NULL DEFAULT '0', +info varchar(20) DEFAULT NULL, +KEY name (info) +) DEFAULT CHARSET=latin1; +CREATE TABLE backing ( +id int(10) unsigned NOT NULL DEFAULT '0', +nullparent int(10) unsigned DEFAULT NULL, +parent int(10) unsigned DEFAULT 1 NOT NULL, +weight real(10,4) NOT NULL DEFAULT 0.0, +info varchar(20) DEFAULT NULL, +not_id_type varchar(20) DEFAULT NULL, +not_weight_type varchar(20) DEFAULT NULL, +PRIMARY KEY (id), +KEY name (info) +) DEFAULT CHARSET=latin1; +SET GLOBAL oqgraph_allow_create_integer_latch=true; +The next warnings 1287 are expected +CREATE TABLE oqtable ( latch SMALLINT UNSIGNED NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH; +Warnings: +Warning 1287 'latch SMALLINT UNSIGNED NULL' is deprecated and will be removed in a future release. Please use 'latch VARCHAR(32) NULL' instead +DESCRIBE oqtable; +ERROR HY000: Got error -1 'Invalid OQGRAPH backing store description (unspecified or empty data_table attribute)' from OQGRAPH +DROP TABLE IF EXISTS oqtable; +CREATE TABLE oqtable ( latch SMALLINT UNSIGNED NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE=''; +Warnings: +Warning 1287 'latch SMALLINT UNSIGNED NULL' is deprecated and will be removed in a future release. Please use 'latch VARCHAR(32) NULL' instead +DESCRIBE oqtable; +ERROR HY000: Got error -1 'Invalid OQGRAPH backing store description (unspecified or empty data_table attribute)' from OQGRAPH +DROP TABLE IF EXISTS oqtable; +CREATE TABLE oqtable ( latch SMALLINT UNSIGNED NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='bogus'; +Warnings: +Warning 1287 'latch SMALLINT UNSIGNED NULL' is deprecated and will be removed in a future release. Please use 'latch VARCHAR(32) NULL' instead +DESCRIBE oqtable; +ERROR HY000: Got error -1 'Invalid OQGRAPH backing store description (unspecified or empty origid attribute)' from OQGRAPH +DROP TABLE IF EXISTS oqtable; +CREATE TABLE oqtable ( latch SMALLINT UNSIGNED NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='Ω Ohms Tennis Ball 〄'; +Warnings: +Warning 1287 'latch SMALLINT UNSIGNED NULL' is deprecated and will be removed in a future release. Please use 'latch VARCHAR(32) NULL' instead +DESCRIBE oqtable; +ERROR HY000: Got error -1 'Invalid OQGRAPH backing store description (unspecified or empty origid attribute)' from OQGRAPH +DROP TABLE IF EXISTS oqtable; +CREATE TABLE oqtable ( latch SMALLINT UNSIGNED NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='not_backing', ORIGID='id'; +Warnings: +Warning 1287 'latch SMALLINT UNSIGNED NULL' is deprecated and will be removed in a future release. Please use 'latch VARCHAR(32) NULL' instead +DESCRIBE oqtable; +ERROR HY000: Got error -1 'Invalid OQGRAPH backing store description (unspecified or empty destid attribute)' from OQGRAPH +DROP TABLE IF EXISTS oqtable; +CREATE TABLE oqtable ( latch SMALLINT UNSIGNED NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='backing',ORIGID=''; +Warnings: +Warning 1287 'latch SMALLINT UNSIGNED NULL' is deprecated and will be removed in a future release. Please use 'latch VARCHAR(32) NULL' instead +DESCRIBE oqtable; +ERROR HY000: Got error -1 'Invalid OQGRAPH backing store description (unspecified or empty origid attribute)' from OQGRAPH +DROP TABLE IF EXISTS oqtable; +CREATE TABLE oqtable ( latch SMALLINT UNSIGNED NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='backing',ORIGID='bogus'; +Warnings: +Warning 1287 'latch SMALLINT UNSIGNED NULL' is deprecated and will be removed in a future release. Please use 'latch VARCHAR(32) NULL' instead +DESCRIBE oqtable; +ERROR HY000: Got error -1 'Invalid OQGRAPH backing store description (unspecified or empty destid attribute)' from OQGRAPH +DROP TABLE IF EXISTS oqtable; +CREATE TABLE oqtable ( latch SMALLINT UNSIGNED NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='backing',ORIGID='not_id_type'; +Warnings: +Warning 1287 'latch SMALLINT UNSIGNED NULL' is deprecated and will be removed in a future release. Please use 'latch VARCHAR(32) NULL' instead +DESCRIBE oqtable; +ERROR HY000: Got error -1 'Invalid OQGRAPH backing store description (unspecified or empty destid attribute)' from OQGRAPH +DROP TABLE IF EXISTS oqtable; +CREATE TABLE oqtable ( latch SMALLINT UNSIGNED NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='backing',ORIGID='id'; +Warnings: +Warning 1287 'latch SMALLINT UNSIGNED NULL' is deprecated and will be removed in a future release. Please use 'latch VARCHAR(32) NULL' instead +DESCRIBE oqtable; +ERROR HY000: Got error -1 'Invalid OQGRAPH backing store description (unspecified or empty destid attribute)' from OQGRAPH +DROP TABLE IF EXISTS oqtable; +CREATE TABLE oqtable ( latch SMALLINT UNSIGNED NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='backing',ORIGID='id',DESTID=''; +Warnings: +Warning 1287 'latch SMALLINT UNSIGNED NULL' is deprecated and will be removed in a future release. Please use 'latch VARCHAR(32) NULL' instead +DESCRIBE oqtable; +ERROR HY000: Got error -1 'Invalid OQGRAPH backing store description (unspecified or empty destid attribute)' from OQGRAPH +DROP TABLE IF EXISTS oqtable; +CREATE TABLE oqtable ( latch SMALLINT UNSIGNED NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='backing',ORIGID='id',DESTID='bogus'; +Warnings: +Warning 1287 'latch SMALLINT UNSIGNED NULL' is deprecated and will be removed in a future release. Please use 'latch VARCHAR(32) NULL' instead +DESCRIBE oqtable; +ERROR HY000: Got error -1 'Invalid OQGRAPH backing store ('oqtable.destid' attribute not set to a valid column of 'backing')' from OQGRAPH +DROP TABLE IF EXISTS oqtable; +CREATE TABLE oqtable ( latch SMALLINT UNSIGNED NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='backing',ORIGID='id',DESTID='not_id_type'; +Warnings: +Warning 1287 'latch SMALLINT UNSIGNED NULL' is deprecated and will be removed in a future release. Please use 'latch VARCHAR(32) NULL' instead +DESCRIBE oqtable; +ERROR HY000: Got error -1 'Column 'backing.not_id_type' (destid) is not a not-null integer type or is a different type to origid attribute.' from OQGRAPH +DROP TABLE IF EXISTS oqtable; +CREATE TABLE oqtable ( latch SMALLINT UNSIGNED NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='backing',ORIGID='bogus',DESTID='id'; +Warnings: +Warning 1287 'latch SMALLINT UNSIGNED NULL' is deprecated and will be removed in a future release. Please use 'latch VARCHAR(32) NULL' instead +DESCRIBE oqtable; +ERROR HY000: Got error -1 'Invalid OQGRAPH backing store ('oqtable.origid' attribute not set to a valid column of 'backing')' from OQGRAPH +DROP TABLE IF EXISTS oqtable; +CREATE TABLE oqtable ( latch SMALLINT UNSIGNED NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='backing',ORIGID='not_id_type',DESTID='id'; +Warnings: +Warning 1287 'latch SMALLINT UNSIGNED NULL' is deprecated and will be removed in a future release. Please use 'latch VARCHAR(32) NULL' instead +DESCRIBE oqtable; +ERROR HY000: Got error -1 'Column 'backing.not_id_type' (origid) is not a not-null integer type' from OQGRAPH +DROP TABLE IF EXISTS oqtable; +CREATE TABLE oqtable ( latch SMALLINT UNSIGNED NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='backing',ORIGID='id',DESTID='id'; +Warnings: +Warning 1287 'latch SMALLINT UNSIGNED NULL' is deprecated and will be removed in a future release. Please use 'latch VARCHAR(32) NULL' instead +DESCRIBE oqtable; +ERROR HY000: Got error -1 'Invalid OQGRAPH backing store ('oqtable.destid' attribute set to same column as origid attribute)' from OQGRAPH +DROP TABLE IF EXISTS oqtable; +CREATE TABLE oqtable ( latch SMALLINT UNSIGNED NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='backing',ORIGID='id',DESTID='parent',WEIGHT='bogus'; +Warnings: +Warning 1287 'latch SMALLINT UNSIGNED NULL' is deprecated and will be removed in a future release. Please use 'latch VARCHAR(32) NULL' instead +DESCRIBE oqtable; +ERROR HY000: Got error -1 'Invalid OQGRAPH backing store ('oqtable.weight' attribute not set to a valid column of 'backing')' from OQGRAPH +DROP TABLE IF EXISTS oqtable; +CREATE TABLE oqtable ( latch SMALLINT UNSIGNED NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='backing',ORIGID='id',DESTID='parent',WEIGHT='not_weight_type'; +Warnings: +Warning 1287 'latch SMALLINT UNSIGNED NULL' is deprecated and will be removed in a future release. Please use 'latch VARCHAR(32) NULL' instead +DESCRIBE oqtable; +ERROR HY000: Got error -1 'Column 'backing.not_weight_type' (weight) is not a not-null real type' from OQGRAPH +DROP TABLE IF EXISTS oqtable; +CREATE TABLE oqtable ( latch SMALLINT UNSIGNED NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='backing',ORIGID='nullparent',DESTID='id',WEIGHT='weight'; +Warnings: +Warning 1287 'latch SMALLINT UNSIGNED NULL' is deprecated and will be removed in a future release. Please use 'latch VARCHAR(32) NULL' instead +DESCRIBE oqtable; +ERROR HY000: Got error -1 'Column 'backing.nullparent' (origid) is not a not-null integer type' from OQGRAPH +DROP TABLE IF EXISTS oqtable; +CREATE TABLE oqtable ( latch SMALLINT UNSIGNED NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='backing',ORIGID='id',DESTID='nullparent',WEIGHT='weight'; +Warnings: +Warning 1287 'latch SMALLINT UNSIGNED NULL' is deprecated and will be removed in a future release. Please use 'latch VARCHAR(32) NULL' instead +DESCRIBE oqtable; +ERROR HY000: Got error -1 'Column 'backing.nullparent' (destid) is not a not-null integer type or is a different type to origid attribute.' from OQGRAPH +DROP TABLE IF EXISTS oqtable; +CREATE TABLE oqtable ( latch SMALLINT UNSIGNED NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='backing',ORIGID='id',DESTID='parent',WEIGHT='weight'; +Warnings: +Warning 1287 'latch SMALLINT UNSIGNED NULL' is deprecated and will be removed in a future release. Please use 'latch VARCHAR(32) NULL' instead +DESCRIBE oqtable; +Field Type Null Key Default Extra +latch smallint(5) unsigned YES MUL NULL +origid bigint(20) unsigned YES NULL +destid bigint(20) unsigned YES NULL +weight double YES NULL +seq bigint(20) unsigned YES NULL +linkid bigint(20) unsigned YES NULL +DROP TABLE IF EXISTS oqtable; +DROP TABLE IF EXISTS backing; +DROP TABLE IF EXISTS not_backing; +SET GLOBAL oqgraph_allow_create_integer_latch=false; diff --git a/storage/oqgraph/mysql-test/oqgraph/create_attr_legacy.test b/storage/oqgraph/mysql-test/oqgraph/create_attr_legacy.test new file mode 100644 index 00000000..7fe58d3e --- /dev/null +++ b/storage/oqgraph/mysql-test/oqgraph/create_attr_legacy.test @@ -0,0 +1,202 @@ +--disable_warnings +DROP TABLE IF EXISTS not_backing; +DROP TABLE IF EXISTS backing; +DROP TABLE IF EXISTS oqtable; +--enable_warnings + + +CREATE TABLE `not_backing` ( + id int(10) unsigned NOT NULL DEFAULT '0', + info varchar(20) DEFAULT NULL, + KEY name (info) +) DEFAULT CHARSET=latin1; + +CREATE TABLE backing ( + id int(10) unsigned NOT NULL DEFAULT '0', + nullparent int(10) unsigned DEFAULT NULL, + parent int(10) unsigned DEFAULT 1 NOT NULL, + weight real(10,4) NOT NULL DEFAULT 0.0, + info varchar(20) DEFAULT NULL, + not_id_type varchar(20) DEFAULT NULL, + not_weight_type varchar(20) DEFAULT NULL, + PRIMARY KEY (id), + KEY name (info) +) DEFAULT CHARSET=latin1; + +# Here we enable scaffolding to let us create a deprecated table +# so we can check that the new code will still allow queries to be performed +# on a legacy database +# It should still generate a warning (1287) - but I don't know how to test for that +# +# latch SMALLINT UNSIGNED NULL' is deprecated and will be removed in a future +# release. Please use 'latch VARCHAR(32) NULL' instead +# +SET GLOBAL oqgraph_allow_create_integer_latch=true; +--echo The next warnings 1287 are expected + + +# oqgraph v2 create table should fail (missing attributes) +CREATE TABLE oqtable ( latch SMALLINT UNSIGNED NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH; +--error 1296 +DESCRIBE oqtable; + +# attributes test +# empty table reference +--disable_warnings +DROP TABLE IF EXISTS oqtable; +--enable_warnings +CREATE TABLE oqtable ( latch SMALLINT UNSIGNED NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE=''; +--error 1296 +DESCRIBE oqtable; + +# non-existent table reference +--disable_warnings +DROP TABLE IF EXISTS oqtable; +--enable_warnings +CREATE TABLE oqtable ( latch SMALLINT UNSIGNED NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='bogus'; +--error 1296 +DESCRIBE oqtable; + +# UTF in table name, make sure it doesnt crash +--disable_warnings +DROP TABLE IF EXISTS oqtable; +--enable_warnings +CREATE TABLE oqtable ( latch SMALLINT UNSIGNED NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='Ω Ohms Tennis Ball 〄'; +--error 1296 +DESCRIBE oqtable; + +# Invalid backing table (backing table has no primary key) +--disable_warnings +DROP TABLE IF EXISTS oqtable; +--enable_warnings +CREATE TABLE oqtable ( latch SMALLINT UNSIGNED NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='not_backing', ORIGID='id'; +--error 1296 +DESCRIBE oqtable; + +# table with empty origid +--disable_warnings +DROP TABLE IF EXISTS oqtable; +--enable_warnings +CREATE TABLE oqtable ( latch SMALLINT UNSIGNED NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='backing',ORIGID=''; +--error 1296 +DESCRIBE oqtable; + +# invalid origid reference +--disable_warnings +DROP TABLE IF EXISTS oqtable; +--enable_warnings +CREATE TABLE oqtable ( latch SMALLINT UNSIGNED NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='backing',ORIGID='bogus'; +--error 1296 +DESCRIBE oqtable; + +# wrong type origid +--disable_warnings +DROP TABLE IF EXISTS oqtable; +--enable_warnings +CREATE TABLE oqtable ( latch SMALLINT UNSIGNED NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='backing',ORIGID='not_id_type'; +--error 1296 +DESCRIBE oqtable; + +# missing destid +--disable_warnings +DROP TABLE IF EXISTS oqtable; +--enable_warnings +CREATE TABLE oqtable ( latch SMALLINT UNSIGNED NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='backing',ORIGID='id'; +--error 1296 +DESCRIBE oqtable; + +# empty destid +--disable_warnings +DROP TABLE IF EXISTS oqtable; +--enable_warnings +CREATE TABLE oqtable ( latch SMALLINT UNSIGNED NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='backing',ORIGID='id',DESTID=''; +--error 1296 +DESCRIBE oqtable; + +# invalid destid reference +--disable_warnings +DROP TABLE IF EXISTS oqtable; +--enable_warnings +CREATE TABLE oqtable ( latch SMALLINT UNSIGNED NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='backing',ORIGID='id',DESTID='bogus'; +--error 1296 +DESCRIBE oqtable; + +# wrong type destid +--disable_warnings +DROP TABLE IF EXISTS oqtable; +--enable_warnings +CREATE TABLE oqtable ( latch SMALLINT UNSIGNED NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='backing',ORIGID='id',DESTID='not_id_type'; +--error 1296 +DESCRIBE oqtable; + +# invalid origid with valid destid +--disable_warnings +DROP TABLE IF EXISTS oqtable; +--enable_warnings +CREATE TABLE oqtable ( latch SMALLINT UNSIGNED NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='backing',ORIGID='bogus',DESTID='id'; +--error 1296 +DESCRIBE oqtable; + +# wrong type origid with valid destid +--disable_warnings +DROP TABLE IF EXISTS oqtable; +--enable_warnings +CREATE TABLE oqtable ( latch SMALLINT UNSIGNED NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='backing',ORIGID='not_id_type',DESTID='id'; +--error 1296 +DESCRIBE oqtable; + +# same origid and destid +--disable_warnings +DROP TABLE IF EXISTS oqtable; +--enable_warnings +CREATE TABLE oqtable ( latch SMALLINT UNSIGNED NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='backing',ORIGID='id',DESTID='id'; +--error 1296 +DESCRIBE oqtable; + +# invalid weight reference +--disable_warnings +DROP TABLE IF EXISTS oqtable; +--enable_warnings +CREATE TABLE oqtable ( latch SMALLINT UNSIGNED NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='backing',ORIGID='id',DESTID='parent',WEIGHT='bogus'; +--error 1296 +DESCRIBE oqtable; + +# wrong type weight +--disable_warnings +DROP TABLE IF EXISTS oqtable; +--enable_warnings +CREATE TABLE oqtable ( latch SMALLINT UNSIGNED NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='backing',ORIGID='id',DESTID='parent',WEIGHT='not_weight_type'; +--error 1296 +DESCRIBE oqtable; + +# NULLABLE ORIGID +--disable_warnings +DROP TABLE IF EXISTS oqtable; +--enable_warnings +CREATE TABLE oqtable ( latch SMALLINT UNSIGNED NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='backing',ORIGID='nullparent',DESTID='id',WEIGHT='weight'; +--error 1296 +DESCRIBE oqtable; + +# NULLABLE DESTID +--disable_warnings +DROP TABLE IF EXISTS oqtable; +--enable_warnings +CREATE TABLE oqtable ( latch SMALLINT UNSIGNED NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='backing',ORIGID='id',DESTID='nullparent',WEIGHT='weight'; +--error 1296 +DESCRIBE oqtable; + +# all valid +--disable_warnings +DROP TABLE IF EXISTS oqtable; +--enable_warnings +CREATE TABLE oqtable ( latch SMALLINT UNSIGNED NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH, DATA_TABLE='backing',ORIGID='id',DESTID='parent',WEIGHT='weight'; +DESCRIBE oqtable; + +# cleanup +--disable_warnings +DROP TABLE IF EXISTS oqtable; +DROP TABLE IF EXISTS backing; +DROP TABLE IF EXISTS not_backing; +--enable_warnings +SET GLOBAL oqgraph_allow_create_integer_latch=false; + diff --git a/storage/oqgraph/mysql-test/oqgraph/general-Aria.result b/storage/oqgraph/mysql-test/oqgraph/general-Aria.result new file mode 100644 index 00000000..bd0f7ed9 --- /dev/null +++ b/storage/oqgraph/mysql-test/oqgraph/general-Aria.result @@ -0,0 +1,1593 @@ +DROP TABLE IF EXISTS graph_base; +DROP TABLE IF EXISTS graph; +DROP TABLE IF EXISTS graph2; +Performing OQGraph General test suite for ENGINE=Aria +CREATE TABLE graph_base ( +from_id INT UNSIGNED NOT NULL, +to_id INT UNSIGNED NOT NULL, +PRIMARY KEY (from_id,to_id), +INDEX (to_id) +) ENGINE= Aria ; +CREATE TABLE graph ENGINE=OQGRAPH DATA_TABLE='graph_base' ORIGID='from_id', DESTID='to_id'; +select * from graph; +latch origid destid weight seq linkid +INSERT INTO graph_base(from_id, to_id) VALUES (1,2), (2,1); +INSERT INTO graph_base(from_id, to_id) VALUES (1,3), (3,1); +INSERT INTO graph_base(from_id, to_id) VALUES (3,4), (4,3); +INSERT INTO graph_base(from_id, to_id) VALUES (5,6), (6,5); +INSERT INTO graph_base(from_id, to_id) VALUES (5,7); +INSERT INTO graph_base(from_id, to_id) VALUES (9,9); +INSERT INTO graph_base(from_id, to_id) VALUES (10,11); +INSERT INTO graph_base(from_id, to_id) VALUES (11,12); +INSERT INTO graph_base(from_id, to_id) VALUES (12,10); +# Return all edges +SELECT * FROM graph; +latch origid destid weight seq linkid +NULL 1 2 1 NULL NULL +NULL 2 1 1 NULL NULL +NULL 1 3 1 NULL NULL +NULL 3 1 1 NULL NULL +NULL 3 4 1 NULL NULL +NULL 4 3 1 NULL NULL +NULL 5 6 1 NULL NULL +NULL 6 5 1 NULL NULL +NULL 5 7 1 NULL NULL +NULL 9 9 1 NULL NULL +NULL 10 11 1 NULL NULL +NULL 11 12 1 NULL NULL +NULL 12 10 1 NULL NULL +# Currently count should be 13 +SELECT count(*) FROM graph; +count(*) +13 +# Return all edges when latch is NULL - this is different to latch='' and same as no where clause +SELECT * FROM graph where latch is NULL; +latch origid destid weight seq linkid +NULL 1 2 1 NULL NULL +NULL 2 1 1 NULL NULL +NULL 1 3 1 NULL NULL +NULL 3 1 1 NULL NULL +NULL 3 4 1 NULL NULL +NULL 4 3 1 NULL NULL +NULL 5 6 1 NULL NULL +NULL 6 5 1 NULL NULL +NULL 5 7 1 NULL NULL +NULL 9 9 1 NULL NULL +NULL 10 11 1 NULL NULL +NULL 11 12 1 NULL NULL +NULL 12 10 1 NULL NULL +# Return all vertices, and subsets of vertices +SELECT * FROM graph where latch=''; +latch origid destid weight seq linkid + NULL NULL NULL NULL 1 + NULL NULL NULL NULL 2 + NULL NULL NULL NULL 3 + NULL NULL NULL NULL 4 + NULL NULL NULL NULL 5 + NULL NULL NULL NULL 6 + NULL NULL NULL NULL 7 + NULL NULL NULL NULL 9 + NULL NULL NULL NULL 10 + NULL NULL NULL NULL 11 + NULL NULL NULL NULL 12 +SELECT * FROM graph where latch='0'; +latch origid destid weight seq linkid +0 NULL NULL NULL NULL 1 +0 NULL NULL NULL NULL 2 +0 NULL NULL NULL NULL 3 +0 NULL NULL NULL NULL 4 +0 NULL NULL NULL NULL 5 +0 NULL NULL NULL NULL 6 +0 NULL NULL NULL NULL 7 +0 NULL NULL NULL NULL 9 +0 NULL NULL NULL NULL 10 +0 NULL NULL NULL NULL 11 +0 NULL NULL NULL NULL 12 +# Currently count should be 11 +SELECT count(*) FROM graph where latch=''; +count(*) +11 +SELECT * FROM graph where latch='' and linkid = 2; +latch origid destid weight seq linkid + NULL NULL NULL NULL 2 +SELECT * FROM graph where latch='' and (linkid > 2 and linkid < 6); +latch origid destid weight seq linkid + NULL NULL NULL NULL 3 + NULL NULL NULL NULL 4 + NULL NULL NULL NULL 5 +SELECT * FROM graph where latch='' and linkid = NULL; +latch origid destid weight seq linkid +SELECT * FROM graph where latch='' and linkid = 666; +latch origid destid weight seq linkid +SELECT origid as `from`, linkid as `to` FROM graph where latch='' and origid = 1; +from to +1 3 +1 2 +SELECT origid as `from`, linkid as `to` FROM graph where latch='' and origid = 2; +from to +2 1 +SELECT origid as `from`, linkid as `to` FROM graph where latch='' and origid = 4; +from to +4 3 +SELECT origid as `from`, linkid as `to` FROM graph where latch='' and origid = 9; +from to +9 9 +SELECT origid as `from`, linkid as `to` FROM graph where latch='' and origid = 10; +from to +10 11 +SELECT origid as `from`, linkid as `to` FROM graph where latch='' and origid = NULL; +from to +SELECT origid as `from`, linkid as `to` FROM graph where latch='' and origid = 666; +from to +SELECT linkid as `from`, destid as `to` FROM graph where latch='' and destid = 1; +from to +3 1 +2 1 +SELECT linkid as `from`, destid as `to` FROM graph where latch='' and destid = 2; +from to +1 2 +SELECT linkid as `from`, destid as `to` FROM graph where latch='' and destid = 4; +from to +3 4 +SELECT linkid as `from`, destid as `to` FROM graph where latch='' and destid = 9; +from to +9 9 +SELECT linkid as `from`, destid as `to` FROM graph where latch='' and destid = 10; +from to +12 10 +SELECT linkid as `from`, destid as `to` FROM graph where latch='' and destid = NULL; +from to +SELECT linkid as `from`, destid as `to` FROM graph where latch='' and destid = 666; +from to +SELECT * FROM graph where latch='0'; +latch origid destid weight seq linkid +0 NULL NULL NULL NULL 1 +0 NULL NULL NULL NULL 2 +0 NULL NULL NULL NULL 3 +0 NULL NULL NULL NULL 4 +0 NULL NULL NULL NULL 5 +0 NULL NULL NULL NULL 6 +0 NULL NULL NULL NULL 7 +0 NULL NULL NULL NULL 9 +0 NULL NULL NULL NULL 10 +0 NULL NULL NULL NULL 11 +0 NULL NULL NULL NULL 12 +SELECT count(*) FROM graph where latch='0'; +count(*) +11 +SELECT * FROM graph where latch='0' and linkid = 2; +latch origid destid weight seq linkid +0 NULL NULL NULL NULL 2 +SELECT * FROM graph where latch='0' and (linkid > 2 and linkid < 6); +latch origid destid weight seq linkid +0 NULL NULL NULL NULL 3 +0 NULL NULL NULL NULL 4 +0 NULL NULL NULL NULL 5 +SELECT origid as `from`, linkid as `to` FROM graph where latch='0' and origid = 1; +from to +1 3 +1 2 +SELECT origid as `from`, linkid as `to` FROM graph where latch='0' and origid = 2; +from to +2 1 +SELECT origid as `from`, linkid as `to` FROM graph where latch='0' and origid = 4; +from to +4 3 +SELECT origid as `from`, linkid as `to` FROM graph where latch='0' and origid = 9; +from to +9 9 +SELECT origid as `from`, linkid as `to` FROM graph where latch='0' and origid = 10; +from to +10 11 +SELECT linkid as `from`, destid as `to` FROM graph where latch='0' and destid = 1; +from to +3 1 +2 1 +SELECT linkid as `from`, destid as `to` FROM graph where latch='0' and destid = 2; +from to +1 2 +SELECT linkid as `from`, destid as `to` FROM graph where latch='0' and destid = 4; +from to +3 4 +SELECT linkid as `from`, destid as `to` FROM graph where latch='0' and destid = 9; +from to +9 9 +SELECT linkid as `from`, destid as `to` FROM graph where latch='0' and destid = 10; +from to +12 10 +# Leaves search tests +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 4; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 5; +latch origid destid weight seq linkid +leaves 5 NULL 1 1 7 +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 6; +latch origid destid weight seq linkid +leaves 6 NULL 2 1 7 +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 7; +latch origid destid weight seq linkid +leaves 7 NULL 0 1 7 +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 8; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 9; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 10; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 11; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 12; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 4; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 5; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 6; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 7; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 8; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 9; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 10; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 11; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 12; +latch origid destid weight seq linkid +INSERT INTO graph_base(from_id, to_id) VALUES (10,13); +INSERT INTO graph_base(from_id, to_id) VALUES (11,14); +INSERT INTO graph_base(from_id, to_id) VALUES (12,15); +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 10; +latch origid destid weight seq linkid +leaves 10 NULL 3 3 15 +leaves 10 NULL 2 2 14 +leaves 10 NULL 1 1 13 +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 11; +latch origid destid weight seq linkid +leaves 11 NULL 3 3 13 +leaves 11 NULL 2 2 15 +leaves 11 NULL 1 1 14 +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 12; +latch origid destid weight seq linkid +leaves 12 NULL 3 3 14 +leaves 12 NULL 2 2 13 +leaves 12 NULL 1 1 15 +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 13; +latch origid destid weight seq linkid +leaves 13 NULL 0 1 13 +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 14; +latch origid destid weight seq linkid +leaves 14 NULL 0 1 14 +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 15; +latch origid destid weight seq linkid +leaves 15 NULL 0 1 15 +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 10; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 11; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 12; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 13; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 14; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 15; +latch origid destid weight seq linkid +DELETE FROM graph_base where from_id=10 and to_id=13; +DELETE FROM graph_base where from_id=11 and to_id=14; +DELETE FROM graph_base where from_id=12 and to_id=15; +INSERT INTO graph_base(from_id, to_id) VALUES (13,10); +INSERT INTO graph_base(from_id, to_id) VALUES (14,11); +INSERT INTO graph_base(from_id, to_id) VALUES (15,12); +INSERT INTO graph_base(from_id, to_id) VALUES (16,1); +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 10; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 11; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 12; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 13; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 14; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 15; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 16; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 10; +latch origid destid weight seq linkid +leaves NULL 10 3 3 14 +leaves NULL 10 2 2 15 +leaves NULL 10 1 1 13 +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 11; +latch origid destid weight seq linkid +leaves NULL 11 3 3 15 +leaves NULL 11 2 2 13 +leaves NULL 11 1 1 14 +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 12; +latch origid destid weight seq linkid +leaves NULL 12 3 3 13 +leaves NULL 12 2 2 14 +leaves NULL 12 1 1 15 +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 13; +latch origid destid weight seq linkid +leaves NULL 13 0 1 13 +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 14; +latch origid destid weight seq linkid +leaves NULL 14 0 1 14 +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 15; +latch origid destid weight seq linkid +leaves NULL 15 0 1 15 +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 1; +latch origid destid weight seq linkid +leaves NULL 1 1 1 16 +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 2; +latch origid destid weight seq linkid +leaves NULL 2 2 1 16 +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 3; +latch origid destid weight seq linkid +leaves NULL 3 2 1 16 +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 4; +latch origid destid weight seq linkid +leaves NULL 4 3 1 16 +DELETE FROM graph_base where from_id=13 and to_id=10; +DELETE FROM graph_base where from_id=14 and to_id=11; +DELETE FROM graph_base where from_id=15 and to_id=12; +DELETE FROM graph_base where from_id=16 and to_id=1; +SELECT * FROM graph WHERE latch='leaves' AND origid=1 AND destid=2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch='leaves' AND origid=1 AND destid=3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch='leaves' AND origid=1 AND destid=4; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch='leaves' AND origid=6 AND destid=7; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch='leaves' AND origid=10 AND destid=11; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch='leaves' AND origid=10 AND destid=12; +latch origid destid weight seq linkid +# Breadth-first search tests +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 1; +latch origid destid weight seq linkid +breadth_first 1 NULL 2 4 4 +breadth_first 1 NULL 1 3 3 +breadth_first 1 NULL 1 2 2 +breadth_first 1 NULL 0 1 1 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 2; +latch origid destid weight seq linkid +breadth_first 2 NULL 3 4 4 +breadth_first 2 NULL 2 3 3 +breadth_first 2 NULL 1 2 1 +breadth_first 2 NULL 0 1 2 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 3; +latch origid destid weight seq linkid +breadth_first 3 NULL 2 4 2 +breadth_first 3 NULL 1 3 4 +breadth_first 3 NULL 1 2 1 +breadth_first 3 NULL 0 1 3 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 4; +latch origid destid weight seq linkid +breadth_first 4 NULL 3 4 2 +breadth_first 4 NULL 2 3 1 +breadth_first 4 NULL 1 2 3 +breadth_first 4 NULL 0 1 4 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 5; +latch origid destid weight seq linkid +breadth_first 5 NULL 1 3 7 +breadth_first 5 NULL 1 2 6 +breadth_first 5 NULL 0 1 5 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 6; +latch origid destid weight seq linkid +breadth_first 6 NULL 2 3 7 +breadth_first 6 NULL 1 2 5 +breadth_first 6 NULL 0 1 6 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 7; +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 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 9; +latch origid destid weight seq linkid +breadth_first 9 NULL 0 1 9 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 10; +latch origid destid weight seq linkid +breadth_first 10 NULL 2 3 12 +breadth_first 10 NULL 1 2 11 +breadth_first 10 NULL 0 1 10 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 11; +latch origid destid weight seq linkid +breadth_first 11 NULL 2 3 10 +breadth_first 11 NULL 1 2 12 +breadth_first 11 NULL 0 1 11 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 12; +latch origid destid weight seq linkid +breadth_first 12 NULL 2 3 11 +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 +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 +breadth_first 1 NULL 1 2 2 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 2 AND weight = 1; +latch origid destid weight seq linkid +breadth_first 2 NULL 1 2 1 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 3 AND weight = 1; +latch origid destid weight seq linkid +breadth_first 3 NULL 1 3 4 +breadth_first 3 NULL 1 2 1 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 4 AND weight = 1; +latch origid destid weight seq linkid +breadth_first 4 NULL 1 2 3 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 5 AND weight = 1; +latch origid destid weight seq linkid +breadth_first 5 NULL 1 3 7 +breadth_first 5 NULL 1 2 6 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 6 AND weight = 1; +latch origid destid weight seq linkid +breadth_first 6 NULL 1 2 5 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 7 AND weight = 1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 8 AND weight = 1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 9 AND weight = 1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 10 AND weight = 1; +latch origid destid weight seq linkid +breadth_first 10 NULL 1 2 11 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 11 AND weight = 1; +latch origid destid weight seq linkid +breadth_first 11 NULL 1 2 12 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 12 AND weight = 1; +latch origid destid weight seq linkid +breadth_first 12 NULL 1 2 10 +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 1 AND weight = 1; +count(*) +2 +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 2 AND weight = 1; +count(*) +1 +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 3 AND weight = 1; +count(*) +2 +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 4 AND weight = 1; +count(*) +1 +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 5 AND weight = 1; +count(*) +2 +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 6 AND weight = 1; +count(*) +1 +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 7 AND weight = 1; +count(*) +0 +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 8 AND weight = 1; +count(*) +0 +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 9 AND weight = 1; +count(*) +0 +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 10 AND weight = 1; +count(*) +1 +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 11 AND weight = 1; +count(*) +1 +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 12 AND weight = 1; +count(*) +1 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 1 AND weight = 2; +latch origid destid weight seq linkid +breadth_first 1 NULL 2 4 4 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 2 AND weight = 2; +latch origid destid weight seq linkid +breadth_first 2 NULL 2 3 3 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 3 AND weight = 2; +latch origid destid weight seq linkid +breadth_first 3 NULL 2 4 2 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 4 AND weight = 2; +latch origid destid weight seq linkid +breadth_first 4 NULL 2 3 1 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 5 AND weight = 2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 6 AND weight = 2; +latch origid destid weight seq linkid +breadth_first 6 NULL 2 3 7 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 7 AND weight = 2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 8 AND weight = 2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 9 AND weight = 2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 10 AND weight = 2; +latch origid destid weight seq linkid +breadth_first 10 NULL 2 3 12 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 11 AND weight = 2; +latch origid destid weight seq linkid +breadth_first 11 NULL 2 3 10 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 12 AND weight = 2; +latch origid destid weight seq linkid +breadth_first 12 NULL 2 3 11 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 1 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 2 AND weight = 3; +latch origid destid weight seq linkid +breadth_first 2 NULL 3 4 4 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 3 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 4 AND weight = 3; +latch origid destid weight seq linkid +breadth_first 4 NULL 3 4 2 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 5 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 6 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 7 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 8 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 9 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 10 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 11 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 12 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 1 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +breadth_first 1 NULL 2 4 4 +breadth_first 1 NULL 1 3 3 +breadth_first 1 NULL 1 2 2 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 2 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +breadth_first 2 NULL 2 3 3 +breadth_first 2 NULL 1 2 1 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 3 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +breadth_first 3 NULL 2 4 2 +breadth_first 3 NULL 1 3 4 +breadth_first 3 NULL 1 2 1 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 4 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +breadth_first 4 NULL 2 3 1 +breadth_first 4 NULL 1 2 3 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 5 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +breadth_first 5 NULL 1 3 7 +breadth_first 5 NULL 1 2 6 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 6 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +breadth_first 6 NULL 2 3 7 +breadth_first 6 NULL 1 2 5 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 7 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 8 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 9 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 10 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +breadth_first 10 NULL 2 3 12 +breadth_first 10 NULL 1 2 11 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 11 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +breadth_first 11 NULL 2 3 10 +breadth_first 11 NULL 1 2 12 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 12 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +breadth_first 12 NULL 2 3 11 +breadth_first 12 NULL 1 2 10 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 1; +latch origid destid weight seq linkid +breadth_first NULL 1 2 4 4 +breadth_first NULL 1 1 3 3 +breadth_first NULL 1 1 2 2 +breadth_first NULL 1 0 1 1 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 2; +latch origid destid weight seq linkid +breadth_first NULL 2 3 4 4 +breadth_first NULL 2 2 3 3 +breadth_first NULL 2 1 2 1 +breadth_first NULL 2 0 1 2 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 3; +latch origid destid weight seq linkid +breadth_first NULL 3 2 4 2 +breadth_first NULL 3 1 3 4 +breadth_first NULL 3 1 2 1 +breadth_first NULL 3 0 1 3 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 4; +latch origid destid weight seq linkid +breadth_first NULL 4 3 4 2 +breadth_first NULL 4 2 3 1 +breadth_first NULL 4 1 2 3 +breadth_first NULL 4 0 1 4 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 5; +latch origid destid weight seq linkid +breadth_first NULL 5 1 2 6 +breadth_first NULL 5 0 1 5 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 6; +latch origid destid weight seq linkid +breadth_first NULL 6 1 2 5 +breadth_first NULL 6 0 1 6 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 7; +latch origid destid weight seq linkid +breadth_first NULL 7 2 3 6 +breadth_first NULL 7 1 2 5 +breadth_first NULL 7 0 1 7 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 8; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 9; +latch origid destid weight seq linkid +breadth_first NULL 9 0 1 9 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 10; +latch origid destid weight seq linkid +breadth_first NULL 10 2 3 11 +breadth_first NULL 10 1 2 12 +breadth_first NULL 10 0 1 10 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 11; +latch origid destid weight seq linkid +breadth_first NULL 11 2 3 12 +breadth_first NULL 11 1 2 10 +breadth_first NULL 11 0 1 11 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 12; +latch origid destid weight seq linkid +breadth_first NULL 12 2 3 10 +breadth_first NULL 12 1 2 11 +breadth_first NULL 12 0 1 12 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 1 and weight = 1; +latch origid destid weight seq linkid +breadth_first NULL 1 1 3 3 +breadth_first NULL 1 1 2 2 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 2 and weight = 1; +latch origid destid weight seq linkid +breadth_first NULL 2 1 2 1 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 3 and weight = 1; +latch origid destid weight seq linkid +breadth_first NULL 3 1 3 4 +breadth_first NULL 3 1 2 1 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 4 and weight = 1; +latch origid destid weight seq linkid +breadth_first NULL 4 1 2 3 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 5 and weight = 1; +latch origid destid weight seq linkid +breadth_first NULL 5 1 2 6 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 6 and weight = 1; +latch origid destid weight seq linkid +breadth_first NULL 6 1 2 5 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 7 and weight = 1; +latch origid destid weight seq linkid +breadth_first NULL 7 1 2 5 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 8 and weight = 1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 9 and weight = 1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 10 and weight = 1; +latch origid destid weight seq linkid +breadth_first NULL 10 1 2 12 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 11 and weight = 1; +latch origid destid weight seq linkid +breadth_first NULL 11 1 2 10 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 12 and weight = 1; +latch origid destid weight seq linkid +breadth_first NULL 12 1 2 11 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 1 and weight = 2; +latch origid destid weight seq linkid +breadth_first NULL 1 2 4 4 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 2 and weight = 2; +latch origid destid weight seq linkid +breadth_first NULL 2 2 3 3 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 3 and weight = 2; +latch origid destid weight seq linkid +breadth_first NULL 3 2 4 2 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 4 and weight = 2; +latch origid destid weight seq linkid +breadth_first NULL 4 2 3 1 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 5 and weight = 2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 6 and weight = 2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 7 and weight = 2; +latch origid destid weight seq linkid +breadth_first NULL 7 2 3 6 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 8 and weight = 2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 9 and weight = 2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 10 and weight = 2; +latch origid destid weight seq linkid +breadth_first NULL 10 2 3 11 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 11 and weight = 2; +latch origid destid weight seq linkid +breadth_first NULL 11 2 3 12 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 12 and weight = 2; +latch origid destid weight seq linkid +breadth_first NULL 12 2 3 10 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 1 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 2 and weight = 3; +latch origid destid weight seq linkid +breadth_first NULL 2 3 4 4 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 3 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 4 and weight = 3; +latch origid destid weight seq linkid +breadth_first NULL 4 3 4 2 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 5 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 6 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 7 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 8 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 9 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 10 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 11 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 12 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = NULL; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = NULL; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND weight = 1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first'; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 1; +latch origid destid weight seq linkid +2 1 NULL 2 4 4 +2 1 NULL 1 3 3 +2 1 NULL 1 2 2 +2 1 NULL 0 1 1 +SELECT * FROM graph WHERE latch = '2' AND origid = 2; +latch origid destid weight seq linkid +2 2 NULL 3 4 4 +2 2 NULL 2 3 3 +2 2 NULL 1 2 1 +2 2 NULL 0 1 2 +SELECT * FROM graph WHERE latch = '2' AND origid = 3; +latch origid destid weight seq linkid +2 3 NULL 2 4 2 +2 3 NULL 1 3 4 +2 3 NULL 1 2 1 +2 3 NULL 0 1 3 +SELECT * FROM graph WHERE latch = '2' AND origid = 4; +latch origid destid weight seq linkid +2 4 NULL 3 4 2 +2 4 NULL 2 3 1 +2 4 NULL 1 2 3 +2 4 NULL 0 1 4 +SELECT * FROM graph WHERE latch = '2' AND origid = 5; +latch origid destid weight seq linkid +2 5 NULL 1 3 7 +2 5 NULL 1 2 6 +2 5 NULL 0 1 5 +SELECT * FROM graph WHERE latch = '2' AND origid = 6; +latch origid destid weight seq linkid +2 6 NULL 2 3 7 +2 6 NULL 1 2 5 +2 6 NULL 0 1 6 +SELECT * FROM graph WHERE latch = '2' AND origid = 7; +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 +SELECT * FROM graph WHERE latch = '2' AND origid = 9; +latch origid destid weight seq linkid +2 9 NULL 0 1 9 +SELECT * FROM graph WHERE latch = '2' AND origid = 10; +latch origid destid weight seq linkid +2 10 NULL 2 3 12 +2 10 NULL 1 2 11 +2 10 NULL 0 1 10 +SELECT * FROM graph WHERE latch = '2' AND origid = 11; +latch origid destid weight seq linkid +2 11 NULL 2 3 10 +2 11 NULL 1 2 12 +2 11 NULL 0 1 11 +SELECT * FROM graph WHERE latch = '2' AND origid = 12; +latch origid destid weight seq linkid +2 12 NULL 2 3 11 +2 12 NULL 1 2 10 +2 12 NULL 0 1 12 +SELECT * FROM graph WHERE latch = '2' AND origid = 666; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 1 AND weight = 1; +latch origid destid weight seq linkid +2 1 NULL 1 3 3 +2 1 NULL 1 2 2 +SELECT * FROM graph WHERE latch = '2' AND origid = 2 AND weight = 1; +latch origid destid weight seq linkid +2 2 NULL 1 2 1 +SELECT * FROM graph WHERE latch = '2' AND origid = 3 AND weight = 1; +latch origid destid weight seq linkid +2 3 NULL 1 3 4 +2 3 NULL 1 2 1 +SELECT * FROM graph WHERE latch = '2' AND origid = 4 AND weight = 1; +latch origid destid weight seq linkid +2 4 NULL 1 2 3 +SELECT * FROM graph WHERE latch = '2' AND origid = 5 AND weight = 1; +latch origid destid weight seq linkid +2 5 NULL 1 3 7 +2 5 NULL 1 2 6 +SELECT * FROM graph WHERE latch = '2' AND origid = 6 AND weight = 1; +latch origid destid weight seq linkid +2 6 NULL 1 2 5 +SELECT * FROM graph WHERE latch = '2' AND origid = 7 AND weight = 1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 8 AND weight = 1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 9 AND weight = 1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 10 AND weight = 1; +latch origid destid weight seq linkid +2 10 NULL 1 2 11 +SELECT * FROM graph WHERE latch = '2' AND origid = 11 AND weight = 1; +latch origid destid weight seq linkid +2 11 NULL 1 2 12 +SELECT * FROM graph WHERE latch = '2' AND origid = 12 AND weight = 1; +latch origid destid weight seq linkid +2 12 NULL 1 2 10 +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 1 AND weight = 1; +count(*) +2 +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 2 AND weight = 1; +count(*) +1 +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 3 AND weight = 1; +count(*) +2 +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 4 AND weight = 1; +count(*) +1 +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 5 AND weight = 1; +count(*) +2 +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 6 AND weight = 1; +count(*) +1 +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 7 AND weight = 1; +count(*) +0 +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 8 AND weight = 1; +count(*) +0 +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 9 AND weight = 1; +count(*) +0 +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 10 AND weight = 1; +count(*) +1 +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 11 AND weight = 1; +count(*) +1 +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 12 AND weight = 1; +count(*) +1 +SELECT * FROM graph WHERE latch = '2' AND origid = 1 AND weight = 2; +latch origid destid weight seq linkid +2 1 NULL 2 4 4 +SELECT * FROM graph WHERE latch = '2' AND origid = 2 AND weight = 2; +latch origid destid weight seq linkid +2 2 NULL 2 3 3 +SELECT * FROM graph WHERE latch = '2' AND origid = 3 AND weight = 2; +latch origid destid weight seq linkid +2 3 NULL 2 4 2 +SELECT * FROM graph WHERE latch = '2' AND origid = 4 AND weight = 2; +latch origid destid weight seq linkid +2 4 NULL 2 3 1 +SELECT * FROM graph WHERE latch = '2' AND origid = 5 AND weight = 2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 6 AND weight = 2; +latch origid destid weight seq linkid +2 6 NULL 2 3 7 +SELECT * FROM graph WHERE latch = '2' AND origid = 7 AND weight = 2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 8 AND weight = 2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 9 AND weight = 2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 10 AND weight = 2; +latch origid destid weight seq linkid +2 10 NULL 2 3 12 +SELECT * FROM graph WHERE latch = '2' AND origid = 11 AND weight = 2; +latch origid destid weight seq linkid +2 11 NULL 2 3 10 +SELECT * FROM graph WHERE latch = '2' AND origid = 12 AND weight = 2; +latch origid destid weight seq linkid +2 12 NULL 2 3 11 +SELECT * FROM graph WHERE latch = '2' AND origid = 1 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 2 AND weight = 3; +latch origid destid weight seq linkid +2 2 NULL 3 4 4 +SELECT * FROM graph WHERE latch = '2' AND origid = 3 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 4 AND weight = 3; +latch origid destid weight seq linkid +2 4 NULL 3 4 2 +SELECT * FROM graph WHERE latch = '2' AND origid = 5 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 6 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 7 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 8 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 9 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 10 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 11 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 12 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 1 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +2 1 NULL 2 4 4 +2 1 NULL 1 3 3 +2 1 NULL 1 2 2 +SELECT * FROM graph WHERE latch = '2' AND origid = 2 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +2 2 NULL 2 3 3 +2 2 NULL 1 2 1 +SELECT * FROM graph WHERE latch = '2' AND origid = 3 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +2 3 NULL 2 4 2 +2 3 NULL 1 3 4 +2 3 NULL 1 2 1 +SELECT * FROM graph WHERE latch = '2' AND origid = 4 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +2 4 NULL 2 3 1 +2 4 NULL 1 2 3 +SELECT * FROM graph WHERE latch = '2' AND origid = 5 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +2 5 NULL 1 3 7 +2 5 NULL 1 2 6 +SELECT * FROM graph WHERE latch = '2' AND origid = 6 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +2 6 NULL 2 3 7 +2 6 NULL 1 2 5 +SELECT * FROM graph WHERE latch = '2' AND origid = 7 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 8 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 9 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 10 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +2 10 NULL 2 3 12 +2 10 NULL 1 2 11 +SELECT * FROM graph WHERE latch = '2' AND origid = 11 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +2 11 NULL 2 3 10 +2 11 NULL 1 2 12 +SELECT * FROM graph WHERE latch = '2' AND origid = 12 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +2 12 NULL 2 3 11 +2 12 NULL 1 2 10 +SELECT * FROM graph WHERE latch = '2' AND destid = 1; +latch origid destid weight seq linkid +2 NULL 1 2 4 4 +2 NULL 1 1 3 3 +2 NULL 1 1 2 2 +2 NULL 1 0 1 1 +SELECT * FROM graph WHERE latch = '2' AND destid = 2; +latch origid destid weight seq linkid +2 NULL 2 3 4 4 +2 NULL 2 2 3 3 +2 NULL 2 1 2 1 +2 NULL 2 0 1 2 +SELECT * FROM graph WHERE latch = '2' AND destid = 3; +latch origid destid weight seq linkid +2 NULL 3 2 4 2 +2 NULL 3 1 3 4 +2 NULL 3 1 2 1 +2 NULL 3 0 1 3 +SELECT * FROM graph WHERE latch = '2' AND destid = 4; +latch origid destid weight seq linkid +2 NULL 4 3 4 2 +2 NULL 4 2 3 1 +2 NULL 4 1 2 3 +2 NULL 4 0 1 4 +SELECT * FROM graph WHERE latch = '2' AND destid = 5; +latch origid destid weight seq linkid +2 NULL 5 1 2 6 +2 NULL 5 0 1 5 +SELECT * FROM graph WHERE latch = '2' AND destid = 6; +latch origid destid weight seq linkid +2 NULL 6 1 2 5 +2 NULL 6 0 1 6 +SELECT * FROM graph WHERE latch = '2' AND destid = 7; +latch origid destid weight seq linkid +2 NULL 7 2 3 6 +2 NULL 7 1 2 5 +2 NULL 7 0 1 7 +SELECT * FROM graph WHERE latch = '2' AND destid = 8; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND destid = 9; +latch origid destid weight seq linkid +2 NULL 9 0 1 9 +SELECT * FROM graph WHERE latch = '2' AND destid = 10; +latch origid destid weight seq linkid +2 NULL 10 2 3 11 +2 NULL 10 1 2 12 +2 NULL 10 0 1 10 +SELECT * FROM graph WHERE latch = '2' AND destid = 11; +latch origid destid weight seq linkid +2 NULL 11 2 3 12 +2 NULL 11 1 2 10 +2 NULL 11 0 1 11 +SELECT * FROM graph WHERE latch = '2' AND destid = 12; +latch origid destid weight seq linkid +2 NULL 12 2 3 10 +2 NULL 12 1 2 11 +2 NULL 12 0 1 12 +SELECT * FROM graph WHERE latch = '2' AND destid = 1 and weight = 1; +latch origid destid weight seq linkid +2 NULL 1 1 3 3 +2 NULL 1 1 2 2 +SELECT * FROM graph WHERE latch = '2' AND destid = 2 and weight = 1; +latch origid destid weight seq linkid +2 NULL 2 1 2 1 +SELECT * FROM graph WHERE latch = '2' AND destid = 3 and weight = 1; +latch origid destid weight seq linkid +2 NULL 3 1 3 4 +2 NULL 3 1 2 1 +SELECT * FROM graph WHERE latch = '2' AND destid = 4 and weight = 1; +latch origid destid weight seq linkid +2 NULL 4 1 2 3 +SELECT * FROM graph WHERE latch = '2' AND destid = 5 and weight = 1; +latch origid destid weight seq linkid +2 NULL 5 1 2 6 +SELECT * FROM graph WHERE latch = '2' AND destid = 6 and weight = 1; +latch origid destid weight seq linkid +2 NULL 6 1 2 5 +SELECT * FROM graph WHERE latch = '2' AND destid = 7 and weight = 1; +latch origid destid weight seq linkid +2 NULL 7 1 2 5 +SELECT * FROM graph WHERE latch = '2' AND destid = 8 and weight = 1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND destid = 9 and weight = 1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND destid = 10 and weight = 1; +latch origid destid weight seq linkid +2 NULL 10 1 2 12 +SELECT * FROM graph WHERE latch = '2' AND destid = 11 and weight = 1; +latch origid destid weight seq linkid +2 NULL 11 1 2 10 +SELECT * FROM graph WHERE latch = '2' AND destid = 12 and weight = 1; +latch origid destid weight seq linkid +2 NULL 12 1 2 11 +SELECT * FROM graph WHERE latch = '2' AND destid = 1 and weight = 2; +latch origid destid weight seq linkid +2 NULL 1 2 4 4 +SELECT * FROM graph WHERE latch = '2' AND destid = 2 and weight = 2; +latch origid destid weight seq linkid +2 NULL 2 2 3 3 +SELECT * FROM graph WHERE latch = '2' AND destid = 3 and weight = 2; +latch origid destid weight seq linkid +2 NULL 3 2 4 2 +SELECT * FROM graph WHERE latch = '2' AND destid = 4 and weight = 2; +latch origid destid weight seq linkid +2 NULL 4 2 3 1 +SELECT * FROM graph WHERE latch = '2' AND destid = 5 and weight = 2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND destid = 6 and weight = 2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND destid = 7 and weight = 2; +latch origid destid weight seq linkid +2 NULL 7 2 3 6 +SELECT * FROM graph WHERE latch = '2' AND destid = 8 and weight = 2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND destid = 9 and weight = 2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND destid = 10 and weight = 2; +latch origid destid weight seq linkid +2 NULL 10 2 3 11 +SELECT * FROM graph WHERE latch = '2' AND destid = 11 and weight = 2; +latch origid destid weight seq linkid +2 NULL 11 2 3 12 +SELECT * FROM graph WHERE latch = '2' AND destid = 12 and weight = 2; +latch origid destid weight seq linkid +2 NULL 12 2 3 10 +SELECT * FROM graph WHERE latch = '2' AND destid = 1 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND destid = 2 and weight = 3; +latch origid destid weight seq linkid +2 NULL 2 3 4 4 +SELECT * FROM graph WHERE latch = '2' AND destid = 3 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND destid = 4 and weight = 3; +latch origid destid weight seq linkid +2 NULL 4 3 4 2 +SELECT * FROM graph WHERE latch = '2' AND destid = 5 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND destid = 6 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND destid = 7 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND destid = 8 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND destid = 9 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND destid = 10 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND destid = 11 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND destid = 12 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = NULL; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND destid = NULL; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND weight = 1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2'; +latch origid destid weight seq linkid +# Dijkstras algorithm tests +SELECT * FROM graph WHERE latch='dijkstras' AND origid=1 AND destid=1; +latch origid destid weight seq linkid +dijkstras 1 1 NULL 0 1 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=1 AND destid=2; +latch origid destid weight seq linkid +dijkstras 1 2 NULL 0 1 +dijkstras 1 2 1 1 2 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=2 AND destid=1; +latch origid destid weight seq linkid +dijkstras 2 1 NULL 0 2 +dijkstras 2 1 1 1 1 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=1 AND destid=4; +latch origid destid weight seq linkid +dijkstras 1 4 NULL 0 1 +dijkstras 1 4 1 1 3 +dijkstras 1 4 1 2 4 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=4 AND destid=1; +latch origid destid weight seq linkid +dijkstras 4 1 NULL 0 4 +dijkstras 4 1 1 1 3 +dijkstras 4 1 1 2 1 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=1 AND destid=5; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch='dijkstras' AND origid=1 AND destid=666; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch='dijkstras' AND origid=5 AND destid=7; +latch origid destid weight seq linkid +dijkstras 5 7 NULL 0 5 +dijkstras 5 7 1 1 7 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=7 AND destid=5; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch='dijkstras' AND origid=10 AND destid=11; +latch origid destid weight seq linkid +dijkstras 10 11 NULL 0 10 +dijkstras 10 11 1 1 11 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=10 AND destid=12; +latch origid destid weight seq linkid +dijkstras 10 12 NULL 0 10 +dijkstras 10 12 1 1 11 +dijkstras 10 12 1 2 12 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=11 AND destid=10; +latch origid destid weight seq linkid +dijkstras 11 10 NULL 0 11 +dijkstras 11 10 1 1 12 +dijkstras 11 10 1 2 10 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=11 AND destid=12; +latch origid destid weight seq linkid +dijkstras 11 12 NULL 0 11 +dijkstras 11 12 1 1 12 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=12 AND destid=10; +latch origid destid weight seq linkid +dijkstras 12 10 NULL 0 12 +dijkstras 12 10 1 1 10 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=12 AND destid=11; +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 2 4 4 +dijkstras 1 NULL 1 3 3 +dijkstras 1 NULL 1 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 3 4 4 +dijkstras 2 NULL 2 3 3 +dijkstras 2 NULL 1 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 2 4 2 +dijkstras 3 NULL 1 3 4 +dijkstras 3 NULL 1 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 3 4 2 +dijkstras 4 NULL 2 3 1 +dijkstras 4 NULL 1 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 1 3 7 +dijkstras 5 NULL 1 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 2 3 7 +dijkstras 6 NULL 1 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 +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 2 3 12 +dijkstras 10 NULL 1 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 2 3 10 +dijkstras 11 NULL 1 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 2 3 11 +dijkstras 12 NULL 1 2 10 +dijkstras 12 NULL 0 1 12 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=666; +latch origid destid weight seq linkid +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 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 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 2 3 6 +dijkstras NULL 7 1 2 5 +dijkstras NULL 7 0 1 7 +SELECT * FROM graph WHERE latch='dijkstras' AND destid=8; +latch origid destid weight seq linkid +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 11 +dijkstras NULL 10 1 2 12 +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 12 +dijkstras NULL 11 1 2 10 +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 10 +dijkstras NULL 12 1 2 11 +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 +1 1 1 NULL 0 1 +SELECT * FROM graph WHERE latch='1' AND origid=1 AND destid=2; +latch origid destid weight seq linkid +1 1 2 NULL 0 1 +1 1 2 1 1 2 +SELECT * FROM graph WHERE latch='1' AND origid=2 AND destid=1; +latch origid destid weight seq linkid +1 2 1 NULL 0 2 +1 2 1 1 1 1 +SELECT * FROM graph WHERE latch='1' AND origid=1 AND destid=4; +latch origid destid weight seq linkid +1 1 4 NULL 0 1 +1 1 4 1 1 3 +1 1 4 1 2 4 +SELECT * FROM graph WHERE latch='1' AND origid=4 AND destid=1; +latch origid destid weight seq linkid +1 4 1 NULL 0 4 +1 4 1 1 1 3 +1 4 1 1 2 1 +SELECT * FROM graph WHERE latch='1' AND origid=1 AND destid=5; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch='1' AND origid=1 AND destid=666; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch='1' AND origid=5 AND destid=7; +latch origid destid weight seq linkid +1 5 7 NULL 0 5 +1 5 7 1 1 7 +SELECT * FROM graph WHERE latch='1' AND origid=7 AND destid=5; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch='1' AND origid=10 AND destid=11; +latch origid destid weight seq linkid +1 10 11 NULL 0 10 +1 10 11 1 1 11 +SELECT * FROM graph WHERE latch='1' AND origid=10 AND destid=12; +latch origid destid weight seq linkid +1 10 12 NULL 0 10 +1 10 12 1 1 11 +1 10 12 1 2 12 +SELECT * FROM graph WHERE latch='1' AND origid=11 AND destid=10; +latch origid destid weight seq linkid +1 11 10 NULL 0 11 +1 11 10 1 1 12 +1 11 10 1 2 10 +SELECT * FROM graph WHERE latch='1' AND origid=11 AND destid=12; +latch origid destid weight seq linkid +1 11 12 NULL 0 11 +1 11 12 1 1 12 +SELECT * FROM graph WHERE latch='1' AND origid=12 AND destid=10; +latch origid destid weight seq linkid +1 12 10 NULL 0 12 +1 12 10 1 1 10 +SELECT * FROM graph WHERE latch='1' AND origid=12 AND destid=11; +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 2 4 4 +1 1 NULL 1 3 3 +1 1 NULL 1 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 3 4 4 +1 2 NULL 2 3 3 +1 2 NULL 1 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 2 4 2 +1 3 NULL 1 3 4 +1 3 NULL 1 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 3 4 2 +1 4 NULL 2 3 1 +1 4 NULL 1 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 1 3 7 +1 5 NULL 1 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 2 3 7 +1 6 NULL 1 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 +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 2 3 12 +1 10 NULL 1 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 2 3 10 +1 11 NULL 1 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 2 3 11 +1 12 NULL 1 2 10 +1 12 NULL 0 1 12 +SELECT * FROM graph WHERE latch='1' AND origid=666; +latch origid destid weight seq linkid +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 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 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 2 3 6 +1 NULL 7 1 2 5 +1 NULL 7 0 1 7 +SELECT * FROM graph WHERE latch='1' AND destid=8; +latch origid destid weight seq linkid +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 11 +1 NULL 10 1 2 12 +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 12 +1 NULL 11 1 2 10 +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 10 +1 NULL 12 1 2 11 +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); +SELECT * FROM graph WHERE latch='dijkstras' AND origid=10 AND destid=13; +latch origid destid weight seq linkid +dijkstras 10 13 NULL 0 10 +dijkstras 10 13 1 1 11 +dijkstras 10 13 1 2 13 +DELETE FROM graph_base where from_id=10 and to_id=11; +INSERT INTO graph_base(from_id, to_id) VALUES (10,15); +INSERT INTO graph_base(from_id, to_id) VALUES (15,13); +SELECT * FROM graph WHERE latch='dijkstras' AND origid=10 AND destid=13; +latch origid destid weight seq linkid +dijkstras 10 13 NULL 0 10 +dijkstras 10 13 1 1 14 +dijkstras 10 13 1 2 13 +INSERT INTO graph_base(from_id, to_id) VALUES (10,11); +SELECT * FROM graph WHERE latch='dijkstras' AND origid=10 AND destid=13; +latch origid destid weight seq linkid +dijkstras 10 13 NULL 0 10 +dijkstras 10 13 1 1 11 +dijkstras 10 13 1 2 13 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=1; +latch origid destid weight seq linkid +dijkstras 1 NULL 2 4 4 +dijkstras 1 NULL 1 3 3 +dijkstras 1 NULL 1 2 2 +dijkstras 1 NULL 0 1 1 +INSERT INTO graph_base(from_id, to_id) VALUES (21,22); +SELECT * FROM graph WHERE latch='dijkstras' AND origid=21; +latch origid destid weight seq linkid +dijkstras 21 NULL 1 2 22 +dijkstras 21 NULL 0 1 21 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=22; +latch origid destid weight seq linkid +dijkstras 22 NULL 0 1 22 +INSERT INTO graph_base(from_id, to_id) VALUES (4,17); +SELECT * FROM graph WHERE latch='dijkstras' AND origid=1; +latch origid destid weight seq linkid +dijkstras 1 NULL 3 5 17 +dijkstras 1 NULL 2 4 4 +dijkstras 1 NULL 1 3 3 +dijkstras 1 NULL 1 2 2 +dijkstras 1 NULL 0 1 1 +INSERT INTO graph_base(from_id, to_id) VALUES (4,16); +SELECT * FROM graph WHERE latch='dijkstras' AND origid=1; +latch origid destid weight seq linkid +dijkstras 1 NULL 3 6 17 +dijkstras 1 NULL 3 5 16 +dijkstras 1 NULL 2 4 4 +dijkstras 1 NULL 1 3 3 +dijkstras 1 NULL 1 2 2 +dijkstras 1 NULL 0 1 1 +INSERT INTO graph_base(from_id, to_id) VALUES (17,18); +SELECT * FROM graph WHERE latch='dijkstras' AND origid=1; +latch origid destid weight seq linkid +dijkstras 1 NULL 4 7 18 +dijkstras 1 NULL 3 6 17 +dijkstras 1 NULL 3 5 16 +dijkstras 1 NULL 2 4 4 +dijkstras 1 NULL 1 3 3 +dijkstras 1 NULL 1 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 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 +DELETE FROM graph_base WHERE from_id=5; +DELETE FROM graph_base WHERE from_id=3 AND to_id=5; +# which means there is a path in one direction only 1>3>4>6 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=1 AND destid=6; +latch origid destid weight seq linkid +dijkstras 1 6 NULL 0 1 +dijkstras 1 6 1 1 3 +dijkstras 1 6 1 2 4 +dijkstras 1 6 1 3 6 +# but not 6>4>3>1 (so no result) +SELECT * FROM graph WHERE latch='dijkstras' AND origid=6 AND destid=1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch='1' AND origid=1 AND destid=6; +latch origid destid weight seq linkid +1 1 6 NULL 0 1 +1 1 6 1 1 3 +1 1 6 1 2 4 +1 1 6 1 3 6 +SELECT * FROM graph WHERE latch='1' AND origid=6 AND destid=1; +latch origid destid weight seq linkid +DELETE FROM graph_base; +FLUSH TABLES; +TRUNCATE TABLE graph_base; +DROP TABLE graph_base; +DROP TABLE graph; diff --git a/storage/oqgraph/mysql-test/oqgraph/general-Aria.test b/storage/oqgraph/mysql-test/oqgraph/general-Aria.test new file mode 100644 index 00000000..f2a0146f --- /dev/null +++ b/storage/oqgraph/mysql-test/oqgraph/general-Aria.test @@ -0,0 +1,3 @@ +# This is a maintainer generated file. Generated at Wednesday 5 February 22:26:12 CST 2014. +--let $oqgraph_use_table_type= Aria +--source general.inc diff --git a/storage/oqgraph/mysql-test/oqgraph/general-MyISAM.result b/storage/oqgraph/mysql-test/oqgraph/general-MyISAM.result new file mode 100644 index 00000000..e5b5e958 --- /dev/null +++ b/storage/oqgraph/mysql-test/oqgraph/general-MyISAM.result @@ -0,0 +1,1593 @@ +DROP TABLE IF EXISTS graph_base; +DROP TABLE IF EXISTS graph; +DROP TABLE IF EXISTS graph2; +Performing OQGraph General test suite for ENGINE=MyISAM +CREATE TABLE graph_base ( +from_id INT UNSIGNED NOT NULL, +to_id INT UNSIGNED NOT NULL, +PRIMARY KEY (from_id,to_id), +INDEX (to_id) +) ENGINE= MyISAM ; +CREATE TABLE graph ENGINE=OQGRAPH DATA_TABLE='graph_base' ORIGID='from_id', DESTID='to_id'; +select * from graph; +latch origid destid weight seq linkid +INSERT INTO graph_base(from_id, to_id) VALUES (1,2), (2,1); +INSERT INTO graph_base(from_id, to_id) VALUES (1,3), (3,1); +INSERT INTO graph_base(from_id, to_id) VALUES (3,4), (4,3); +INSERT INTO graph_base(from_id, to_id) VALUES (5,6), (6,5); +INSERT INTO graph_base(from_id, to_id) VALUES (5,7); +INSERT INTO graph_base(from_id, to_id) VALUES (9,9); +INSERT INTO graph_base(from_id, to_id) VALUES (10,11); +INSERT INTO graph_base(from_id, to_id) VALUES (11,12); +INSERT INTO graph_base(from_id, to_id) VALUES (12,10); +# Return all edges +SELECT * FROM graph; +latch origid destid weight seq linkid +NULL 1 2 1 NULL NULL +NULL 2 1 1 NULL NULL +NULL 1 3 1 NULL NULL +NULL 3 1 1 NULL NULL +NULL 3 4 1 NULL NULL +NULL 4 3 1 NULL NULL +NULL 5 6 1 NULL NULL +NULL 6 5 1 NULL NULL +NULL 5 7 1 NULL NULL +NULL 9 9 1 NULL NULL +NULL 10 11 1 NULL NULL +NULL 11 12 1 NULL NULL +NULL 12 10 1 NULL NULL +# Currently count should be 13 +SELECT count(*) FROM graph; +count(*) +13 +# Return all edges when latch is NULL - this is different to latch='' and same as no where clause +SELECT * FROM graph where latch is NULL; +latch origid destid weight seq linkid +NULL 1 2 1 NULL NULL +NULL 2 1 1 NULL NULL +NULL 1 3 1 NULL NULL +NULL 3 1 1 NULL NULL +NULL 3 4 1 NULL NULL +NULL 4 3 1 NULL NULL +NULL 5 6 1 NULL NULL +NULL 6 5 1 NULL NULL +NULL 5 7 1 NULL NULL +NULL 9 9 1 NULL NULL +NULL 10 11 1 NULL NULL +NULL 11 12 1 NULL NULL +NULL 12 10 1 NULL NULL +# Return all vertices, and subsets of vertices +SELECT * FROM graph where latch=''; +latch origid destid weight seq linkid + NULL NULL NULL NULL 1 + NULL NULL NULL NULL 2 + NULL NULL NULL NULL 3 + NULL NULL NULL NULL 4 + NULL NULL NULL NULL 5 + NULL NULL NULL NULL 6 + NULL NULL NULL NULL 7 + NULL NULL NULL NULL 9 + NULL NULL NULL NULL 10 + NULL NULL NULL NULL 11 + NULL NULL NULL NULL 12 +SELECT * FROM graph where latch='0'; +latch origid destid weight seq linkid +0 NULL NULL NULL NULL 1 +0 NULL NULL NULL NULL 2 +0 NULL NULL NULL NULL 3 +0 NULL NULL NULL NULL 4 +0 NULL NULL NULL NULL 5 +0 NULL NULL NULL NULL 6 +0 NULL NULL NULL NULL 7 +0 NULL NULL NULL NULL 9 +0 NULL NULL NULL NULL 10 +0 NULL NULL NULL NULL 11 +0 NULL NULL NULL NULL 12 +# Currently count should be 11 +SELECT count(*) FROM graph where latch=''; +count(*) +11 +SELECT * FROM graph where latch='' and linkid = 2; +latch origid destid weight seq linkid + NULL NULL NULL NULL 2 +SELECT * FROM graph where latch='' and (linkid > 2 and linkid < 6); +latch origid destid weight seq linkid + NULL NULL NULL NULL 3 + NULL NULL NULL NULL 4 + NULL NULL NULL NULL 5 +SELECT * FROM graph where latch='' and linkid = NULL; +latch origid destid weight seq linkid +SELECT * FROM graph where latch='' and linkid = 666; +latch origid destid weight seq linkid +SELECT origid as `from`, linkid as `to` FROM graph where latch='' and origid = 1; +from to +1 3 +1 2 +SELECT origid as `from`, linkid as `to` FROM graph where latch='' and origid = 2; +from to +2 1 +SELECT origid as `from`, linkid as `to` FROM graph where latch='' and origid = 4; +from to +4 3 +SELECT origid as `from`, linkid as `to` FROM graph where latch='' and origid = 9; +from to +9 9 +SELECT origid as `from`, linkid as `to` FROM graph where latch='' and origid = 10; +from to +10 11 +SELECT origid as `from`, linkid as `to` FROM graph where latch='' and origid = NULL; +from to +SELECT origid as `from`, linkid as `to` FROM graph where latch='' and origid = 666; +from to +SELECT linkid as `from`, destid as `to` FROM graph where latch='' and destid = 1; +from to +3 1 +2 1 +SELECT linkid as `from`, destid as `to` FROM graph where latch='' and destid = 2; +from to +1 2 +SELECT linkid as `from`, destid as `to` FROM graph where latch='' and destid = 4; +from to +3 4 +SELECT linkid as `from`, destid as `to` FROM graph where latch='' and destid = 9; +from to +9 9 +SELECT linkid as `from`, destid as `to` FROM graph where latch='' and destid = 10; +from to +12 10 +SELECT linkid as `from`, destid as `to` FROM graph where latch='' and destid = NULL; +from to +SELECT linkid as `from`, destid as `to` FROM graph where latch='' and destid = 666; +from to +SELECT * FROM graph where latch='0'; +latch origid destid weight seq linkid +0 NULL NULL NULL NULL 1 +0 NULL NULL NULL NULL 2 +0 NULL NULL NULL NULL 3 +0 NULL NULL NULL NULL 4 +0 NULL NULL NULL NULL 5 +0 NULL NULL NULL NULL 6 +0 NULL NULL NULL NULL 7 +0 NULL NULL NULL NULL 9 +0 NULL NULL NULL NULL 10 +0 NULL NULL NULL NULL 11 +0 NULL NULL NULL NULL 12 +SELECT count(*) FROM graph where latch='0'; +count(*) +11 +SELECT * FROM graph where latch='0' and linkid = 2; +latch origid destid weight seq linkid +0 NULL NULL NULL NULL 2 +SELECT * FROM graph where latch='0' and (linkid > 2 and linkid < 6); +latch origid destid weight seq linkid +0 NULL NULL NULL NULL 3 +0 NULL NULL NULL NULL 4 +0 NULL NULL NULL NULL 5 +SELECT origid as `from`, linkid as `to` FROM graph where latch='0' and origid = 1; +from to +1 3 +1 2 +SELECT origid as `from`, linkid as `to` FROM graph where latch='0' and origid = 2; +from to +2 1 +SELECT origid as `from`, linkid as `to` FROM graph where latch='0' and origid = 4; +from to +4 3 +SELECT origid as `from`, linkid as `to` FROM graph where latch='0' and origid = 9; +from to +9 9 +SELECT origid as `from`, linkid as `to` FROM graph where latch='0' and origid = 10; +from to +10 11 +SELECT linkid as `from`, destid as `to` FROM graph where latch='0' and destid = 1; +from to +3 1 +2 1 +SELECT linkid as `from`, destid as `to` FROM graph where latch='0' and destid = 2; +from to +1 2 +SELECT linkid as `from`, destid as `to` FROM graph where latch='0' and destid = 4; +from to +3 4 +SELECT linkid as `from`, destid as `to` FROM graph where latch='0' and destid = 9; +from to +9 9 +SELECT linkid as `from`, destid as `to` FROM graph where latch='0' and destid = 10; +from to +12 10 +# Leaves search tests +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 4; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 5; +latch origid destid weight seq linkid +leaves 5 NULL 1 1 7 +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 6; +latch origid destid weight seq linkid +leaves 6 NULL 2 1 7 +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 7; +latch origid destid weight seq linkid +leaves 7 NULL 0 1 7 +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 8; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 9; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 10; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 11; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 12; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 4; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 5; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 6; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 7; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 8; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 9; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 10; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 11; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 12; +latch origid destid weight seq linkid +INSERT INTO graph_base(from_id, to_id) VALUES (10,13); +INSERT INTO graph_base(from_id, to_id) VALUES (11,14); +INSERT INTO graph_base(from_id, to_id) VALUES (12,15); +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 10; +latch origid destid weight seq linkid +leaves 10 NULL 3 3 15 +leaves 10 NULL 2 2 14 +leaves 10 NULL 1 1 13 +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 11; +latch origid destid weight seq linkid +leaves 11 NULL 3 3 13 +leaves 11 NULL 2 2 15 +leaves 11 NULL 1 1 14 +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 12; +latch origid destid weight seq linkid +leaves 12 NULL 3 3 14 +leaves 12 NULL 2 2 13 +leaves 12 NULL 1 1 15 +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 13; +latch origid destid weight seq linkid +leaves 13 NULL 0 1 13 +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 14; +latch origid destid weight seq linkid +leaves 14 NULL 0 1 14 +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 15; +latch origid destid weight seq linkid +leaves 15 NULL 0 1 15 +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 10; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 11; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 12; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 13; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 14; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 15; +latch origid destid weight seq linkid +DELETE FROM graph_base where from_id=10 and to_id=13; +DELETE FROM graph_base where from_id=11 and to_id=14; +DELETE FROM graph_base where from_id=12 and to_id=15; +INSERT INTO graph_base(from_id, to_id) VALUES (13,10); +INSERT INTO graph_base(from_id, to_id) VALUES (14,11); +INSERT INTO graph_base(from_id, to_id) VALUES (15,12); +INSERT INTO graph_base(from_id, to_id) VALUES (16,1); +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 10; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 11; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 12; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 13; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 14; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 15; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 16; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 10; +latch origid destid weight seq linkid +leaves NULL 10 3 3 14 +leaves NULL 10 2 2 15 +leaves NULL 10 1 1 13 +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 11; +latch origid destid weight seq linkid +leaves NULL 11 3 3 15 +leaves NULL 11 2 2 13 +leaves NULL 11 1 1 14 +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 12; +latch origid destid weight seq linkid +leaves NULL 12 3 3 13 +leaves NULL 12 2 2 14 +leaves NULL 12 1 1 15 +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 13; +latch origid destid weight seq linkid +leaves NULL 13 0 1 13 +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 14; +latch origid destid weight seq linkid +leaves NULL 14 0 1 14 +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 15; +latch origid destid weight seq linkid +leaves NULL 15 0 1 15 +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 1; +latch origid destid weight seq linkid +leaves NULL 1 1 1 16 +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 2; +latch origid destid weight seq linkid +leaves NULL 2 2 1 16 +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 3; +latch origid destid weight seq linkid +leaves NULL 3 2 1 16 +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 4; +latch origid destid weight seq linkid +leaves NULL 4 3 1 16 +DELETE FROM graph_base where from_id=13 and to_id=10; +DELETE FROM graph_base where from_id=14 and to_id=11; +DELETE FROM graph_base where from_id=15 and to_id=12; +DELETE FROM graph_base where from_id=16 and to_id=1; +SELECT * FROM graph WHERE latch='leaves' AND origid=1 AND destid=2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch='leaves' AND origid=1 AND destid=3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch='leaves' AND origid=1 AND destid=4; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch='leaves' AND origid=6 AND destid=7; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch='leaves' AND origid=10 AND destid=11; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch='leaves' AND origid=10 AND destid=12; +latch origid destid weight seq linkid +# Breadth-first search tests +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 1; +latch origid destid weight seq linkid +breadth_first 1 NULL 2 4 4 +breadth_first 1 NULL 1 3 3 +breadth_first 1 NULL 1 2 2 +breadth_first 1 NULL 0 1 1 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 2; +latch origid destid weight seq linkid +breadth_first 2 NULL 3 4 4 +breadth_first 2 NULL 2 3 3 +breadth_first 2 NULL 1 2 1 +breadth_first 2 NULL 0 1 2 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 3; +latch origid destid weight seq linkid +breadth_first 3 NULL 2 4 2 +breadth_first 3 NULL 1 3 4 +breadth_first 3 NULL 1 2 1 +breadth_first 3 NULL 0 1 3 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 4; +latch origid destid weight seq linkid +breadth_first 4 NULL 3 4 2 +breadth_first 4 NULL 2 3 1 +breadth_first 4 NULL 1 2 3 +breadth_first 4 NULL 0 1 4 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 5; +latch origid destid weight seq linkid +breadth_first 5 NULL 1 3 7 +breadth_first 5 NULL 1 2 6 +breadth_first 5 NULL 0 1 5 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 6; +latch origid destid weight seq linkid +breadth_first 6 NULL 2 3 7 +breadth_first 6 NULL 1 2 5 +breadth_first 6 NULL 0 1 6 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 7; +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 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 9; +latch origid destid weight seq linkid +breadth_first 9 NULL 0 1 9 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 10; +latch origid destid weight seq linkid +breadth_first 10 NULL 2 3 12 +breadth_first 10 NULL 1 2 11 +breadth_first 10 NULL 0 1 10 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 11; +latch origid destid weight seq linkid +breadth_first 11 NULL 2 3 10 +breadth_first 11 NULL 1 2 12 +breadth_first 11 NULL 0 1 11 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 12; +latch origid destid weight seq linkid +breadth_first 12 NULL 2 3 11 +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 +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 +breadth_first 1 NULL 1 2 2 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 2 AND weight = 1; +latch origid destid weight seq linkid +breadth_first 2 NULL 1 2 1 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 3 AND weight = 1; +latch origid destid weight seq linkid +breadth_first 3 NULL 1 3 4 +breadth_first 3 NULL 1 2 1 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 4 AND weight = 1; +latch origid destid weight seq linkid +breadth_first 4 NULL 1 2 3 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 5 AND weight = 1; +latch origid destid weight seq linkid +breadth_first 5 NULL 1 3 7 +breadth_first 5 NULL 1 2 6 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 6 AND weight = 1; +latch origid destid weight seq linkid +breadth_first 6 NULL 1 2 5 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 7 AND weight = 1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 8 AND weight = 1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 9 AND weight = 1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 10 AND weight = 1; +latch origid destid weight seq linkid +breadth_first 10 NULL 1 2 11 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 11 AND weight = 1; +latch origid destid weight seq linkid +breadth_first 11 NULL 1 2 12 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 12 AND weight = 1; +latch origid destid weight seq linkid +breadth_first 12 NULL 1 2 10 +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 1 AND weight = 1; +count(*) +2 +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 2 AND weight = 1; +count(*) +1 +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 3 AND weight = 1; +count(*) +2 +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 4 AND weight = 1; +count(*) +1 +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 5 AND weight = 1; +count(*) +2 +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 6 AND weight = 1; +count(*) +1 +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 7 AND weight = 1; +count(*) +0 +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 8 AND weight = 1; +count(*) +0 +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 9 AND weight = 1; +count(*) +0 +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 10 AND weight = 1; +count(*) +1 +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 11 AND weight = 1; +count(*) +1 +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 12 AND weight = 1; +count(*) +1 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 1 AND weight = 2; +latch origid destid weight seq linkid +breadth_first 1 NULL 2 4 4 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 2 AND weight = 2; +latch origid destid weight seq linkid +breadth_first 2 NULL 2 3 3 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 3 AND weight = 2; +latch origid destid weight seq linkid +breadth_first 3 NULL 2 4 2 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 4 AND weight = 2; +latch origid destid weight seq linkid +breadth_first 4 NULL 2 3 1 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 5 AND weight = 2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 6 AND weight = 2; +latch origid destid weight seq linkid +breadth_first 6 NULL 2 3 7 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 7 AND weight = 2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 8 AND weight = 2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 9 AND weight = 2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 10 AND weight = 2; +latch origid destid weight seq linkid +breadth_first 10 NULL 2 3 12 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 11 AND weight = 2; +latch origid destid weight seq linkid +breadth_first 11 NULL 2 3 10 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 12 AND weight = 2; +latch origid destid weight seq linkid +breadth_first 12 NULL 2 3 11 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 1 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 2 AND weight = 3; +latch origid destid weight seq linkid +breadth_first 2 NULL 3 4 4 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 3 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 4 AND weight = 3; +latch origid destid weight seq linkid +breadth_first 4 NULL 3 4 2 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 5 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 6 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 7 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 8 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 9 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 10 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 11 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 12 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 1 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +breadth_first 1 NULL 2 4 4 +breadth_first 1 NULL 1 3 3 +breadth_first 1 NULL 1 2 2 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 2 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +breadth_first 2 NULL 2 3 3 +breadth_first 2 NULL 1 2 1 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 3 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +breadth_first 3 NULL 2 4 2 +breadth_first 3 NULL 1 3 4 +breadth_first 3 NULL 1 2 1 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 4 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +breadth_first 4 NULL 2 3 1 +breadth_first 4 NULL 1 2 3 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 5 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +breadth_first 5 NULL 1 3 7 +breadth_first 5 NULL 1 2 6 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 6 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +breadth_first 6 NULL 2 3 7 +breadth_first 6 NULL 1 2 5 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 7 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 8 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 9 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 10 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +breadth_first 10 NULL 2 3 12 +breadth_first 10 NULL 1 2 11 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 11 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +breadth_first 11 NULL 2 3 10 +breadth_first 11 NULL 1 2 12 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 12 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +breadth_first 12 NULL 2 3 11 +breadth_first 12 NULL 1 2 10 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 1; +latch origid destid weight seq linkid +breadth_first NULL 1 2 4 4 +breadth_first NULL 1 1 3 3 +breadth_first NULL 1 1 2 2 +breadth_first NULL 1 0 1 1 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 2; +latch origid destid weight seq linkid +breadth_first NULL 2 3 4 4 +breadth_first NULL 2 2 3 3 +breadth_first NULL 2 1 2 1 +breadth_first NULL 2 0 1 2 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 3; +latch origid destid weight seq linkid +breadth_first NULL 3 2 4 2 +breadth_first NULL 3 1 3 4 +breadth_first NULL 3 1 2 1 +breadth_first NULL 3 0 1 3 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 4; +latch origid destid weight seq linkid +breadth_first NULL 4 3 4 2 +breadth_first NULL 4 2 3 1 +breadth_first NULL 4 1 2 3 +breadth_first NULL 4 0 1 4 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 5; +latch origid destid weight seq linkid +breadth_first NULL 5 1 2 6 +breadth_first NULL 5 0 1 5 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 6; +latch origid destid weight seq linkid +breadth_first NULL 6 1 2 5 +breadth_first NULL 6 0 1 6 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 7; +latch origid destid weight seq linkid +breadth_first NULL 7 2 3 6 +breadth_first NULL 7 1 2 5 +breadth_first NULL 7 0 1 7 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 8; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 9; +latch origid destid weight seq linkid +breadth_first NULL 9 0 1 9 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 10; +latch origid destid weight seq linkid +breadth_first NULL 10 2 3 11 +breadth_first NULL 10 1 2 12 +breadth_first NULL 10 0 1 10 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 11; +latch origid destid weight seq linkid +breadth_first NULL 11 2 3 12 +breadth_first NULL 11 1 2 10 +breadth_first NULL 11 0 1 11 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 12; +latch origid destid weight seq linkid +breadth_first NULL 12 2 3 10 +breadth_first NULL 12 1 2 11 +breadth_first NULL 12 0 1 12 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 1 and weight = 1; +latch origid destid weight seq linkid +breadth_first NULL 1 1 3 3 +breadth_first NULL 1 1 2 2 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 2 and weight = 1; +latch origid destid weight seq linkid +breadth_first NULL 2 1 2 1 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 3 and weight = 1; +latch origid destid weight seq linkid +breadth_first NULL 3 1 3 4 +breadth_first NULL 3 1 2 1 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 4 and weight = 1; +latch origid destid weight seq linkid +breadth_first NULL 4 1 2 3 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 5 and weight = 1; +latch origid destid weight seq linkid +breadth_first NULL 5 1 2 6 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 6 and weight = 1; +latch origid destid weight seq linkid +breadth_first NULL 6 1 2 5 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 7 and weight = 1; +latch origid destid weight seq linkid +breadth_first NULL 7 1 2 5 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 8 and weight = 1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 9 and weight = 1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 10 and weight = 1; +latch origid destid weight seq linkid +breadth_first NULL 10 1 2 12 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 11 and weight = 1; +latch origid destid weight seq linkid +breadth_first NULL 11 1 2 10 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 12 and weight = 1; +latch origid destid weight seq linkid +breadth_first NULL 12 1 2 11 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 1 and weight = 2; +latch origid destid weight seq linkid +breadth_first NULL 1 2 4 4 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 2 and weight = 2; +latch origid destid weight seq linkid +breadth_first NULL 2 2 3 3 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 3 and weight = 2; +latch origid destid weight seq linkid +breadth_first NULL 3 2 4 2 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 4 and weight = 2; +latch origid destid weight seq linkid +breadth_first NULL 4 2 3 1 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 5 and weight = 2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 6 and weight = 2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 7 and weight = 2; +latch origid destid weight seq linkid +breadth_first NULL 7 2 3 6 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 8 and weight = 2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 9 and weight = 2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 10 and weight = 2; +latch origid destid weight seq linkid +breadth_first NULL 10 2 3 11 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 11 and weight = 2; +latch origid destid weight seq linkid +breadth_first NULL 11 2 3 12 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 12 and weight = 2; +latch origid destid weight seq linkid +breadth_first NULL 12 2 3 10 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 1 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 2 and weight = 3; +latch origid destid weight seq linkid +breadth_first NULL 2 3 4 4 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 3 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 4 and weight = 3; +latch origid destid weight seq linkid +breadth_first NULL 4 3 4 2 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 5 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 6 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 7 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 8 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 9 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 10 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 11 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 12 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = NULL; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = NULL; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND weight = 1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first'; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 1; +latch origid destid weight seq linkid +2 1 NULL 2 4 4 +2 1 NULL 1 3 3 +2 1 NULL 1 2 2 +2 1 NULL 0 1 1 +SELECT * FROM graph WHERE latch = '2' AND origid = 2; +latch origid destid weight seq linkid +2 2 NULL 3 4 4 +2 2 NULL 2 3 3 +2 2 NULL 1 2 1 +2 2 NULL 0 1 2 +SELECT * FROM graph WHERE latch = '2' AND origid = 3; +latch origid destid weight seq linkid +2 3 NULL 2 4 2 +2 3 NULL 1 3 4 +2 3 NULL 1 2 1 +2 3 NULL 0 1 3 +SELECT * FROM graph WHERE latch = '2' AND origid = 4; +latch origid destid weight seq linkid +2 4 NULL 3 4 2 +2 4 NULL 2 3 1 +2 4 NULL 1 2 3 +2 4 NULL 0 1 4 +SELECT * FROM graph WHERE latch = '2' AND origid = 5; +latch origid destid weight seq linkid +2 5 NULL 1 3 7 +2 5 NULL 1 2 6 +2 5 NULL 0 1 5 +SELECT * FROM graph WHERE latch = '2' AND origid = 6; +latch origid destid weight seq linkid +2 6 NULL 2 3 7 +2 6 NULL 1 2 5 +2 6 NULL 0 1 6 +SELECT * FROM graph WHERE latch = '2' AND origid = 7; +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 +SELECT * FROM graph WHERE latch = '2' AND origid = 9; +latch origid destid weight seq linkid +2 9 NULL 0 1 9 +SELECT * FROM graph WHERE latch = '2' AND origid = 10; +latch origid destid weight seq linkid +2 10 NULL 2 3 12 +2 10 NULL 1 2 11 +2 10 NULL 0 1 10 +SELECT * FROM graph WHERE latch = '2' AND origid = 11; +latch origid destid weight seq linkid +2 11 NULL 2 3 10 +2 11 NULL 1 2 12 +2 11 NULL 0 1 11 +SELECT * FROM graph WHERE latch = '2' AND origid = 12; +latch origid destid weight seq linkid +2 12 NULL 2 3 11 +2 12 NULL 1 2 10 +2 12 NULL 0 1 12 +SELECT * FROM graph WHERE latch = '2' AND origid = 666; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 1 AND weight = 1; +latch origid destid weight seq linkid +2 1 NULL 1 3 3 +2 1 NULL 1 2 2 +SELECT * FROM graph WHERE latch = '2' AND origid = 2 AND weight = 1; +latch origid destid weight seq linkid +2 2 NULL 1 2 1 +SELECT * FROM graph WHERE latch = '2' AND origid = 3 AND weight = 1; +latch origid destid weight seq linkid +2 3 NULL 1 3 4 +2 3 NULL 1 2 1 +SELECT * FROM graph WHERE latch = '2' AND origid = 4 AND weight = 1; +latch origid destid weight seq linkid +2 4 NULL 1 2 3 +SELECT * FROM graph WHERE latch = '2' AND origid = 5 AND weight = 1; +latch origid destid weight seq linkid +2 5 NULL 1 3 7 +2 5 NULL 1 2 6 +SELECT * FROM graph WHERE latch = '2' AND origid = 6 AND weight = 1; +latch origid destid weight seq linkid +2 6 NULL 1 2 5 +SELECT * FROM graph WHERE latch = '2' AND origid = 7 AND weight = 1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 8 AND weight = 1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 9 AND weight = 1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 10 AND weight = 1; +latch origid destid weight seq linkid +2 10 NULL 1 2 11 +SELECT * FROM graph WHERE latch = '2' AND origid = 11 AND weight = 1; +latch origid destid weight seq linkid +2 11 NULL 1 2 12 +SELECT * FROM graph WHERE latch = '2' AND origid = 12 AND weight = 1; +latch origid destid weight seq linkid +2 12 NULL 1 2 10 +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 1 AND weight = 1; +count(*) +2 +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 2 AND weight = 1; +count(*) +1 +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 3 AND weight = 1; +count(*) +2 +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 4 AND weight = 1; +count(*) +1 +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 5 AND weight = 1; +count(*) +2 +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 6 AND weight = 1; +count(*) +1 +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 7 AND weight = 1; +count(*) +0 +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 8 AND weight = 1; +count(*) +0 +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 9 AND weight = 1; +count(*) +0 +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 10 AND weight = 1; +count(*) +1 +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 11 AND weight = 1; +count(*) +1 +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 12 AND weight = 1; +count(*) +1 +SELECT * FROM graph WHERE latch = '2' AND origid = 1 AND weight = 2; +latch origid destid weight seq linkid +2 1 NULL 2 4 4 +SELECT * FROM graph WHERE latch = '2' AND origid = 2 AND weight = 2; +latch origid destid weight seq linkid +2 2 NULL 2 3 3 +SELECT * FROM graph WHERE latch = '2' AND origid = 3 AND weight = 2; +latch origid destid weight seq linkid +2 3 NULL 2 4 2 +SELECT * FROM graph WHERE latch = '2' AND origid = 4 AND weight = 2; +latch origid destid weight seq linkid +2 4 NULL 2 3 1 +SELECT * FROM graph WHERE latch = '2' AND origid = 5 AND weight = 2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 6 AND weight = 2; +latch origid destid weight seq linkid +2 6 NULL 2 3 7 +SELECT * FROM graph WHERE latch = '2' AND origid = 7 AND weight = 2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 8 AND weight = 2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 9 AND weight = 2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 10 AND weight = 2; +latch origid destid weight seq linkid +2 10 NULL 2 3 12 +SELECT * FROM graph WHERE latch = '2' AND origid = 11 AND weight = 2; +latch origid destid weight seq linkid +2 11 NULL 2 3 10 +SELECT * FROM graph WHERE latch = '2' AND origid = 12 AND weight = 2; +latch origid destid weight seq linkid +2 12 NULL 2 3 11 +SELECT * FROM graph WHERE latch = '2' AND origid = 1 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 2 AND weight = 3; +latch origid destid weight seq linkid +2 2 NULL 3 4 4 +SELECT * FROM graph WHERE latch = '2' AND origid = 3 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 4 AND weight = 3; +latch origid destid weight seq linkid +2 4 NULL 3 4 2 +SELECT * FROM graph WHERE latch = '2' AND origid = 5 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 6 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 7 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 8 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 9 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 10 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 11 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 12 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 1 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +2 1 NULL 2 4 4 +2 1 NULL 1 3 3 +2 1 NULL 1 2 2 +SELECT * FROM graph WHERE latch = '2' AND origid = 2 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +2 2 NULL 2 3 3 +2 2 NULL 1 2 1 +SELECT * FROM graph WHERE latch = '2' AND origid = 3 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +2 3 NULL 2 4 2 +2 3 NULL 1 3 4 +2 3 NULL 1 2 1 +SELECT * FROM graph WHERE latch = '2' AND origid = 4 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +2 4 NULL 2 3 1 +2 4 NULL 1 2 3 +SELECT * FROM graph WHERE latch = '2' AND origid = 5 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +2 5 NULL 1 3 7 +2 5 NULL 1 2 6 +SELECT * FROM graph WHERE latch = '2' AND origid = 6 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +2 6 NULL 2 3 7 +2 6 NULL 1 2 5 +SELECT * FROM graph WHERE latch = '2' AND origid = 7 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 8 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 9 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 10 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +2 10 NULL 2 3 12 +2 10 NULL 1 2 11 +SELECT * FROM graph WHERE latch = '2' AND origid = 11 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +2 11 NULL 2 3 10 +2 11 NULL 1 2 12 +SELECT * FROM graph WHERE latch = '2' AND origid = 12 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +2 12 NULL 2 3 11 +2 12 NULL 1 2 10 +SELECT * FROM graph WHERE latch = '2' AND destid = 1; +latch origid destid weight seq linkid +2 NULL 1 2 4 4 +2 NULL 1 1 3 3 +2 NULL 1 1 2 2 +2 NULL 1 0 1 1 +SELECT * FROM graph WHERE latch = '2' AND destid = 2; +latch origid destid weight seq linkid +2 NULL 2 3 4 4 +2 NULL 2 2 3 3 +2 NULL 2 1 2 1 +2 NULL 2 0 1 2 +SELECT * FROM graph WHERE latch = '2' AND destid = 3; +latch origid destid weight seq linkid +2 NULL 3 2 4 2 +2 NULL 3 1 3 4 +2 NULL 3 1 2 1 +2 NULL 3 0 1 3 +SELECT * FROM graph WHERE latch = '2' AND destid = 4; +latch origid destid weight seq linkid +2 NULL 4 3 4 2 +2 NULL 4 2 3 1 +2 NULL 4 1 2 3 +2 NULL 4 0 1 4 +SELECT * FROM graph WHERE latch = '2' AND destid = 5; +latch origid destid weight seq linkid +2 NULL 5 1 2 6 +2 NULL 5 0 1 5 +SELECT * FROM graph WHERE latch = '2' AND destid = 6; +latch origid destid weight seq linkid +2 NULL 6 1 2 5 +2 NULL 6 0 1 6 +SELECT * FROM graph WHERE latch = '2' AND destid = 7; +latch origid destid weight seq linkid +2 NULL 7 2 3 6 +2 NULL 7 1 2 5 +2 NULL 7 0 1 7 +SELECT * FROM graph WHERE latch = '2' AND destid = 8; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND destid = 9; +latch origid destid weight seq linkid +2 NULL 9 0 1 9 +SELECT * FROM graph WHERE latch = '2' AND destid = 10; +latch origid destid weight seq linkid +2 NULL 10 2 3 11 +2 NULL 10 1 2 12 +2 NULL 10 0 1 10 +SELECT * FROM graph WHERE latch = '2' AND destid = 11; +latch origid destid weight seq linkid +2 NULL 11 2 3 12 +2 NULL 11 1 2 10 +2 NULL 11 0 1 11 +SELECT * FROM graph WHERE latch = '2' AND destid = 12; +latch origid destid weight seq linkid +2 NULL 12 2 3 10 +2 NULL 12 1 2 11 +2 NULL 12 0 1 12 +SELECT * FROM graph WHERE latch = '2' AND destid = 1 and weight = 1; +latch origid destid weight seq linkid +2 NULL 1 1 3 3 +2 NULL 1 1 2 2 +SELECT * FROM graph WHERE latch = '2' AND destid = 2 and weight = 1; +latch origid destid weight seq linkid +2 NULL 2 1 2 1 +SELECT * FROM graph WHERE latch = '2' AND destid = 3 and weight = 1; +latch origid destid weight seq linkid +2 NULL 3 1 3 4 +2 NULL 3 1 2 1 +SELECT * FROM graph WHERE latch = '2' AND destid = 4 and weight = 1; +latch origid destid weight seq linkid +2 NULL 4 1 2 3 +SELECT * FROM graph WHERE latch = '2' AND destid = 5 and weight = 1; +latch origid destid weight seq linkid +2 NULL 5 1 2 6 +SELECT * FROM graph WHERE latch = '2' AND destid = 6 and weight = 1; +latch origid destid weight seq linkid +2 NULL 6 1 2 5 +SELECT * FROM graph WHERE latch = '2' AND destid = 7 and weight = 1; +latch origid destid weight seq linkid +2 NULL 7 1 2 5 +SELECT * FROM graph WHERE latch = '2' AND destid = 8 and weight = 1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND destid = 9 and weight = 1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND destid = 10 and weight = 1; +latch origid destid weight seq linkid +2 NULL 10 1 2 12 +SELECT * FROM graph WHERE latch = '2' AND destid = 11 and weight = 1; +latch origid destid weight seq linkid +2 NULL 11 1 2 10 +SELECT * FROM graph WHERE latch = '2' AND destid = 12 and weight = 1; +latch origid destid weight seq linkid +2 NULL 12 1 2 11 +SELECT * FROM graph WHERE latch = '2' AND destid = 1 and weight = 2; +latch origid destid weight seq linkid +2 NULL 1 2 4 4 +SELECT * FROM graph WHERE latch = '2' AND destid = 2 and weight = 2; +latch origid destid weight seq linkid +2 NULL 2 2 3 3 +SELECT * FROM graph WHERE latch = '2' AND destid = 3 and weight = 2; +latch origid destid weight seq linkid +2 NULL 3 2 4 2 +SELECT * FROM graph WHERE latch = '2' AND destid = 4 and weight = 2; +latch origid destid weight seq linkid +2 NULL 4 2 3 1 +SELECT * FROM graph WHERE latch = '2' AND destid = 5 and weight = 2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND destid = 6 and weight = 2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND destid = 7 and weight = 2; +latch origid destid weight seq linkid +2 NULL 7 2 3 6 +SELECT * FROM graph WHERE latch = '2' AND destid = 8 and weight = 2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND destid = 9 and weight = 2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND destid = 10 and weight = 2; +latch origid destid weight seq linkid +2 NULL 10 2 3 11 +SELECT * FROM graph WHERE latch = '2' AND destid = 11 and weight = 2; +latch origid destid weight seq linkid +2 NULL 11 2 3 12 +SELECT * FROM graph WHERE latch = '2' AND destid = 12 and weight = 2; +latch origid destid weight seq linkid +2 NULL 12 2 3 10 +SELECT * FROM graph WHERE latch = '2' AND destid = 1 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND destid = 2 and weight = 3; +latch origid destid weight seq linkid +2 NULL 2 3 4 4 +SELECT * FROM graph WHERE latch = '2' AND destid = 3 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND destid = 4 and weight = 3; +latch origid destid weight seq linkid +2 NULL 4 3 4 2 +SELECT * FROM graph WHERE latch = '2' AND destid = 5 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND destid = 6 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND destid = 7 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND destid = 8 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND destid = 9 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND destid = 10 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND destid = 11 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND destid = 12 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = NULL; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND destid = NULL; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND weight = 1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2'; +latch origid destid weight seq linkid +# Dijkstras algorithm tests +SELECT * FROM graph WHERE latch='dijkstras' AND origid=1 AND destid=1; +latch origid destid weight seq linkid +dijkstras 1 1 NULL 0 1 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=1 AND destid=2; +latch origid destid weight seq linkid +dijkstras 1 2 NULL 0 1 +dijkstras 1 2 1 1 2 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=2 AND destid=1; +latch origid destid weight seq linkid +dijkstras 2 1 NULL 0 2 +dijkstras 2 1 1 1 1 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=1 AND destid=4; +latch origid destid weight seq linkid +dijkstras 1 4 NULL 0 1 +dijkstras 1 4 1 1 3 +dijkstras 1 4 1 2 4 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=4 AND destid=1; +latch origid destid weight seq linkid +dijkstras 4 1 NULL 0 4 +dijkstras 4 1 1 1 3 +dijkstras 4 1 1 2 1 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=1 AND destid=5; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch='dijkstras' AND origid=1 AND destid=666; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch='dijkstras' AND origid=5 AND destid=7; +latch origid destid weight seq linkid +dijkstras 5 7 NULL 0 5 +dijkstras 5 7 1 1 7 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=7 AND destid=5; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch='dijkstras' AND origid=10 AND destid=11; +latch origid destid weight seq linkid +dijkstras 10 11 NULL 0 10 +dijkstras 10 11 1 1 11 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=10 AND destid=12; +latch origid destid weight seq linkid +dijkstras 10 12 NULL 0 10 +dijkstras 10 12 1 1 11 +dijkstras 10 12 1 2 12 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=11 AND destid=10; +latch origid destid weight seq linkid +dijkstras 11 10 NULL 0 11 +dijkstras 11 10 1 1 12 +dijkstras 11 10 1 2 10 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=11 AND destid=12; +latch origid destid weight seq linkid +dijkstras 11 12 NULL 0 11 +dijkstras 11 12 1 1 12 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=12 AND destid=10; +latch origid destid weight seq linkid +dijkstras 12 10 NULL 0 12 +dijkstras 12 10 1 1 10 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=12 AND destid=11; +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 2 4 4 +dijkstras 1 NULL 1 3 3 +dijkstras 1 NULL 1 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 3 4 4 +dijkstras 2 NULL 2 3 3 +dijkstras 2 NULL 1 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 2 4 2 +dijkstras 3 NULL 1 3 4 +dijkstras 3 NULL 1 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 3 4 2 +dijkstras 4 NULL 2 3 1 +dijkstras 4 NULL 1 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 1 3 7 +dijkstras 5 NULL 1 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 2 3 7 +dijkstras 6 NULL 1 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 +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 2 3 12 +dijkstras 10 NULL 1 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 2 3 10 +dijkstras 11 NULL 1 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 2 3 11 +dijkstras 12 NULL 1 2 10 +dijkstras 12 NULL 0 1 12 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=666; +latch origid destid weight seq linkid +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 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 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 2 3 6 +dijkstras NULL 7 1 2 5 +dijkstras NULL 7 0 1 7 +SELECT * FROM graph WHERE latch='dijkstras' AND destid=8; +latch origid destid weight seq linkid +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 11 +dijkstras NULL 10 1 2 12 +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 12 +dijkstras NULL 11 1 2 10 +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 10 +dijkstras NULL 12 1 2 11 +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 +1 1 1 NULL 0 1 +SELECT * FROM graph WHERE latch='1' AND origid=1 AND destid=2; +latch origid destid weight seq linkid +1 1 2 NULL 0 1 +1 1 2 1 1 2 +SELECT * FROM graph WHERE latch='1' AND origid=2 AND destid=1; +latch origid destid weight seq linkid +1 2 1 NULL 0 2 +1 2 1 1 1 1 +SELECT * FROM graph WHERE latch='1' AND origid=1 AND destid=4; +latch origid destid weight seq linkid +1 1 4 NULL 0 1 +1 1 4 1 1 3 +1 1 4 1 2 4 +SELECT * FROM graph WHERE latch='1' AND origid=4 AND destid=1; +latch origid destid weight seq linkid +1 4 1 NULL 0 4 +1 4 1 1 1 3 +1 4 1 1 2 1 +SELECT * FROM graph WHERE latch='1' AND origid=1 AND destid=5; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch='1' AND origid=1 AND destid=666; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch='1' AND origid=5 AND destid=7; +latch origid destid weight seq linkid +1 5 7 NULL 0 5 +1 5 7 1 1 7 +SELECT * FROM graph WHERE latch='1' AND origid=7 AND destid=5; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch='1' AND origid=10 AND destid=11; +latch origid destid weight seq linkid +1 10 11 NULL 0 10 +1 10 11 1 1 11 +SELECT * FROM graph WHERE latch='1' AND origid=10 AND destid=12; +latch origid destid weight seq linkid +1 10 12 NULL 0 10 +1 10 12 1 1 11 +1 10 12 1 2 12 +SELECT * FROM graph WHERE latch='1' AND origid=11 AND destid=10; +latch origid destid weight seq linkid +1 11 10 NULL 0 11 +1 11 10 1 1 12 +1 11 10 1 2 10 +SELECT * FROM graph WHERE latch='1' AND origid=11 AND destid=12; +latch origid destid weight seq linkid +1 11 12 NULL 0 11 +1 11 12 1 1 12 +SELECT * FROM graph WHERE latch='1' AND origid=12 AND destid=10; +latch origid destid weight seq linkid +1 12 10 NULL 0 12 +1 12 10 1 1 10 +SELECT * FROM graph WHERE latch='1' AND origid=12 AND destid=11; +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 2 4 4 +1 1 NULL 1 3 3 +1 1 NULL 1 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 3 4 4 +1 2 NULL 2 3 3 +1 2 NULL 1 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 2 4 2 +1 3 NULL 1 3 4 +1 3 NULL 1 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 3 4 2 +1 4 NULL 2 3 1 +1 4 NULL 1 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 1 3 7 +1 5 NULL 1 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 2 3 7 +1 6 NULL 1 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 +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 2 3 12 +1 10 NULL 1 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 2 3 10 +1 11 NULL 1 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 2 3 11 +1 12 NULL 1 2 10 +1 12 NULL 0 1 12 +SELECT * FROM graph WHERE latch='1' AND origid=666; +latch origid destid weight seq linkid +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 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 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 2 3 6 +1 NULL 7 1 2 5 +1 NULL 7 0 1 7 +SELECT * FROM graph WHERE latch='1' AND destid=8; +latch origid destid weight seq linkid +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 11 +1 NULL 10 1 2 12 +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 12 +1 NULL 11 1 2 10 +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 10 +1 NULL 12 1 2 11 +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); +SELECT * FROM graph WHERE latch='dijkstras' AND origid=10 AND destid=13; +latch origid destid weight seq linkid +dijkstras 10 13 NULL 0 10 +dijkstras 10 13 1 1 11 +dijkstras 10 13 1 2 13 +DELETE FROM graph_base where from_id=10 and to_id=11; +INSERT INTO graph_base(from_id, to_id) VALUES (10,15); +INSERT INTO graph_base(from_id, to_id) VALUES (15,13); +SELECT * FROM graph WHERE latch='dijkstras' AND origid=10 AND destid=13; +latch origid destid weight seq linkid +dijkstras 10 13 NULL 0 10 +dijkstras 10 13 1 1 14 +dijkstras 10 13 1 2 13 +INSERT INTO graph_base(from_id, to_id) VALUES (10,11); +SELECT * FROM graph WHERE latch='dijkstras' AND origid=10 AND destid=13; +latch origid destid weight seq linkid +dijkstras 10 13 NULL 0 10 +dijkstras 10 13 1 1 11 +dijkstras 10 13 1 2 13 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=1; +latch origid destid weight seq linkid +dijkstras 1 NULL 2 4 4 +dijkstras 1 NULL 1 3 3 +dijkstras 1 NULL 1 2 2 +dijkstras 1 NULL 0 1 1 +INSERT INTO graph_base(from_id, to_id) VALUES (21,22); +SELECT * FROM graph WHERE latch='dijkstras' AND origid=21; +latch origid destid weight seq linkid +dijkstras 21 NULL 1 2 22 +dijkstras 21 NULL 0 1 21 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=22; +latch origid destid weight seq linkid +dijkstras 22 NULL 0 1 22 +INSERT INTO graph_base(from_id, to_id) VALUES (4,17); +SELECT * FROM graph WHERE latch='dijkstras' AND origid=1; +latch origid destid weight seq linkid +dijkstras 1 NULL 3 5 17 +dijkstras 1 NULL 2 4 4 +dijkstras 1 NULL 1 3 3 +dijkstras 1 NULL 1 2 2 +dijkstras 1 NULL 0 1 1 +INSERT INTO graph_base(from_id, to_id) VALUES (4,16); +SELECT * FROM graph WHERE latch='dijkstras' AND origid=1; +latch origid destid weight seq linkid +dijkstras 1 NULL 3 6 17 +dijkstras 1 NULL 3 5 16 +dijkstras 1 NULL 2 4 4 +dijkstras 1 NULL 1 3 3 +dijkstras 1 NULL 1 2 2 +dijkstras 1 NULL 0 1 1 +INSERT INTO graph_base(from_id, to_id) VALUES (17,18); +SELECT * FROM graph WHERE latch='dijkstras' AND origid=1; +latch origid destid weight seq linkid +dijkstras 1 NULL 4 7 18 +dijkstras 1 NULL 3 6 17 +dijkstras 1 NULL 3 5 16 +dijkstras 1 NULL 2 4 4 +dijkstras 1 NULL 1 3 3 +dijkstras 1 NULL 1 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 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 +DELETE FROM graph_base WHERE from_id=5; +DELETE FROM graph_base WHERE from_id=3 AND to_id=5; +# which means there is a path in one direction only 1>3>4>6 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=1 AND destid=6; +latch origid destid weight seq linkid +dijkstras 1 6 NULL 0 1 +dijkstras 1 6 1 1 3 +dijkstras 1 6 1 2 4 +dijkstras 1 6 1 3 6 +# but not 6>4>3>1 (so no result) +SELECT * FROM graph WHERE latch='dijkstras' AND origid=6 AND destid=1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch='1' AND origid=1 AND destid=6; +latch origid destid weight seq linkid +1 1 6 NULL 0 1 +1 1 6 1 1 3 +1 1 6 1 2 4 +1 1 6 1 3 6 +SELECT * FROM graph WHERE latch='1' AND origid=6 AND destid=1; +latch origid destid weight seq linkid +DELETE FROM graph_base; +FLUSH TABLES; +TRUNCATE TABLE graph_base; +DROP TABLE graph_base; +DROP TABLE graph; diff --git a/storage/oqgraph/mysql-test/oqgraph/general-MyISAM.test b/storage/oqgraph/mysql-test/oqgraph/general-MyISAM.test new file mode 100644 index 00000000..f1e59e54 --- /dev/null +++ b/storage/oqgraph/mysql-test/oqgraph/general-MyISAM.test @@ -0,0 +1,3 @@ +# This is a maintainer generated file. Generated at Wednesday 5 February 22:26:12 CST 2014. +--let $oqgraph_use_table_type= MyISAM +--source general.inc diff --git a/storage/oqgraph/mysql-test/oqgraph/general-innodb.result b/storage/oqgraph/mysql-test/oqgraph/general-innodb.result new file mode 100644 index 00000000..38e3e0a2 --- /dev/null +++ b/storage/oqgraph/mysql-test/oqgraph/general-innodb.result @@ -0,0 +1,1593 @@ +DROP TABLE IF EXISTS graph_base; +DROP TABLE IF EXISTS graph; +DROP TABLE IF EXISTS graph2; +Performing OQGraph General test suite for ENGINE=innodb +CREATE TABLE graph_base ( +from_id INT UNSIGNED NOT NULL, +to_id INT UNSIGNED NOT NULL, +PRIMARY KEY (from_id,to_id), +INDEX (to_id) +) ENGINE= innodb ; +CREATE TABLE graph ENGINE=OQGRAPH DATA_TABLE='graph_base' ORIGID='from_id', DESTID='to_id'; +select * from graph; +latch origid destid weight seq linkid +INSERT INTO graph_base(from_id, to_id) VALUES (1,2), (2,1); +INSERT INTO graph_base(from_id, to_id) VALUES (1,3), (3,1); +INSERT INTO graph_base(from_id, to_id) VALUES (3,4), (4,3); +INSERT INTO graph_base(from_id, to_id) VALUES (5,6), (6,5); +INSERT INTO graph_base(from_id, to_id) VALUES (5,7); +INSERT INTO graph_base(from_id, to_id) VALUES (9,9); +INSERT INTO graph_base(from_id, to_id) VALUES (10,11); +INSERT INTO graph_base(from_id, to_id) VALUES (11,12); +INSERT INTO graph_base(from_id, to_id) VALUES (12,10); +# Return all edges +SELECT * FROM graph; +latch origid destid weight seq linkid +NULL 1 2 1 NULL NULL +NULL 1 3 1 NULL NULL +NULL 2 1 1 NULL NULL +NULL 3 1 1 NULL NULL +NULL 3 4 1 NULL NULL +NULL 4 3 1 NULL NULL +NULL 5 6 1 NULL NULL +NULL 5 7 1 NULL NULL +NULL 6 5 1 NULL NULL +NULL 9 9 1 NULL NULL +NULL 10 11 1 NULL NULL +NULL 11 12 1 NULL NULL +NULL 12 10 1 NULL NULL +# Currently count should be 13 +SELECT count(*) FROM graph; +count(*) +13 +# Return all edges when latch is NULL - this is different to latch='' and same as no where clause +SELECT * FROM graph where latch is NULL; +latch origid destid weight seq linkid +NULL 1 2 1 NULL NULL +NULL 1 3 1 NULL NULL +NULL 2 1 1 NULL NULL +NULL 3 1 1 NULL NULL +NULL 3 4 1 NULL NULL +NULL 4 3 1 NULL NULL +NULL 5 6 1 NULL NULL +NULL 5 7 1 NULL NULL +NULL 6 5 1 NULL NULL +NULL 9 9 1 NULL NULL +NULL 10 11 1 NULL NULL +NULL 11 12 1 NULL NULL +NULL 12 10 1 NULL NULL +# Return all vertices, and subsets of vertices +SELECT * FROM graph where latch=''; +latch origid destid weight seq linkid + NULL NULL NULL NULL 1 + NULL NULL NULL NULL 2 + NULL NULL NULL NULL 3 + NULL NULL NULL NULL 4 + NULL NULL NULL NULL 5 + NULL NULL NULL NULL 6 + NULL NULL NULL NULL 7 + NULL NULL NULL NULL 9 + NULL NULL NULL NULL 10 + NULL NULL NULL NULL 11 + NULL NULL NULL NULL 12 +SELECT * FROM graph where latch='0'; +latch origid destid weight seq linkid +0 NULL NULL NULL NULL 1 +0 NULL NULL NULL NULL 2 +0 NULL NULL NULL NULL 3 +0 NULL NULL NULL NULL 4 +0 NULL NULL NULL NULL 5 +0 NULL NULL NULL NULL 6 +0 NULL NULL NULL NULL 7 +0 NULL NULL NULL NULL 9 +0 NULL NULL NULL NULL 10 +0 NULL NULL NULL NULL 11 +0 NULL NULL NULL NULL 12 +# Currently count should be 11 +SELECT count(*) FROM graph where latch=''; +count(*) +11 +SELECT * FROM graph where latch='' and linkid = 2; +latch origid destid weight seq linkid + NULL NULL NULL NULL 2 +SELECT * FROM graph where latch='' and (linkid > 2 and linkid < 6); +latch origid destid weight seq linkid + NULL NULL NULL NULL 3 + NULL NULL NULL NULL 4 + NULL NULL NULL NULL 5 +SELECT * FROM graph where latch='' and linkid = NULL; +latch origid destid weight seq linkid +SELECT * FROM graph where latch='' and linkid = 666; +latch origid destid weight seq linkid +SELECT origid as `from`, linkid as `to` FROM graph where latch='' and origid = 1; +from to +1 3 +1 2 +SELECT origid as `from`, linkid as `to` FROM graph where latch='' and origid = 2; +from to +2 1 +SELECT origid as `from`, linkid as `to` FROM graph where latch='' and origid = 4; +from to +4 3 +SELECT origid as `from`, linkid as `to` FROM graph where latch='' and origid = 9; +from to +9 9 +SELECT origid as `from`, linkid as `to` FROM graph where latch='' and origid = 10; +from to +10 11 +SELECT origid as `from`, linkid as `to` FROM graph where latch='' and origid = NULL; +from to +SELECT origid as `from`, linkid as `to` FROM graph where latch='' and origid = 666; +from to +SELECT linkid as `from`, destid as `to` FROM graph where latch='' and destid = 1; +from to +3 1 +2 1 +SELECT linkid as `from`, destid as `to` FROM graph where latch='' and destid = 2; +from to +1 2 +SELECT linkid as `from`, destid as `to` FROM graph where latch='' and destid = 4; +from to +3 4 +SELECT linkid as `from`, destid as `to` FROM graph where latch='' and destid = 9; +from to +9 9 +SELECT linkid as `from`, destid as `to` FROM graph where latch='' and destid = 10; +from to +12 10 +SELECT linkid as `from`, destid as `to` FROM graph where latch='' and destid = NULL; +from to +SELECT linkid as `from`, destid as `to` FROM graph where latch='' and destid = 666; +from to +SELECT * FROM graph where latch='0'; +latch origid destid weight seq linkid +0 NULL NULL NULL NULL 1 +0 NULL NULL NULL NULL 2 +0 NULL NULL NULL NULL 3 +0 NULL NULL NULL NULL 4 +0 NULL NULL NULL NULL 5 +0 NULL NULL NULL NULL 6 +0 NULL NULL NULL NULL 7 +0 NULL NULL NULL NULL 9 +0 NULL NULL NULL NULL 10 +0 NULL NULL NULL NULL 11 +0 NULL NULL NULL NULL 12 +SELECT count(*) FROM graph where latch='0'; +count(*) +11 +SELECT * FROM graph where latch='0' and linkid = 2; +latch origid destid weight seq linkid +0 NULL NULL NULL NULL 2 +SELECT * FROM graph where latch='0' and (linkid > 2 and linkid < 6); +latch origid destid weight seq linkid +0 NULL NULL NULL NULL 3 +0 NULL NULL NULL NULL 4 +0 NULL NULL NULL NULL 5 +SELECT origid as `from`, linkid as `to` FROM graph where latch='0' and origid = 1; +from to +1 3 +1 2 +SELECT origid as `from`, linkid as `to` FROM graph where latch='0' and origid = 2; +from to +2 1 +SELECT origid as `from`, linkid as `to` FROM graph where latch='0' and origid = 4; +from to +4 3 +SELECT origid as `from`, linkid as `to` FROM graph where latch='0' and origid = 9; +from to +9 9 +SELECT origid as `from`, linkid as `to` FROM graph where latch='0' and origid = 10; +from to +10 11 +SELECT linkid as `from`, destid as `to` FROM graph where latch='0' and destid = 1; +from to +3 1 +2 1 +SELECT linkid as `from`, destid as `to` FROM graph where latch='0' and destid = 2; +from to +1 2 +SELECT linkid as `from`, destid as `to` FROM graph where latch='0' and destid = 4; +from to +3 4 +SELECT linkid as `from`, destid as `to` FROM graph where latch='0' and destid = 9; +from to +9 9 +SELECT linkid as `from`, destid as `to` FROM graph where latch='0' and destid = 10; +from to +12 10 +# Leaves search tests +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 4; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 5; +latch origid destid weight seq linkid +leaves 5 NULL 1 1 7 +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 6; +latch origid destid weight seq linkid +leaves 6 NULL 2 1 7 +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 7; +latch origid destid weight seq linkid +leaves 7 NULL 0 1 7 +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 8; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 9; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 10; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 11; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 12; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 4; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 5; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 6; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 7; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 8; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 9; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 10; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 11; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 12; +latch origid destid weight seq linkid +INSERT INTO graph_base(from_id, to_id) VALUES (10,13); +INSERT INTO graph_base(from_id, to_id) VALUES (11,14); +INSERT INTO graph_base(from_id, to_id) VALUES (12,15); +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 10; +latch origid destid weight seq linkid +leaves 10 NULL 3 3 15 +leaves 10 NULL 2 2 14 +leaves 10 NULL 1 1 13 +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 11; +latch origid destid weight seq linkid +leaves 11 NULL 3 3 13 +leaves 11 NULL 2 2 15 +leaves 11 NULL 1 1 14 +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 12; +latch origid destid weight seq linkid +leaves 12 NULL 3 3 14 +leaves 12 NULL 2 2 13 +leaves 12 NULL 1 1 15 +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 13; +latch origid destid weight seq linkid +leaves 13 NULL 0 1 13 +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 14; +latch origid destid weight seq linkid +leaves 14 NULL 0 1 14 +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 15; +latch origid destid weight seq linkid +leaves 15 NULL 0 1 15 +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 10; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 11; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 12; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 13; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 14; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 15; +latch origid destid weight seq linkid +DELETE FROM graph_base where from_id=10 and to_id=13; +DELETE FROM graph_base where from_id=11 and to_id=14; +DELETE FROM graph_base where from_id=12 and to_id=15; +INSERT INTO graph_base(from_id, to_id) VALUES (13,10); +INSERT INTO graph_base(from_id, to_id) VALUES (14,11); +INSERT INTO graph_base(from_id, to_id) VALUES (15,12); +INSERT INTO graph_base(from_id, to_id) VALUES (16,1); +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 10; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 11; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 12; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 13; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 14; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 15; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 16; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 10; +latch origid destid weight seq linkid +leaves NULL 10 3 3 14 +leaves NULL 10 2 2 15 +leaves NULL 10 1 1 13 +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 11; +latch origid destid weight seq linkid +leaves NULL 11 3 3 15 +leaves NULL 11 2 2 13 +leaves NULL 11 1 1 14 +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 12; +latch origid destid weight seq linkid +leaves NULL 12 3 3 13 +leaves NULL 12 2 2 14 +leaves NULL 12 1 1 15 +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 13; +latch origid destid weight seq linkid +leaves NULL 13 0 1 13 +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 14; +latch origid destid weight seq linkid +leaves NULL 14 0 1 14 +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 15; +latch origid destid weight seq linkid +leaves NULL 15 0 1 15 +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 1; +latch origid destid weight seq linkid +leaves NULL 1 1 1 16 +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 2; +latch origid destid weight seq linkid +leaves NULL 2 2 1 16 +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 3; +latch origid destid weight seq linkid +leaves NULL 3 2 1 16 +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 4; +latch origid destid weight seq linkid +leaves NULL 4 3 1 16 +DELETE FROM graph_base where from_id=13 and to_id=10; +DELETE FROM graph_base where from_id=14 and to_id=11; +DELETE FROM graph_base where from_id=15 and to_id=12; +DELETE FROM graph_base where from_id=16 and to_id=1; +SELECT * FROM graph WHERE latch='leaves' AND origid=1 AND destid=2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch='leaves' AND origid=1 AND destid=3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch='leaves' AND origid=1 AND destid=4; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch='leaves' AND origid=6 AND destid=7; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch='leaves' AND origid=10 AND destid=11; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch='leaves' AND origid=10 AND destid=12; +latch origid destid weight seq linkid +# Breadth-first search tests +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 1; +latch origid destid weight seq linkid +breadth_first 1 NULL 2 4 4 +breadth_first 1 NULL 1 3 3 +breadth_first 1 NULL 1 2 2 +breadth_first 1 NULL 0 1 1 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 2; +latch origid destid weight seq linkid +breadth_first 2 NULL 3 4 4 +breadth_first 2 NULL 2 3 3 +breadth_first 2 NULL 1 2 1 +breadth_first 2 NULL 0 1 2 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 3; +latch origid destid weight seq linkid +breadth_first 3 NULL 2 4 2 +breadth_first 3 NULL 1 3 4 +breadth_first 3 NULL 1 2 1 +breadth_first 3 NULL 0 1 3 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 4; +latch origid destid weight seq linkid +breadth_first 4 NULL 3 4 2 +breadth_first 4 NULL 2 3 1 +breadth_first 4 NULL 1 2 3 +breadth_first 4 NULL 0 1 4 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 5; +latch origid destid weight seq linkid +breadth_first 5 NULL 1 3 7 +breadth_first 5 NULL 1 2 6 +breadth_first 5 NULL 0 1 5 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 6; +latch origid destid weight seq linkid +breadth_first 6 NULL 2 3 7 +breadth_first 6 NULL 1 2 5 +breadth_first 6 NULL 0 1 6 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 7; +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 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 9; +latch origid destid weight seq linkid +breadth_first 9 NULL 0 1 9 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 10; +latch origid destid weight seq linkid +breadth_first 10 NULL 2 3 12 +breadth_first 10 NULL 1 2 11 +breadth_first 10 NULL 0 1 10 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 11; +latch origid destid weight seq linkid +breadth_first 11 NULL 2 3 10 +breadth_first 11 NULL 1 2 12 +breadth_first 11 NULL 0 1 11 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 12; +latch origid destid weight seq linkid +breadth_first 12 NULL 2 3 11 +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 +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 +breadth_first 1 NULL 1 2 2 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 2 AND weight = 1; +latch origid destid weight seq linkid +breadth_first 2 NULL 1 2 1 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 3 AND weight = 1; +latch origid destid weight seq linkid +breadth_first 3 NULL 1 3 4 +breadth_first 3 NULL 1 2 1 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 4 AND weight = 1; +latch origid destid weight seq linkid +breadth_first 4 NULL 1 2 3 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 5 AND weight = 1; +latch origid destid weight seq linkid +breadth_first 5 NULL 1 3 7 +breadth_first 5 NULL 1 2 6 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 6 AND weight = 1; +latch origid destid weight seq linkid +breadth_first 6 NULL 1 2 5 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 7 AND weight = 1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 8 AND weight = 1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 9 AND weight = 1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 10 AND weight = 1; +latch origid destid weight seq linkid +breadth_first 10 NULL 1 2 11 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 11 AND weight = 1; +latch origid destid weight seq linkid +breadth_first 11 NULL 1 2 12 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 12 AND weight = 1; +latch origid destid weight seq linkid +breadth_first 12 NULL 1 2 10 +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 1 AND weight = 1; +count(*) +2 +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 2 AND weight = 1; +count(*) +1 +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 3 AND weight = 1; +count(*) +2 +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 4 AND weight = 1; +count(*) +1 +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 5 AND weight = 1; +count(*) +2 +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 6 AND weight = 1; +count(*) +1 +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 7 AND weight = 1; +count(*) +0 +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 8 AND weight = 1; +count(*) +0 +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 9 AND weight = 1; +count(*) +0 +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 10 AND weight = 1; +count(*) +1 +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 11 AND weight = 1; +count(*) +1 +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 12 AND weight = 1; +count(*) +1 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 1 AND weight = 2; +latch origid destid weight seq linkid +breadth_first 1 NULL 2 4 4 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 2 AND weight = 2; +latch origid destid weight seq linkid +breadth_first 2 NULL 2 3 3 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 3 AND weight = 2; +latch origid destid weight seq linkid +breadth_first 3 NULL 2 4 2 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 4 AND weight = 2; +latch origid destid weight seq linkid +breadth_first 4 NULL 2 3 1 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 5 AND weight = 2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 6 AND weight = 2; +latch origid destid weight seq linkid +breadth_first 6 NULL 2 3 7 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 7 AND weight = 2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 8 AND weight = 2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 9 AND weight = 2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 10 AND weight = 2; +latch origid destid weight seq linkid +breadth_first 10 NULL 2 3 12 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 11 AND weight = 2; +latch origid destid weight seq linkid +breadth_first 11 NULL 2 3 10 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 12 AND weight = 2; +latch origid destid weight seq linkid +breadth_first 12 NULL 2 3 11 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 1 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 2 AND weight = 3; +latch origid destid weight seq linkid +breadth_first 2 NULL 3 4 4 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 3 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 4 AND weight = 3; +latch origid destid weight seq linkid +breadth_first 4 NULL 3 4 2 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 5 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 6 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 7 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 8 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 9 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 10 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 11 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 12 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 1 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +breadth_first 1 NULL 2 4 4 +breadth_first 1 NULL 1 3 3 +breadth_first 1 NULL 1 2 2 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 2 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +breadth_first 2 NULL 2 3 3 +breadth_first 2 NULL 1 2 1 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 3 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +breadth_first 3 NULL 2 4 2 +breadth_first 3 NULL 1 3 4 +breadth_first 3 NULL 1 2 1 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 4 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +breadth_first 4 NULL 2 3 1 +breadth_first 4 NULL 1 2 3 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 5 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +breadth_first 5 NULL 1 3 7 +breadth_first 5 NULL 1 2 6 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 6 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +breadth_first 6 NULL 2 3 7 +breadth_first 6 NULL 1 2 5 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 7 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 8 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 9 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 10 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +breadth_first 10 NULL 2 3 12 +breadth_first 10 NULL 1 2 11 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 11 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +breadth_first 11 NULL 2 3 10 +breadth_first 11 NULL 1 2 12 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 12 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +breadth_first 12 NULL 2 3 11 +breadth_first 12 NULL 1 2 10 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 1; +latch origid destid weight seq linkid +breadth_first NULL 1 2 4 4 +breadth_first NULL 1 1 3 3 +breadth_first NULL 1 1 2 2 +breadth_first NULL 1 0 1 1 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 2; +latch origid destid weight seq linkid +breadth_first NULL 2 3 4 4 +breadth_first NULL 2 2 3 3 +breadth_first NULL 2 1 2 1 +breadth_first NULL 2 0 1 2 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 3; +latch origid destid weight seq linkid +breadth_first NULL 3 2 4 2 +breadth_first NULL 3 1 3 4 +breadth_first NULL 3 1 2 1 +breadth_first NULL 3 0 1 3 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 4; +latch origid destid weight seq linkid +breadth_first NULL 4 3 4 2 +breadth_first NULL 4 2 3 1 +breadth_first NULL 4 1 2 3 +breadth_first NULL 4 0 1 4 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 5; +latch origid destid weight seq linkid +breadth_first NULL 5 1 2 6 +breadth_first NULL 5 0 1 5 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 6; +latch origid destid weight seq linkid +breadth_first NULL 6 1 2 5 +breadth_first NULL 6 0 1 6 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 7; +latch origid destid weight seq linkid +breadth_first NULL 7 2 3 6 +breadth_first NULL 7 1 2 5 +breadth_first NULL 7 0 1 7 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 8; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 9; +latch origid destid weight seq linkid +breadth_first NULL 9 0 1 9 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 10; +latch origid destid weight seq linkid +breadth_first NULL 10 2 3 11 +breadth_first NULL 10 1 2 12 +breadth_first NULL 10 0 1 10 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 11; +latch origid destid weight seq linkid +breadth_first NULL 11 2 3 12 +breadth_first NULL 11 1 2 10 +breadth_first NULL 11 0 1 11 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 12; +latch origid destid weight seq linkid +breadth_first NULL 12 2 3 10 +breadth_first NULL 12 1 2 11 +breadth_first NULL 12 0 1 12 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 1 and weight = 1; +latch origid destid weight seq linkid +breadth_first NULL 1 1 3 3 +breadth_first NULL 1 1 2 2 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 2 and weight = 1; +latch origid destid weight seq linkid +breadth_first NULL 2 1 2 1 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 3 and weight = 1; +latch origid destid weight seq linkid +breadth_first NULL 3 1 3 4 +breadth_first NULL 3 1 2 1 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 4 and weight = 1; +latch origid destid weight seq linkid +breadth_first NULL 4 1 2 3 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 5 and weight = 1; +latch origid destid weight seq linkid +breadth_first NULL 5 1 2 6 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 6 and weight = 1; +latch origid destid weight seq linkid +breadth_first NULL 6 1 2 5 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 7 and weight = 1; +latch origid destid weight seq linkid +breadth_first NULL 7 1 2 5 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 8 and weight = 1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 9 and weight = 1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 10 and weight = 1; +latch origid destid weight seq linkid +breadth_first NULL 10 1 2 12 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 11 and weight = 1; +latch origid destid weight seq linkid +breadth_first NULL 11 1 2 10 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 12 and weight = 1; +latch origid destid weight seq linkid +breadth_first NULL 12 1 2 11 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 1 and weight = 2; +latch origid destid weight seq linkid +breadth_first NULL 1 2 4 4 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 2 and weight = 2; +latch origid destid weight seq linkid +breadth_first NULL 2 2 3 3 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 3 and weight = 2; +latch origid destid weight seq linkid +breadth_first NULL 3 2 4 2 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 4 and weight = 2; +latch origid destid weight seq linkid +breadth_first NULL 4 2 3 1 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 5 and weight = 2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 6 and weight = 2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 7 and weight = 2; +latch origid destid weight seq linkid +breadth_first NULL 7 2 3 6 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 8 and weight = 2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 9 and weight = 2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 10 and weight = 2; +latch origid destid weight seq linkid +breadth_first NULL 10 2 3 11 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 11 and weight = 2; +latch origid destid weight seq linkid +breadth_first NULL 11 2 3 12 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 12 and weight = 2; +latch origid destid weight seq linkid +breadth_first NULL 12 2 3 10 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 1 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 2 and weight = 3; +latch origid destid weight seq linkid +breadth_first NULL 2 3 4 4 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 3 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 4 and weight = 3; +latch origid destid weight seq linkid +breadth_first NULL 4 3 4 2 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 5 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 6 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 7 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 8 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 9 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 10 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 11 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 12 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = NULL; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = NULL; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND weight = 1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first'; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 1; +latch origid destid weight seq linkid +2 1 NULL 2 4 4 +2 1 NULL 1 3 3 +2 1 NULL 1 2 2 +2 1 NULL 0 1 1 +SELECT * FROM graph WHERE latch = '2' AND origid = 2; +latch origid destid weight seq linkid +2 2 NULL 3 4 4 +2 2 NULL 2 3 3 +2 2 NULL 1 2 1 +2 2 NULL 0 1 2 +SELECT * FROM graph WHERE latch = '2' AND origid = 3; +latch origid destid weight seq linkid +2 3 NULL 2 4 2 +2 3 NULL 1 3 4 +2 3 NULL 1 2 1 +2 3 NULL 0 1 3 +SELECT * FROM graph WHERE latch = '2' AND origid = 4; +latch origid destid weight seq linkid +2 4 NULL 3 4 2 +2 4 NULL 2 3 1 +2 4 NULL 1 2 3 +2 4 NULL 0 1 4 +SELECT * FROM graph WHERE latch = '2' AND origid = 5; +latch origid destid weight seq linkid +2 5 NULL 1 3 7 +2 5 NULL 1 2 6 +2 5 NULL 0 1 5 +SELECT * FROM graph WHERE latch = '2' AND origid = 6; +latch origid destid weight seq linkid +2 6 NULL 2 3 7 +2 6 NULL 1 2 5 +2 6 NULL 0 1 6 +SELECT * FROM graph WHERE latch = '2' AND origid = 7; +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 +SELECT * FROM graph WHERE latch = '2' AND origid = 9; +latch origid destid weight seq linkid +2 9 NULL 0 1 9 +SELECT * FROM graph WHERE latch = '2' AND origid = 10; +latch origid destid weight seq linkid +2 10 NULL 2 3 12 +2 10 NULL 1 2 11 +2 10 NULL 0 1 10 +SELECT * FROM graph WHERE latch = '2' AND origid = 11; +latch origid destid weight seq linkid +2 11 NULL 2 3 10 +2 11 NULL 1 2 12 +2 11 NULL 0 1 11 +SELECT * FROM graph WHERE latch = '2' AND origid = 12; +latch origid destid weight seq linkid +2 12 NULL 2 3 11 +2 12 NULL 1 2 10 +2 12 NULL 0 1 12 +SELECT * FROM graph WHERE latch = '2' AND origid = 666; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 1 AND weight = 1; +latch origid destid weight seq linkid +2 1 NULL 1 3 3 +2 1 NULL 1 2 2 +SELECT * FROM graph WHERE latch = '2' AND origid = 2 AND weight = 1; +latch origid destid weight seq linkid +2 2 NULL 1 2 1 +SELECT * FROM graph WHERE latch = '2' AND origid = 3 AND weight = 1; +latch origid destid weight seq linkid +2 3 NULL 1 3 4 +2 3 NULL 1 2 1 +SELECT * FROM graph WHERE latch = '2' AND origid = 4 AND weight = 1; +latch origid destid weight seq linkid +2 4 NULL 1 2 3 +SELECT * FROM graph WHERE latch = '2' AND origid = 5 AND weight = 1; +latch origid destid weight seq linkid +2 5 NULL 1 3 7 +2 5 NULL 1 2 6 +SELECT * FROM graph WHERE latch = '2' AND origid = 6 AND weight = 1; +latch origid destid weight seq linkid +2 6 NULL 1 2 5 +SELECT * FROM graph WHERE latch = '2' AND origid = 7 AND weight = 1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 8 AND weight = 1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 9 AND weight = 1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 10 AND weight = 1; +latch origid destid weight seq linkid +2 10 NULL 1 2 11 +SELECT * FROM graph WHERE latch = '2' AND origid = 11 AND weight = 1; +latch origid destid weight seq linkid +2 11 NULL 1 2 12 +SELECT * FROM graph WHERE latch = '2' AND origid = 12 AND weight = 1; +latch origid destid weight seq linkid +2 12 NULL 1 2 10 +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 1 AND weight = 1; +count(*) +2 +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 2 AND weight = 1; +count(*) +1 +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 3 AND weight = 1; +count(*) +2 +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 4 AND weight = 1; +count(*) +1 +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 5 AND weight = 1; +count(*) +2 +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 6 AND weight = 1; +count(*) +1 +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 7 AND weight = 1; +count(*) +0 +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 8 AND weight = 1; +count(*) +0 +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 9 AND weight = 1; +count(*) +0 +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 10 AND weight = 1; +count(*) +1 +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 11 AND weight = 1; +count(*) +1 +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 12 AND weight = 1; +count(*) +1 +SELECT * FROM graph WHERE latch = '2' AND origid = 1 AND weight = 2; +latch origid destid weight seq linkid +2 1 NULL 2 4 4 +SELECT * FROM graph WHERE latch = '2' AND origid = 2 AND weight = 2; +latch origid destid weight seq linkid +2 2 NULL 2 3 3 +SELECT * FROM graph WHERE latch = '2' AND origid = 3 AND weight = 2; +latch origid destid weight seq linkid +2 3 NULL 2 4 2 +SELECT * FROM graph WHERE latch = '2' AND origid = 4 AND weight = 2; +latch origid destid weight seq linkid +2 4 NULL 2 3 1 +SELECT * FROM graph WHERE latch = '2' AND origid = 5 AND weight = 2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 6 AND weight = 2; +latch origid destid weight seq linkid +2 6 NULL 2 3 7 +SELECT * FROM graph WHERE latch = '2' AND origid = 7 AND weight = 2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 8 AND weight = 2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 9 AND weight = 2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 10 AND weight = 2; +latch origid destid weight seq linkid +2 10 NULL 2 3 12 +SELECT * FROM graph WHERE latch = '2' AND origid = 11 AND weight = 2; +latch origid destid weight seq linkid +2 11 NULL 2 3 10 +SELECT * FROM graph WHERE latch = '2' AND origid = 12 AND weight = 2; +latch origid destid weight seq linkid +2 12 NULL 2 3 11 +SELECT * FROM graph WHERE latch = '2' AND origid = 1 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 2 AND weight = 3; +latch origid destid weight seq linkid +2 2 NULL 3 4 4 +SELECT * FROM graph WHERE latch = '2' AND origid = 3 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 4 AND weight = 3; +latch origid destid weight seq linkid +2 4 NULL 3 4 2 +SELECT * FROM graph WHERE latch = '2' AND origid = 5 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 6 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 7 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 8 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 9 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 10 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 11 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 12 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 1 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +2 1 NULL 2 4 4 +2 1 NULL 1 3 3 +2 1 NULL 1 2 2 +SELECT * FROM graph WHERE latch = '2' AND origid = 2 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +2 2 NULL 2 3 3 +2 2 NULL 1 2 1 +SELECT * FROM graph WHERE latch = '2' AND origid = 3 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +2 3 NULL 2 4 2 +2 3 NULL 1 3 4 +2 3 NULL 1 2 1 +SELECT * FROM graph WHERE latch = '2' AND origid = 4 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +2 4 NULL 2 3 1 +2 4 NULL 1 2 3 +SELECT * FROM graph WHERE latch = '2' AND origid = 5 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +2 5 NULL 1 3 7 +2 5 NULL 1 2 6 +SELECT * FROM graph WHERE latch = '2' AND origid = 6 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +2 6 NULL 2 3 7 +2 6 NULL 1 2 5 +SELECT * FROM graph WHERE latch = '2' AND origid = 7 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 8 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 9 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 10 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +2 10 NULL 2 3 12 +2 10 NULL 1 2 11 +SELECT * FROM graph WHERE latch = '2' AND origid = 11 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +2 11 NULL 2 3 10 +2 11 NULL 1 2 12 +SELECT * FROM graph WHERE latch = '2' AND origid = 12 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +2 12 NULL 2 3 11 +2 12 NULL 1 2 10 +SELECT * FROM graph WHERE latch = '2' AND destid = 1; +latch origid destid weight seq linkid +2 NULL 1 2 4 4 +2 NULL 1 1 3 3 +2 NULL 1 1 2 2 +2 NULL 1 0 1 1 +SELECT * FROM graph WHERE latch = '2' AND destid = 2; +latch origid destid weight seq linkid +2 NULL 2 3 4 4 +2 NULL 2 2 3 3 +2 NULL 2 1 2 1 +2 NULL 2 0 1 2 +SELECT * FROM graph WHERE latch = '2' AND destid = 3; +latch origid destid weight seq linkid +2 NULL 3 2 4 2 +2 NULL 3 1 3 4 +2 NULL 3 1 2 1 +2 NULL 3 0 1 3 +SELECT * FROM graph WHERE latch = '2' AND destid = 4; +latch origid destid weight seq linkid +2 NULL 4 3 4 2 +2 NULL 4 2 3 1 +2 NULL 4 1 2 3 +2 NULL 4 0 1 4 +SELECT * FROM graph WHERE latch = '2' AND destid = 5; +latch origid destid weight seq linkid +2 NULL 5 1 2 6 +2 NULL 5 0 1 5 +SELECT * FROM graph WHERE latch = '2' AND destid = 6; +latch origid destid weight seq linkid +2 NULL 6 1 2 5 +2 NULL 6 0 1 6 +SELECT * FROM graph WHERE latch = '2' AND destid = 7; +latch origid destid weight seq linkid +2 NULL 7 2 3 6 +2 NULL 7 1 2 5 +2 NULL 7 0 1 7 +SELECT * FROM graph WHERE latch = '2' AND destid = 8; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND destid = 9; +latch origid destid weight seq linkid +2 NULL 9 0 1 9 +SELECT * FROM graph WHERE latch = '2' AND destid = 10; +latch origid destid weight seq linkid +2 NULL 10 2 3 11 +2 NULL 10 1 2 12 +2 NULL 10 0 1 10 +SELECT * FROM graph WHERE latch = '2' AND destid = 11; +latch origid destid weight seq linkid +2 NULL 11 2 3 12 +2 NULL 11 1 2 10 +2 NULL 11 0 1 11 +SELECT * FROM graph WHERE latch = '2' AND destid = 12; +latch origid destid weight seq linkid +2 NULL 12 2 3 10 +2 NULL 12 1 2 11 +2 NULL 12 0 1 12 +SELECT * FROM graph WHERE latch = '2' AND destid = 1 and weight = 1; +latch origid destid weight seq linkid +2 NULL 1 1 3 3 +2 NULL 1 1 2 2 +SELECT * FROM graph WHERE latch = '2' AND destid = 2 and weight = 1; +latch origid destid weight seq linkid +2 NULL 2 1 2 1 +SELECT * FROM graph WHERE latch = '2' AND destid = 3 and weight = 1; +latch origid destid weight seq linkid +2 NULL 3 1 3 4 +2 NULL 3 1 2 1 +SELECT * FROM graph WHERE latch = '2' AND destid = 4 and weight = 1; +latch origid destid weight seq linkid +2 NULL 4 1 2 3 +SELECT * FROM graph WHERE latch = '2' AND destid = 5 and weight = 1; +latch origid destid weight seq linkid +2 NULL 5 1 2 6 +SELECT * FROM graph WHERE latch = '2' AND destid = 6 and weight = 1; +latch origid destid weight seq linkid +2 NULL 6 1 2 5 +SELECT * FROM graph WHERE latch = '2' AND destid = 7 and weight = 1; +latch origid destid weight seq linkid +2 NULL 7 1 2 5 +SELECT * FROM graph WHERE latch = '2' AND destid = 8 and weight = 1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND destid = 9 and weight = 1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND destid = 10 and weight = 1; +latch origid destid weight seq linkid +2 NULL 10 1 2 12 +SELECT * FROM graph WHERE latch = '2' AND destid = 11 and weight = 1; +latch origid destid weight seq linkid +2 NULL 11 1 2 10 +SELECT * FROM graph WHERE latch = '2' AND destid = 12 and weight = 1; +latch origid destid weight seq linkid +2 NULL 12 1 2 11 +SELECT * FROM graph WHERE latch = '2' AND destid = 1 and weight = 2; +latch origid destid weight seq linkid +2 NULL 1 2 4 4 +SELECT * FROM graph WHERE latch = '2' AND destid = 2 and weight = 2; +latch origid destid weight seq linkid +2 NULL 2 2 3 3 +SELECT * FROM graph WHERE latch = '2' AND destid = 3 and weight = 2; +latch origid destid weight seq linkid +2 NULL 3 2 4 2 +SELECT * FROM graph WHERE latch = '2' AND destid = 4 and weight = 2; +latch origid destid weight seq linkid +2 NULL 4 2 3 1 +SELECT * FROM graph WHERE latch = '2' AND destid = 5 and weight = 2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND destid = 6 and weight = 2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND destid = 7 and weight = 2; +latch origid destid weight seq linkid +2 NULL 7 2 3 6 +SELECT * FROM graph WHERE latch = '2' AND destid = 8 and weight = 2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND destid = 9 and weight = 2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND destid = 10 and weight = 2; +latch origid destid weight seq linkid +2 NULL 10 2 3 11 +SELECT * FROM graph WHERE latch = '2' AND destid = 11 and weight = 2; +latch origid destid weight seq linkid +2 NULL 11 2 3 12 +SELECT * FROM graph WHERE latch = '2' AND destid = 12 and weight = 2; +latch origid destid weight seq linkid +2 NULL 12 2 3 10 +SELECT * FROM graph WHERE latch = '2' AND destid = 1 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND destid = 2 and weight = 3; +latch origid destid weight seq linkid +2 NULL 2 3 4 4 +SELECT * FROM graph WHERE latch = '2' AND destid = 3 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND destid = 4 and weight = 3; +latch origid destid weight seq linkid +2 NULL 4 3 4 2 +SELECT * FROM graph WHERE latch = '2' AND destid = 5 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND destid = 6 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND destid = 7 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND destid = 8 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND destid = 9 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND destid = 10 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND destid = 11 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND destid = 12 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = NULL; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND destid = NULL; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND weight = 1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2'; +latch origid destid weight seq linkid +# Dijkstras algorithm tests +SELECT * FROM graph WHERE latch='dijkstras' AND origid=1 AND destid=1; +latch origid destid weight seq linkid +dijkstras 1 1 NULL 0 1 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=1 AND destid=2; +latch origid destid weight seq linkid +dijkstras 1 2 NULL 0 1 +dijkstras 1 2 1 1 2 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=2 AND destid=1; +latch origid destid weight seq linkid +dijkstras 2 1 NULL 0 2 +dijkstras 2 1 1 1 1 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=1 AND destid=4; +latch origid destid weight seq linkid +dijkstras 1 4 NULL 0 1 +dijkstras 1 4 1 1 3 +dijkstras 1 4 1 2 4 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=4 AND destid=1; +latch origid destid weight seq linkid +dijkstras 4 1 NULL 0 4 +dijkstras 4 1 1 1 3 +dijkstras 4 1 1 2 1 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=1 AND destid=5; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch='dijkstras' AND origid=1 AND destid=666; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch='dijkstras' AND origid=5 AND destid=7; +latch origid destid weight seq linkid +dijkstras 5 7 NULL 0 5 +dijkstras 5 7 1 1 7 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=7 AND destid=5; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch='dijkstras' AND origid=10 AND destid=11; +latch origid destid weight seq linkid +dijkstras 10 11 NULL 0 10 +dijkstras 10 11 1 1 11 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=10 AND destid=12; +latch origid destid weight seq linkid +dijkstras 10 12 NULL 0 10 +dijkstras 10 12 1 1 11 +dijkstras 10 12 1 2 12 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=11 AND destid=10; +latch origid destid weight seq linkid +dijkstras 11 10 NULL 0 11 +dijkstras 11 10 1 1 12 +dijkstras 11 10 1 2 10 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=11 AND destid=12; +latch origid destid weight seq linkid +dijkstras 11 12 NULL 0 11 +dijkstras 11 12 1 1 12 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=12 AND destid=10; +latch origid destid weight seq linkid +dijkstras 12 10 NULL 0 12 +dijkstras 12 10 1 1 10 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=12 AND destid=11; +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 2 4 4 +dijkstras 1 NULL 1 3 3 +dijkstras 1 NULL 1 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 3 4 4 +dijkstras 2 NULL 2 3 3 +dijkstras 2 NULL 1 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 2 4 2 +dijkstras 3 NULL 1 3 4 +dijkstras 3 NULL 1 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 3 4 2 +dijkstras 4 NULL 2 3 1 +dijkstras 4 NULL 1 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 1 3 7 +dijkstras 5 NULL 1 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 2 3 7 +dijkstras 6 NULL 1 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 +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 2 3 12 +dijkstras 10 NULL 1 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 2 3 10 +dijkstras 11 NULL 1 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 2 3 11 +dijkstras 12 NULL 1 2 10 +dijkstras 12 NULL 0 1 12 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=666; +latch origid destid weight seq linkid +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 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 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 2 3 6 +dijkstras NULL 7 1 2 5 +dijkstras NULL 7 0 1 7 +SELECT * FROM graph WHERE latch='dijkstras' AND destid=8; +latch origid destid weight seq linkid +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 11 +dijkstras NULL 10 1 2 12 +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 12 +dijkstras NULL 11 1 2 10 +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 10 +dijkstras NULL 12 1 2 11 +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 +1 1 1 NULL 0 1 +SELECT * FROM graph WHERE latch='1' AND origid=1 AND destid=2; +latch origid destid weight seq linkid +1 1 2 NULL 0 1 +1 1 2 1 1 2 +SELECT * FROM graph WHERE latch='1' AND origid=2 AND destid=1; +latch origid destid weight seq linkid +1 2 1 NULL 0 2 +1 2 1 1 1 1 +SELECT * FROM graph WHERE latch='1' AND origid=1 AND destid=4; +latch origid destid weight seq linkid +1 1 4 NULL 0 1 +1 1 4 1 1 3 +1 1 4 1 2 4 +SELECT * FROM graph WHERE latch='1' AND origid=4 AND destid=1; +latch origid destid weight seq linkid +1 4 1 NULL 0 4 +1 4 1 1 1 3 +1 4 1 1 2 1 +SELECT * FROM graph WHERE latch='1' AND origid=1 AND destid=5; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch='1' AND origid=1 AND destid=666; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch='1' AND origid=5 AND destid=7; +latch origid destid weight seq linkid +1 5 7 NULL 0 5 +1 5 7 1 1 7 +SELECT * FROM graph WHERE latch='1' AND origid=7 AND destid=5; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch='1' AND origid=10 AND destid=11; +latch origid destid weight seq linkid +1 10 11 NULL 0 10 +1 10 11 1 1 11 +SELECT * FROM graph WHERE latch='1' AND origid=10 AND destid=12; +latch origid destid weight seq linkid +1 10 12 NULL 0 10 +1 10 12 1 1 11 +1 10 12 1 2 12 +SELECT * FROM graph WHERE latch='1' AND origid=11 AND destid=10; +latch origid destid weight seq linkid +1 11 10 NULL 0 11 +1 11 10 1 1 12 +1 11 10 1 2 10 +SELECT * FROM graph WHERE latch='1' AND origid=11 AND destid=12; +latch origid destid weight seq linkid +1 11 12 NULL 0 11 +1 11 12 1 1 12 +SELECT * FROM graph WHERE latch='1' AND origid=12 AND destid=10; +latch origid destid weight seq linkid +1 12 10 NULL 0 12 +1 12 10 1 1 10 +SELECT * FROM graph WHERE latch='1' AND origid=12 AND destid=11; +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 2 4 4 +1 1 NULL 1 3 3 +1 1 NULL 1 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 3 4 4 +1 2 NULL 2 3 3 +1 2 NULL 1 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 2 4 2 +1 3 NULL 1 3 4 +1 3 NULL 1 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 3 4 2 +1 4 NULL 2 3 1 +1 4 NULL 1 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 1 3 7 +1 5 NULL 1 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 2 3 7 +1 6 NULL 1 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 +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 2 3 12 +1 10 NULL 1 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 2 3 10 +1 11 NULL 1 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 2 3 11 +1 12 NULL 1 2 10 +1 12 NULL 0 1 12 +SELECT * FROM graph WHERE latch='1' AND origid=666; +latch origid destid weight seq linkid +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 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 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 2 3 6 +1 NULL 7 1 2 5 +1 NULL 7 0 1 7 +SELECT * FROM graph WHERE latch='1' AND destid=8; +latch origid destid weight seq linkid +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 11 +1 NULL 10 1 2 12 +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 12 +1 NULL 11 1 2 10 +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 10 +1 NULL 12 1 2 11 +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); +SELECT * FROM graph WHERE latch='dijkstras' AND origid=10 AND destid=13; +latch origid destid weight seq linkid +dijkstras 10 13 NULL 0 10 +dijkstras 10 13 1 1 11 +dijkstras 10 13 1 2 13 +DELETE FROM graph_base where from_id=10 and to_id=11; +INSERT INTO graph_base(from_id, to_id) VALUES (10,15); +INSERT INTO graph_base(from_id, to_id) VALUES (15,13); +SELECT * FROM graph WHERE latch='dijkstras' AND origid=10 AND destid=13; +latch origid destid weight seq linkid +dijkstras 10 13 NULL 0 10 +dijkstras 10 13 1 1 14 +dijkstras 10 13 1 2 13 +INSERT INTO graph_base(from_id, to_id) VALUES (10,11); +SELECT * FROM graph WHERE latch='dijkstras' AND origid=10 AND destid=13; +latch origid destid weight seq linkid +dijkstras 10 13 NULL 0 10 +dijkstras 10 13 1 1 11 +dijkstras 10 13 1 2 13 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=1; +latch origid destid weight seq linkid +dijkstras 1 NULL 2 4 4 +dijkstras 1 NULL 1 3 3 +dijkstras 1 NULL 1 2 2 +dijkstras 1 NULL 0 1 1 +INSERT INTO graph_base(from_id, to_id) VALUES (21,22); +SELECT * FROM graph WHERE latch='dijkstras' AND origid=21; +latch origid destid weight seq linkid +dijkstras 21 NULL 1 2 22 +dijkstras 21 NULL 0 1 21 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=22; +latch origid destid weight seq linkid +dijkstras 22 NULL 0 1 22 +INSERT INTO graph_base(from_id, to_id) VALUES (4,17); +SELECT * FROM graph WHERE latch='dijkstras' AND origid=1; +latch origid destid weight seq linkid +dijkstras 1 NULL 3 5 17 +dijkstras 1 NULL 2 4 4 +dijkstras 1 NULL 1 3 3 +dijkstras 1 NULL 1 2 2 +dijkstras 1 NULL 0 1 1 +INSERT INTO graph_base(from_id, to_id) VALUES (4,16); +SELECT * FROM graph WHERE latch='dijkstras' AND origid=1; +latch origid destid weight seq linkid +dijkstras 1 NULL 3 6 17 +dijkstras 1 NULL 3 5 16 +dijkstras 1 NULL 2 4 4 +dijkstras 1 NULL 1 3 3 +dijkstras 1 NULL 1 2 2 +dijkstras 1 NULL 0 1 1 +INSERT INTO graph_base(from_id, to_id) VALUES (17,18); +SELECT * FROM graph WHERE latch='dijkstras' AND origid=1; +latch origid destid weight seq linkid +dijkstras 1 NULL 4 7 18 +dijkstras 1 NULL 3 6 17 +dijkstras 1 NULL 3 5 16 +dijkstras 1 NULL 2 4 4 +dijkstras 1 NULL 1 3 3 +dijkstras 1 NULL 1 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 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 +DELETE FROM graph_base WHERE from_id=5; +DELETE FROM graph_base WHERE from_id=3 AND to_id=5; +# which means there is a path in one direction only 1>3>4>6 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=1 AND destid=6; +latch origid destid weight seq linkid +dijkstras 1 6 NULL 0 1 +dijkstras 1 6 1 1 3 +dijkstras 1 6 1 2 4 +dijkstras 1 6 1 3 6 +# but not 6>4>3>1 (so no result) +SELECT * FROM graph WHERE latch='dijkstras' AND origid=6 AND destid=1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch='1' AND origid=1 AND destid=6; +latch origid destid weight seq linkid +1 1 6 NULL 0 1 +1 1 6 1 1 3 +1 1 6 1 2 4 +1 1 6 1 3 6 +SELECT * FROM graph WHERE latch='1' AND origid=6 AND destid=1; +latch origid destid weight seq linkid +DELETE FROM graph_base; +FLUSH TABLES; +TRUNCATE TABLE graph_base; +DROP TABLE graph_base; +DROP TABLE graph; diff --git a/storage/oqgraph/mysql-test/oqgraph/general-innodb.test b/storage/oqgraph/mysql-test/oqgraph/general-innodb.test new file mode 100644 index 00000000..4534eb41 --- /dev/null +++ b/storage/oqgraph/mysql-test/oqgraph/general-innodb.test @@ -0,0 +1,4 @@ +# This is a maintainer generated file. Generated at Wednesday 5 February 22:26:12 CST 2014. +-- source include/have_innodb.inc +--let $oqgraph_use_table_type= innodb +--source general.inc diff --git a/storage/oqgraph/mysql-test/oqgraph/general.inc b/storage/oqgraph/mysql-test/oqgraph/general.inc new file mode 100644 index 00000000..48960f7c --- /dev/null +++ b/storage/oqgraph/mysql-test/oqgraph/general.inc @@ -0,0 +1,730 @@ +--disable_warnings +DROP TABLE IF EXISTS graph_base; +DROP TABLE IF EXISTS graph; +DROP TABLE IF EXISTS graph2; +--enable_warnings + +--echo Performing OQGraph General test suite for ENGINE=$oqgraph_use_table_type + +# Create the backing store +eval CREATE TABLE graph_base ( + from_id INT UNSIGNED NOT NULL, + to_id INT UNSIGNED NOT NULL, + PRIMARY KEY (from_id,to_id), + INDEX (to_id) + ) ENGINE= $oqgraph_use_table_type ; + +# Since late June 2014 OQGraph supports 'assisted discovery' as per https://mariadb.atlassian.net/browse/MDEV-5871 +CREATE TABLE graph ENGINE=OQGRAPH DATA_TABLE='graph_base' ORIGID='from_id', DESTID='to_id'; + +# Regression for MDEV-5891 +select * from graph; + +#-- +#-- ASCII art graph of this test data +#-- +-->(2) +#-- ( )<---+ +#-- (1) +#-- ( )<---+ +#-- +-->(3)<------->(4) +#-- +#-- (7)<----------(5)<--------->(6) (9) +#-- +#-- +--->(11) +#-- | | +#-- (10) | +#-- ^ v +#-- +----(12) + +INSERT INTO graph_base(from_id, to_id) VALUES (1,2), (2,1); +INSERT INTO graph_base(from_id, to_id) VALUES (1,3), (3,1); +INSERT INTO graph_base(from_id, to_id) VALUES (3,4), (4,3); +INSERT INTO graph_base(from_id, to_id) VALUES (5,6), (6,5); + +#-- extra unidirected node +INSERT INTO graph_base(from_id, to_id) VALUES (5,7); + +#-- isolated node with no loop - disallowed +#-- so origid 8 below should return an empty rowset +#-- INSERT INTO graph_base(from_id, to_id) VALUES (8,NULL); + +#-- isolated node with a (undirected) loop +#-- we have no way of representing a directed loop on an isolated node, is this valid in pure graph theory? +INSERT INTO graph_base(from_id, to_id) VALUES (9,9); + +#-- directed _cyclic_ graph triangle? +INSERT INTO graph_base(from_id, to_id) VALUES (10,11); +INSERT INTO graph_base(from_id, to_id) VALUES (11,12); +INSERT INTO graph_base(from_id, to_id) VALUES (12,10); + +--echo # Return all edges +#-- we note that when weight is NULL it defaults to 1 +SELECT * FROM graph; +--echo # Currently count should be 13 +SELECT count(*) FROM graph; + +--echo # Return all edges when latch is NULL - this is different to latch='' and same as no where clause +SELECT * FROM graph where latch is NULL; + +--echo # Return all vertices, and subsets of vertices +SELECT * FROM graph where latch=''; +SELECT * FROM graph where latch='0'; + +--echo # Currently count should be 11 + +SELECT count(*) FROM graph where latch=''; +#-- get a subset of vertices +SELECT * FROM graph where latch='' and linkid = 2; +SELECT * FROM graph where latch='' and (linkid > 2 and linkid < 6); +SELECT * FROM graph where latch='' and linkid = NULL; +SELECT * FROM graph where latch='' and linkid = 666; + +#-- Query out-edges for vertex (no_search AND origid=N) +SELECT origid as `from`, linkid as `to` FROM graph where latch='' and origid = 1; +SELECT origid as `from`, linkid as `to` FROM graph where latch='' and origid = 2; +SELECT origid as `from`, linkid as `to` FROM graph where latch='' and origid = 4; +SELECT origid as `from`, linkid as `to` FROM graph where latch='' and origid = 9; +SELECT origid as `from`, linkid as `to` FROM graph where latch='' and origid = 10; +SELECT origid as `from`, linkid as `to` FROM graph where latch='' and origid = NULL; +SELECT origid as `from`, linkid as `to` FROM graph where latch='' and origid = 666; + +#-- Query in-edges for vertex (no_search AND destid=N) +#-- linkid will have the other end +SELECT linkid as `from`, destid as `to` FROM graph where latch='' and destid = 1; +SELECT linkid as `from`, destid as `to` FROM graph where latch='' and destid = 2; +SELECT linkid as `from`, destid as `to` FROM graph where latch='' and destid = 4; +SELECT linkid as `from`, destid as `to` FROM graph where latch='' and destid = 9; +SELECT linkid as `from`, destid as `to` FROM graph where latch='' and destid = 10; +SELECT linkid as `from`, destid as `to` FROM graph where latch='' and destid = NULL; +SELECT linkid as `from`, destid as `to` FROM graph where latch='' and destid = 666; + +# The following returns a result that makes no sense... +#-- what happens when we combined orig and dest? +#-- Bug https://bugs.launchpad.net/oqgraph/+bug/1195778 +#SELECT * FROM graph where latch='' and origid = 1; +#SELECT * FROM graph where latch='' and destid = 2; +#SELECT * FROM graph where latch='' and origid=1 and destid = 2; + +SELECT * FROM graph where latch='0'; +SELECT count(*) FROM graph where latch='0'; +SELECT * FROM graph where latch='0' and linkid = 2; +SELECT * FROM graph where latch='0' and (linkid > 2 and linkid < 6); +SELECT origid as `from`, linkid as `to` FROM graph where latch='0' and origid = 1; +SELECT origid as `from`, linkid as `to` FROM graph where latch='0' and origid = 2; +SELECT origid as `from`, linkid as `to` FROM graph where latch='0' and origid = 4; +SELECT origid as `from`, linkid as `to` FROM graph where latch='0' and origid = 9; +SELECT origid as `from`, linkid as `to` FROM graph where latch='0' and origid = 10; +SELECT linkid as `from`, destid as `to` FROM graph where latch='0' and destid = 1; +SELECT linkid as `from`, destid as `to` FROM graph where latch='0' and destid = 2; +SELECT linkid as `from`, destid as `to` FROM graph where latch='0' and destid = 4; +SELECT linkid as `from`, destid as `to` FROM graph where latch='0' and destid = 9; +SELECT linkid as `from`, destid as `to` FROM graph where latch='0' and destid = 10; + +--echo # Leaves search tests +#-- We are asking "Are there nodes reachable from origid, from which no other nodes can be reached" +#-- We return a row for each leaf node that is reachable, with its id in 'linkid' +#-- and the weight calculated as "How many _directed_ hops to get there" +#-- If there is no path from origid to another node then there is no row for that linkid +#-- '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 = 'leaves' AND origid = 1; +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 2; +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 3; +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 4; +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 5; +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 6; +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 7; +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 8; +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 9; +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 10; +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 11; +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 12; + +#-- now do it in reverse - using destid find originating vertices +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 1; +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 2; +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 3; +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 4; +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 5; +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 6; +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 7; +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 8; +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 9; +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 10; +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 11; +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 12; + +# Add more leaf nodes +INSERT INTO graph_base(from_id, to_id) VALUES (10,13); +INSERT INTO graph_base(from_id, to_id) VALUES (11,14); +INSERT INTO graph_base(from_id, to_id) VALUES (12,15); + +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 10; +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 11; +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 12; +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 13; +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 14; +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 15; +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 10; +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 11; +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 12; +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 13; +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 14; +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 15; + +DELETE FROM graph_base where from_id=10 and to_id=13; +DELETE FROM graph_base where from_id=11 and to_id=14; +DELETE FROM graph_base where from_id=12 and to_id=15; + +# Add some root nodes +INSERT INTO graph_base(from_id, to_id) VALUES (13,10); +INSERT INTO graph_base(from_id, to_id) VALUES (14,11); +INSERT INTO graph_base(from_id, to_id) VALUES (15,12); +INSERT INTO graph_base(from_id, to_id) VALUES (16,1); + +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 10; +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 11; +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 12; +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 13; +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 14; +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 15; +SELECT * FROM graph WHERE latch = 'leaves' AND origid = 16; +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 10; +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 11; +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 12; +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 13; +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 14; +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 15; +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 1; +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 2; +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 3; +SELECT * FROM graph WHERE latch = 'leaves' AND destid = 4; + +DELETE FROM graph_base where from_id=13 and to_id=10; +DELETE FROM graph_base where from_id=14 and to_id=11; +DELETE FROM graph_base where from_id=15 and to_id=12; +DELETE FROM graph_base where from_id=16 and to_id=1; + +# path queries yield no result with "leaves" +SELECT * FROM graph WHERE latch='leaves' AND origid=1 AND destid=2; +SELECT * FROM graph WHERE latch='leaves' AND origid=1 AND destid=3; +SELECT * FROM graph WHERE latch='leaves' AND origid=1 AND destid=4; +SELECT * FROM graph WHERE latch='leaves' AND origid=6 AND destid=7; +SELECT * FROM graph WHERE latch='leaves' AND origid=10 AND destid=11; +SELECT * FROM graph WHERE latch='leaves' AND origid=10 AND destid=12; + +--echo # Breadth-first search tests +#-- We are asking "Is there a path from node 'origid' to (all) other nodes?" +#-- We return a row for each other node that is reachable, with its id in 'linkid' +#-- and the weight calculated as "How many _directed_ hops to get there" +#-- If there is no path from origid to another node then there is no row for that linkid +#-- 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; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 4; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 5; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 6; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 7; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 8; # <-- note, should return nothing +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 9; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 10; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 11; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 12; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 666; # <-- note, should return nothing +#-- The above results can then be filtered by weight, so the results should be a subset for the corresponding origid above +#-- so effectively, `AND weight=1` returns the neighbours of origid in linkid +#<----- orig test harness - still returns (breadth_first 1 NULL 1 3 3), (breadth_first 1 NULL 1 2 2) +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 1 AND weight = 1; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 2 AND weight = 1; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 3 AND weight = 1; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 4 AND weight = 1; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 5 AND weight = 1; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 6 AND weight = 1; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 7 AND weight = 1; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 8 AND weight = 1; # <-- note, should return nothing +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 9 AND weight = 1; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 10 AND weight = 1; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 11 AND weight = 1; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 12 AND weight = 1; +#-- so effectively, `count(... AND weight=1)` returns the number of _reachable_ immediate neighbours +#-- included because it allows human to quickly eyeball against the visual ASCII graph for correctness... +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 1 AND weight = 1; +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 2 AND weight = 1; +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 3 AND weight = 1; +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 4 AND weight = 1; +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 5 AND weight = 1; +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 6 AND weight = 1; +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 7 AND weight = 1; +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 8 AND weight = 1; # <-- note, should return nothing +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 9 AND weight = 1; +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 10 AND weight = 1; +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 11 AND weight = 1; +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 12 AND weight = 1; +#-- so effectively, `AND weight=2` returns the second-level neighbours of origid in linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 1 AND weight = 2; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 2 AND weight = 2; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 3 AND weight = 2; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 4 AND weight = 2; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 5 AND weight = 2; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 6 AND weight = 2; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 7 AND weight = 2; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 8 AND weight = 2; # <-- note, should return nothing +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 9 AND weight = 2; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 10 AND weight = 2; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 11 AND weight = 2; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 12 AND weight = 2; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 1 AND weight = 3; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 2 AND weight = 3; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 3 AND weight = 3; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 4 AND weight = 3; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 5 AND weight = 3; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 6 AND weight = 3; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 7 AND weight = 3; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 8 AND weight = 3; # <-- note, should return nothing +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 9 AND weight = 3; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 10 AND weight = 3; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 11 AND weight = 3; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 12 AND weight = 3; + +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 1 AND (weight = 1 or weight = 2); +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 2 AND (weight = 1 or weight = 2); +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 3 AND (weight = 1 or weight = 2); +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 4 AND (weight = 1 or weight = 2); +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 5 AND (weight = 1 or weight = 2); +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 6 AND (weight = 1 or weight = 2); +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 7 AND (weight = 1 or weight = 2); +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 8 AND (weight = 1 or weight = 2); # <-- note, should return nothing +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 9 AND (weight = 1 or weight = 2); +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 10 AND (weight = 1 or weight = 2); +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 11 AND (weight = 1 or weight = 2); +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 12 AND (weight = 1 or weight = 2); + +#-- now do it in reverse - using destid find originating vertices +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 1; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 2; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 3; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 4; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 5; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 6; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 7; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 8; # <-- note, should return nothing +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 9; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 10; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 11; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 12; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 1 and weight = 1; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 2 and weight = 1; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 3 and weight = 1; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 4 and weight = 1; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 5 and weight = 1; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 6 and weight = 1; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 7 and weight = 1; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 8 and weight = 1; # <-- note, should return nothing +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 9 and weight = 1; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 10 and weight = 1; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 11 and weight = 1; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 12 and weight = 1; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 1 and weight = 2; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 2 and weight = 2; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 3 and weight = 2; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 4 and weight = 2; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 5 and weight = 2; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 6 and weight = 2; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 7 and weight = 2; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 8 and weight = 2; # <-- note, should return nothing +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 9 and weight = 2; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 10 and weight = 2; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 11 and weight = 2; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 12 and weight = 2; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 1 and weight = 3; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 2 and weight = 3; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 3 and weight = 3; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 4 and weight = 3; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 5 and weight = 3; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 6 and weight = 3; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 7 and weight = 3; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 8 and weight = 3; # <-- note, should return nothing +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 9 and weight = 3; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 10 and weight = 3; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 11 and weight = 3; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 12 and weight = 3; + +#-- These return empty sets - origid or destid must be specified and non null to get a result set +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = NULL; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = NULL; +SELECT * FROM graph WHERE latch = 'breadth_first' AND weight = 1; +SELECT * FROM graph WHERE latch = 'breadth_first'; + +#-- Repeat the above with legacy string +SELECT * FROM graph WHERE latch = '2' AND origid = 1; +SELECT * FROM graph WHERE latch = '2' AND origid = 2; +SELECT * FROM graph WHERE latch = '2' AND origid = 3; +SELECT * FROM graph WHERE latch = '2' AND origid = 4; +SELECT * FROM graph WHERE latch = '2' AND origid = 5; +SELECT * FROM graph WHERE latch = '2' AND origid = 6; +SELECT * FROM graph WHERE latch = '2' AND origid = 7; +SELECT * FROM graph WHERE latch = '2' AND origid = 8; # <-- note, should return nothing +SELECT * FROM graph WHERE latch = '2' AND origid = 9; +SELECT * FROM graph WHERE latch = '2' AND origid = 10; +SELECT * FROM graph WHERE latch = '2' AND origid = 11; +SELECT * FROM graph WHERE latch = '2' AND origid = 12; +SELECT * FROM graph WHERE latch = '2' AND origid = 666; # <-- note, should return nothing +SELECT * FROM graph WHERE latch = '2' AND origid = 1 AND weight = 1; +SELECT * FROM graph WHERE latch = '2' AND origid = 2 AND weight = 1; +SELECT * FROM graph WHERE latch = '2' AND origid = 3 AND weight = 1; +SELECT * FROM graph WHERE latch = '2' AND origid = 4 AND weight = 1; +SELECT * FROM graph WHERE latch = '2' AND origid = 5 AND weight = 1; +SELECT * FROM graph WHERE latch = '2' AND origid = 6 AND weight = 1; +SELECT * FROM graph WHERE latch = '2' AND origid = 7 AND weight = 1; +SELECT * FROM graph WHERE latch = '2' AND origid = 8 AND weight = 1; # <-- note, should return nothing +SELECT * FROM graph WHERE latch = '2' AND origid = 9 AND weight = 1; +SELECT * FROM graph WHERE latch = '2' AND origid = 10 AND weight = 1; +SELECT * FROM graph WHERE latch = '2' AND origid = 11 AND weight = 1; +SELECT * FROM graph WHERE latch = '2' AND origid = 12 AND weight = 1; +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 1 AND weight = 1; +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 2 AND weight = 1; +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 3 AND weight = 1; +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 4 AND weight = 1; +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 5 AND weight = 1; +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 6 AND weight = 1; +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 7 AND weight = 1; +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 8 AND weight = 1; # <-- note, should return nothing +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 9 AND weight = 1; +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 10 AND weight = 1; +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 11 AND weight = 1; +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 12 AND weight = 1; +SELECT * FROM graph WHERE latch = '2' AND origid = 1 AND weight = 2; +SELECT * FROM graph WHERE latch = '2' AND origid = 2 AND weight = 2; +SELECT * FROM graph WHERE latch = '2' AND origid = 3 AND weight = 2; +SELECT * FROM graph WHERE latch = '2' AND origid = 4 AND weight = 2; +SELECT * FROM graph WHERE latch = '2' AND origid = 5 AND weight = 2; +SELECT * FROM graph WHERE latch = '2' AND origid = 6 AND weight = 2; +SELECT * FROM graph WHERE latch = '2' AND origid = 7 AND weight = 2; +SELECT * FROM graph WHERE latch = '2' AND origid = 8 AND weight = 2; # <-- note, should return nothing +SELECT * FROM graph WHERE latch = '2' AND origid = 9 AND weight = 2; +SELECT * FROM graph WHERE latch = '2' AND origid = 10 AND weight = 2; +SELECT * FROM graph WHERE latch = '2' AND origid = 11 AND weight = 2; +SELECT * FROM graph WHERE latch = '2' AND origid = 12 AND weight = 2; +SELECT * FROM graph WHERE latch = '2' AND origid = 1 AND weight = 3; +SELECT * FROM graph WHERE latch = '2' AND origid = 2 AND weight = 3; +SELECT * FROM graph WHERE latch = '2' AND origid = 3 AND weight = 3; +SELECT * FROM graph WHERE latch = '2' AND origid = 4 AND weight = 3; +SELECT * FROM graph WHERE latch = '2' AND origid = 5 AND weight = 3; +SELECT * FROM graph WHERE latch = '2' AND origid = 6 AND weight = 3; +SELECT * FROM graph WHERE latch = '2' AND origid = 7 AND weight = 3; +SELECT * FROM graph WHERE latch = '2' AND origid = 8 AND weight = 3; # <-- note, should return nothing +SELECT * FROM graph WHERE latch = '2' AND origid = 9 AND weight = 3; +SELECT * FROM graph WHERE latch = '2' AND origid = 10 AND weight = 3; +SELECT * FROM graph WHERE latch = '2' AND origid = 11 AND weight = 3; +SELECT * FROM graph WHERE latch = '2' AND origid = 12 AND weight = 3; + +SELECT * FROM graph WHERE latch = '2' AND origid = 1 AND (weight = 1 or weight = 2); +SELECT * FROM graph WHERE latch = '2' AND origid = 2 AND (weight = 1 or weight = 2); +SELECT * FROM graph WHERE latch = '2' AND origid = 3 AND (weight = 1 or weight = 2); +SELECT * FROM graph WHERE latch = '2' AND origid = 4 AND (weight = 1 or weight = 2); +SELECT * FROM graph WHERE latch = '2' AND origid = 5 AND (weight = 1 or weight = 2); +SELECT * FROM graph WHERE latch = '2' AND origid = 6 AND (weight = 1 or weight = 2); +SELECT * FROM graph WHERE latch = '2' AND origid = 7 AND (weight = 1 or weight = 2); +SELECT * FROM graph WHERE latch = '2' AND origid = 8 AND (weight = 1 or weight = 2); # <-- note, should return nothing +SELECT * FROM graph WHERE latch = '2' AND origid = 9 AND (weight = 1 or weight = 2); +SELECT * FROM graph WHERE latch = '2' AND origid = 10 AND (weight = 1 or weight = 2); +SELECT * FROM graph WHERE latch = '2' AND origid = 11 AND (weight = 1 or weight = 2); +SELECT * FROM graph WHERE latch = '2' AND origid = 12 AND (weight = 1 or weight = 2); + +SELECT * FROM graph WHERE latch = '2' AND destid = 1; +SELECT * FROM graph WHERE latch = '2' AND destid = 2; +SELECT * FROM graph WHERE latch = '2' AND destid = 3; +SELECT * FROM graph WHERE latch = '2' AND destid = 4; +SELECT * FROM graph WHERE latch = '2' AND destid = 5; +SELECT * FROM graph WHERE latch = '2' AND destid = 6; +SELECT * FROM graph WHERE latch = '2' AND destid = 7; +SELECT * FROM graph WHERE latch = '2' AND destid = 8; # <-- note, should return nothing +SELECT * FROM graph WHERE latch = '2' AND destid = 9; +SELECT * FROM graph WHERE latch = '2' AND destid = 10; +SELECT * FROM graph WHERE latch = '2' AND destid = 11; +SELECT * FROM graph WHERE latch = '2' AND destid = 12; +SELECT * FROM graph WHERE latch = '2' AND destid = 1 and weight = 1; +SELECT * FROM graph WHERE latch = '2' AND destid = 2 and weight = 1; +SELECT * FROM graph WHERE latch = '2' AND destid = 3 and weight = 1; +SELECT * FROM graph WHERE latch = '2' AND destid = 4 and weight = 1; +SELECT * FROM graph WHERE latch = '2' AND destid = 5 and weight = 1; +SELECT * FROM graph WHERE latch = '2' AND destid = 6 and weight = 1; +SELECT * FROM graph WHERE latch = '2' AND destid = 7 and weight = 1; +SELECT * FROM graph WHERE latch = '2' AND destid = 8 and weight = 1; # <-- note, should return nothing +SELECT * FROM graph WHERE latch = '2' AND destid = 9 and weight = 1; +SELECT * FROM graph WHERE latch = '2' AND destid = 10 and weight = 1; +SELECT * FROM graph WHERE latch = '2' AND destid = 11 and weight = 1; +SELECT * FROM graph WHERE latch = '2' AND destid = 12 and weight = 1; +SELECT * FROM graph WHERE latch = '2' AND destid = 1 and weight = 2; +SELECT * FROM graph WHERE latch = '2' AND destid = 2 and weight = 2; +SELECT * FROM graph WHERE latch = '2' AND destid = 3 and weight = 2; +SELECT * FROM graph WHERE latch = '2' AND destid = 4 and weight = 2; +SELECT * FROM graph WHERE latch = '2' AND destid = 5 and weight = 2; +SELECT * FROM graph WHERE latch = '2' AND destid = 6 and weight = 2; +SELECT * FROM graph WHERE latch = '2' AND destid = 7 and weight = 2; +SELECT * FROM graph WHERE latch = '2' AND destid = 8 and weight = 2; # <-- note, should return nothing +SELECT * FROM graph WHERE latch = '2' AND destid = 9 and weight = 2; +SELECT * FROM graph WHERE latch = '2' AND destid = 10 and weight = 2; +SELECT * FROM graph WHERE latch = '2' AND destid = 11 and weight = 2; +SELECT * FROM graph WHERE latch = '2' AND destid = 12 and weight = 2; +SELECT * FROM graph WHERE latch = '2' AND destid = 1 and weight = 3; +SELECT * FROM graph WHERE latch = '2' AND destid = 2 and weight = 3; +SELECT * FROM graph WHERE latch = '2' AND destid = 3 and weight = 3; +SELECT * FROM graph WHERE latch = '2' AND destid = 4 and weight = 3; +SELECT * FROM graph WHERE latch = '2' AND destid = 5 and weight = 3; +SELECT * FROM graph WHERE latch = '2' AND destid = 6 and weight = 3; +SELECT * FROM graph WHERE latch = '2' AND destid = 7 and weight = 3; +SELECT * FROM graph WHERE latch = '2' AND destid = 8 and weight = 3; # <-- note, should return nothing +SELECT * FROM graph WHERE latch = '2' AND destid = 9 and weight = 3; +SELECT * FROM graph WHERE latch = '2' AND destid = 10 and weight = 3; +SELECT * FROM graph WHERE latch = '2' AND destid = 11 and weight = 3; +SELECT * FROM graph WHERE latch = '2' AND destid = 12 and weight = 3; + +#-- These return empty sets - origid must be specified and non null to get a result set +SELECT * FROM graph WHERE latch = '2' AND origid = NULL; +SELECT * FROM graph WHERE latch = '2' AND destid = NULL; +SELECT * FROM graph WHERE latch = '2' AND weight = 1; +SELECT * FROM graph WHERE latch = '2'; + + +--echo # Dijkstras algorithm tests +#-- We ask 'What is the shortest path (if any) between 'origid' and 'destid' +#-- This returns the number of directed hops +1 (for the starting node) +#-- 'weight' is NULL for the starting point, or 1 +#-- 'linkid' is the way point id +#-- 'seq' is the distance of the waypoint from the start (counting from zero) +#-- the default order returned is waypoints out from the start +#-- zero hop (1 row) +SELECT * FROM graph WHERE latch='dijkstras' AND origid=1 AND destid=1; +#-- one hop +SELECT * FROM graph WHERE latch='dijkstras' AND origid=1 AND destid=2; +#-- one hop in reverse +SELECT * FROM graph WHERE latch='dijkstras' AND origid=2 AND destid=1; +#-- two hops (via 3) +SELECT * FROM graph WHERE latch='dijkstras' AND origid=1 AND destid=4; +#-- two hops in reverse direction +SELECT * FROM graph WHERE latch='dijkstras' AND origid=4 AND destid=1; +#-- no result (no connection) +SELECT * FROM graph WHERE latch='dijkstras' AND origid=1 AND destid=5; +#-- no result (no destination exists) +SELECT * FROM graph WHERE latch='dijkstras' AND origid=1 AND destid=666; + +#-- one hop on a unidirected link +SELECT * FROM graph WHERE latch='dijkstras' AND origid=5 AND destid=7; +#-- zero hop in reverse direction on a unidirected link +SELECT * FROM graph WHERE latch='dijkstras' AND origid=7 AND destid=5; + +#-- Trickery - what about the cyclic loop? +SELECT * FROM graph WHERE latch='dijkstras' AND origid=10 AND destid=11; +SELECT * FROM graph WHERE latch='dijkstras' AND origid=10 AND destid=12; +SELECT * FROM graph WHERE latch='dijkstras' AND origid=11 AND destid=10; +SELECT * FROM graph WHERE latch='dijkstras' AND origid=11 AND destid=12; +SELECT * FROM graph WHERE latch='dijkstras' AND origid=12 AND destid=10; +SELECT * FROM graph WHERE latch='dijkstras' AND origid=12 AND destid=11; + +#-- reachable vertices +SELECT * FROM graph WHERE latch='dijkstras' AND origid=1; +SELECT * FROM graph WHERE latch='dijkstras' AND origid=2; +SELECT * FROM graph WHERE latch='dijkstras' AND origid=3; +SELECT * FROM graph WHERE latch='dijkstras' AND origid=4; +SELECT * FROM graph WHERE latch='dijkstras' AND origid=5; +SELECT * FROM graph WHERE latch='dijkstras' AND origid=6; +SELECT * FROM graph WHERE latch='dijkstras' AND origid=7; +SELECT * FROM graph WHERE latch='dijkstras' AND origid=8; # <-- note, should return nothing +SELECT * FROM graph WHERE latch='dijkstras' AND origid=9; +SELECT * FROM graph WHERE latch='dijkstras' AND origid=10; +SELECT * FROM graph WHERE latch='dijkstras' AND origid=11; +SELECT * FROM graph WHERE latch='dijkstras' AND origid=12; +SELECT * FROM graph WHERE latch='dijkstras' AND origid=666; # <-- note, should return nothing + +#-- originating vertices +SELECT * FROM graph WHERE latch='dijkstras' AND destid=1; +SELECT * FROM graph WHERE latch='dijkstras' AND destid=2; +SELECT * FROM graph WHERE latch='dijkstras' AND destid=3; +SELECT * FROM graph WHERE latch='dijkstras' AND destid=4; +SELECT * FROM graph WHERE latch='dijkstras' AND destid=5; +SELECT * FROM graph WHERE latch='dijkstras' AND destid=6; +SELECT * FROM graph WHERE latch='dijkstras' AND destid=7; +SELECT * FROM graph WHERE latch='dijkstras' AND destid=8; # <-- note, should return nothing +SELECT * FROM graph WHERE latch='dijkstras' AND destid=9; +SELECT * FROM graph WHERE latch='dijkstras' AND destid=10; +SELECT * FROM graph WHERE latch='dijkstras' AND destid=11; +SELECT * FROM graph WHERE latch='dijkstras' AND destid=12; + +--echo # legacy string number +SELECT * FROM graph WHERE latch='1' AND origid=1 AND destid=1; +SELECT * FROM graph WHERE latch='1' AND origid=1 AND destid=2; +SELECT * FROM graph WHERE latch='1' AND origid=2 AND destid=1; +SELECT * FROM graph WHERE latch='1' AND origid=1 AND destid=4; +SELECT * FROM graph WHERE latch='1' AND origid=4 AND destid=1; +SELECT * FROM graph WHERE latch='1' AND origid=1 AND destid=5; +SELECT * FROM graph WHERE latch='1' AND origid=1 AND destid=666; # <-- note, should return nothing +SELECT * FROM graph WHERE latch='1' AND origid=5 AND destid=7; +SELECT * FROM graph WHERE latch='1' AND origid=7 AND destid=5; +SELECT * FROM graph WHERE latch='1' AND origid=10 AND destid=11; +SELECT * FROM graph WHERE latch='1' AND origid=10 AND destid=12; +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; +SELECT * FROM graph WHERE latch='1' AND origid=8; # <-- note, should return nothing +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; +SELECT * FROM graph WHERE latch='1' AND origid=666; # <-- note, should return nothing +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; +SELECT * FROM graph WHERE latch='1' AND destid=8; # <-- note, should return nothing +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? +#-- +#-- +#-- +--->(14)----------+ +#-- | v +#-- | +--->(11)---->(13) +#-- | | | +#-- +-(10) | +#-- ^ v +#-- +----(12) +#-- +#-- We note it chooses 10,11,13 but will it always? +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); +SELECT * FROM graph WHERE latch='dijkstras' AND origid=10 AND destid=13; +DELETE FROM graph_base where from_id=10 and to_id=11; +INSERT INTO graph_base(from_id, to_id) VALUES (10,15); +INSERT INTO graph_base(from_id, to_id) VALUES (15,13); +SELECT * FROM graph WHERE latch='dijkstras' AND origid=10 AND destid=13; +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; + +#-- 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; +SELECT * FROM graph WHERE latch='dijkstras' AND origid=22; +INSERT INTO graph_base(from_id, to_id) VALUES (4,17); +SELECT * FROM graph WHERE latch='dijkstras' AND origid=1; +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; +SELECT * FROM graph WHERE latch='dijkstras' AND destid=1; + +--echo # Now we add a connection from 4->6 +INSERT INTO graph_base (from_id,to_id) VALUES (4,6); + +--echo # And delete all references to node 5 +DELETE FROM graph_base WHERE from_id=5; +DELETE FROM graph_base WHERE from_id=3 AND to_id=5; + +--echo # which means there is a path in one direction only 1>3>4>6 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=1 AND destid=6; +--echo # but not 6>4>3>1 (so no result) +SELECT * FROM graph WHERE latch='dijkstras' AND origid=6 AND destid=1; + +SELECT * FROM graph WHERE latch='1' AND origid=1 AND destid=6; +SELECT * FROM graph WHERE latch='1' AND origid=6 AND destid=1; + + +DELETE FROM graph_base; +FLUSH TABLES; +TRUNCATE TABLE graph_base; + +DROP TABLE graph_base; +DROP TABLE graph; + +#-- Reminder - the basic spec is at http://openquery.com/graph/doc +#-- Query edges stored in graph engine (latch=NULL) +#-- SELECT * FROM foo; +#-- Results: +#-- vertex id for origin of edge in origid column. +#-- vertex id for destination of edge in destid column. +#-- weight of edge in weight column. +#-- Essentially this returns the values (origid,destid pairs with optional weight) you put in, in this mode OQGRAPH looks very close to a real table. But it also does nothing special, it's just store/retrieve for those columns. The other columns will be returned as NULL. +#-- +#-- Query vertices stored in graph engine (latch=0) +#-- SELECT * FROM foo WHERE latch = 0; +#-- Results: +#-- vertex id in linkid column +#-- +#-- Query out-edges for vertex (latch=0 AND origid=N) +#-- SELECT * FROM foo WHERE latch = 0 AND origid = 2; +#-- Results: +#-- vertex id in linkid column +#-- edge weight in weight column +#-- +#-- Query in-edges for vertex (latch=0 AND destid=N) +#-- SELECT * FROM foo WHERE latch = 0 AND destid = 6; +#-- Results: +#-- vertex id in linkid column +#-- edge weight in weight column +#-- +#-- Dijkstra's shortest path algorithm (latch=1) +#-- Find shortest path: +#-- SELECT * FROM foo WHERE latch = 1 AND origid = 1 AND destid = 6; +#-- Results: +#-- latch, origid, destid are same as input. +#-- vertex id of the current step in linkid column. +#-- weight of traversed edge in weight column. +#-- step counter in seq column, so you can sort and use the result (starting at step 0). +#-- Example: SELECT GROUP_CONCAT(linkid ORDER BY seq) ... +#-- +#-- Find reachable vertices: +#-- SELECT * FROM foo WHERE latch = 1 AND origid = 1; +#-- Results: +#-- latch, origid, destid are same as input. +#-- vertex id in linkid column. +#-- aggregate of weights in weight column. +#-- +#-- Find originating vertices: +#-- SELECT * FROM foo WHERE latch = 1 AND destid = 6; +#-- Results: +#-- latch, origid, destid are same as input. +#-- vertex id in linkid column. +#-- aggregate of weights in weight column. +#-- +#-- Breadth-first search (latch=2, assumes that each vertex is weight 1) +#-- Find shortest path: +#-- SELECT * FROM foo WHERE latch = 2 AND origid = 1 AND destid = 6; +#-- Results: +#-- vertex id in linkid column. +#-- weight column = 1 for each hop. +#-- +#-- Find reachable vertices: +#-- SELECT * FROM foo WHERE latch = 2 AND origid = 1; +#-- Results: +#-- vertex id in linkid column. +#-- computed number of hops in weight column. +#-- +#-- Find originating vertices: +#-- SELECT * FROM foo WHERE latch = 2 AND destid = 6; +#-- Results: +#-- vertex id in linkid column. +#-- computed number of hops in weight column. + + diff --git a/storage/oqgraph/mysql-test/oqgraph/generate_backing_table_tests_suite.sh b/storage/oqgraph/mysql-test/oqgraph/generate_backing_table_tests_suite.sh new file mode 100755 index 00000000..894607fd --- /dev/null +++ b/storage/oqgraph/mysql-test/oqgraph/generate_backing_table_tests_suite.sh @@ -0,0 +1,52 @@ +#!/bin/bash + +# This is a template fgenerator or repeating an identical suite of tests for each backing table storage engine +# It generates a set of .test files for the following, for example: +# general-myisam.test +# general-memory.test +# general-innodb.test +# (etc) +# +# We generate these files, because as a general rule the coverage should be identical per backing table engine +# but we might want to pick out and re-reun for an individual backing table engine +# otherwise we could use an MTR loop instead. + +# This is intended to be used by a maintainer; i.e. the resulting .test files are still committed to git. + +# Note on known storage engines: +# See https://mariadb.com/kb/en/information-schema-engines-table/ for a full list +# CSV - doesn't work with OQGraph, attempting to create backing table gives 'failed: 1069: Too many keys specified; max 0 keys allowed' +# BLACKHOLE - makes no sense... but we should make sure it doesnt crash +# FEDERATED, ARCHIVE - consider later + +ENGINES="MyISAM MEMORY Aria" + +for ENGINE in $ENGINES ; do + cat > general-$ENGINE.test <<EOF +# This is a maintainer generated file. Generated at `date`. +--let \$oqgraph_use_table_type= $ENGINE +--source general.inc +EOF +done + +# These engines need an extra check to see if thy are compiled +ENGINES2="innodb" +for ENGINE in $ENGINES2 ; do + cat > general-$ENGINE.test <<EOF +# This is a maintainer generated file. Generated at `date`. +-- source include/have_$ENGINE.inc +--let \$oqgraph_use_table_type= $ENGINE +--source general.inc +EOF +done + +# Generate a script to rerun the test suite as well +# Intended to be run from build as ../storage/oqgraph/mysql-test/oqgraph/maintainer-general-record.sh + +MGFILE=maintainer-general-record.sh +echo '#!/bin/sh' > $MGFILE +echo '# This is a maintainer generated file. Generated at '`date`'.' >> $MGFILE +for ENGINE in $ENGINES $ENGINES2 ; do + echo mysql-test/mysql-test-run --record oqgraph.general-$ENGINE >> $MGFILE +done + diff --git a/storage/oqgraph/mysql-test/oqgraph/invalid_operations.result b/storage/oqgraph/mysql-test/oqgraph/invalid_operations.result new file mode 100644 index 00000000..930d65af --- /dev/null +++ b/storage/oqgraph/mysql-test/oqgraph/invalid_operations.result @@ -0,0 +1,43 @@ +DROP TABLE IF EXISTS graph_base; +DROP TABLE IF EXISTS graph; +call mtr.add_suppression("graph_base is open on delete"); +CREATE TABLE graph_base ( +from_id INT UNSIGNED NOT NULL, +to_id INT UNSIGNED NOT NULL, +PRIMARY KEY (from_id,to_id), +INDEX (to_id) +) ENGINE=MyISAM; +CREATE TABLE graph ( +latch VARCHAR(32) NULL, +origid BIGINT UNSIGNED NULL, +destid BIGINT UNSIGNED NULL, +weight DOUBLE NULL, +seq BIGINT UNSIGNED NULL, +linkid BIGINT UNSIGNED NULL, +KEY (latch, origid, destid) USING HASH, +KEY (latch, destid, origid) USING HASH +) ENGINE=OQGRAPH DATA_TABLE='graph_base' ORIGID='from_id', DESTID='to_id'; +INSERT INTO graph_base(from_id, to_id) VALUES (1,2), (2,1); +INSERT INTO graph_base(from_id, to_id) VALUES (3,2), (2,3); +INSERT INTO graph_base(from_id, to_id) VALUES (1,3), (3,1); +insert into graph values (NULL, 1, 2, 3.0, NULL, NULL); +ERROR HY000: Table 'graph' is read only +delete from graph; +ERROR HY000: Table 'graph' is read only +truncate graph; +ERROR HY000: Table 'graph' is read only +update graph set origid=123; +ERROR HY000: Table 'graph' is read only +DROP TABLE graph_base; +DROP TABLE graph; +# +# End of 10.0 tests +# +# +# MDEV-25373 DROP TABLE doesn't raise error while dropping non-existing table in MariaDB 10.5.9 when OQGraph SE is loaded to the server +# +drop table foobar; +ERROR 42S02: Unknown table 'test.foobar' +# +# End of 10.5 tests +# diff --git a/storage/oqgraph/mysql-test/oqgraph/invalid_operations.test b/storage/oqgraph/mysql-test/oqgraph/invalid_operations.test new file mode 100644 index 00000000..24351cc9 --- /dev/null +++ b/storage/oqgraph/mysql-test/oqgraph/invalid_operations.test @@ -0,0 +1,63 @@ +--disable_warnings +DROP TABLE IF EXISTS graph_base; +DROP TABLE IF EXISTS graph; +--enable_warnings + +call mtr.add_suppression("graph_base is open on delete"); + +# Create the backing store +CREATE TABLE graph_base ( + from_id INT UNSIGNED NOT NULL, + to_id INT UNSIGNED NOT NULL, + PRIMARY KEY (from_id,to_id), + INDEX (to_id) + ) ENGINE=MyISAM; + + +CREATE TABLE graph ( + latch VARCHAR(32) NULL, + origid BIGINT UNSIGNED NULL, + destid BIGINT UNSIGNED NULL, + weight DOUBLE NULL, + seq BIGINT UNSIGNED NULL, + linkid BIGINT UNSIGNED NULL, + KEY (latch, origid, destid) USING HASH, + KEY (latch, destid, origid) USING HASH + ) ENGINE=OQGRAPH DATA_TABLE='graph_base' ORIGID='from_id', DESTID='to_id'; + + +INSERT INTO graph_base(from_id, to_id) VALUES (1,2), (2,1); +INSERT INTO graph_base(from_id, to_id) VALUES (3,2), (2,3); +INSERT INTO graph_base(from_id, to_id) VALUES (1,3), (3,1); + +# -- check readonly'ness +--error 1036 +insert into graph values (NULL, 1, 2, 3.0, NULL, NULL); + +--error 1036 +delete from graph; + +--error 1036 +truncate graph; + +# This was hitting bug https://bugs.launchpad.net/oqgraph/+bug/1233113 +--error 1036 +update graph set origid=123; + + +DROP TABLE graph_base; +DROP TABLE graph; + +--echo # +--echo # End of 10.0 tests +--echo # + +--echo # +--echo # MDEV-25373 DROP TABLE doesn't raise error while dropping non-existing table in MariaDB 10.5.9 when OQGraph SE is loaded to the server +--echo # +--error 1051 +drop table foobar; + +--echo # +--echo # End of 10.5 tests +--echo # diff --git a/storage/oqgraph/mysql-test/oqgraph/isnull.result b/storage/oqgraph/mysql-test/oqgraph/isnull.result new file mode 100644 index 00000000..d9af3322 --- /dev/null +++ b/storage/oqgraph/mysql-test/oqgraph/isnull.result @@ -0,0 +1,42 @@ +DROP TABLE IF EXISTS graph_base; +DROP TABLE IF EXISTS graph; +DROP TABLE IF EXISTS graph2; +CREATE TABLE graph_base ( +from_id INT UNSIGNED NOT NULL, +to_id INT UNSIGNED NOT NULL, +PRIMARY KEY (from_id,to_id), +INDEX (to_id) +) ENGINE=MyISAM; +CREATE TABLE graph ( +latch VARCHAR(32) NULL, +origid BIGINT UNSIGNED NULL, +destid BIGINT UNSIGNED NULL, +weight DOUBLE NULL, +seq BIGINT UNSIGNED NULL, +linkid BIGINT UNSIGNED NULL, +KEY (latch, origid, destid) USING HASH, +KEY (latch, destid, origid) USING HASH +) ENGINE=OQGRAPH DATA_TABLE='graph_base' ORIGID='from_id', DESTID='to_id'; +INSERT INTO graph_base(from_id, to_id) VALUES (1,2), (2,1); +INSERT INTO graph_base(from_id, to_id) VALUES (1,3), (3,1); +INSERT INTO graph_base(from_id, to_id) VALUES (3,4), (4,3); +INSERT INTO graph_base(from_id, to_id) VALUES (5,6), (6,5); +select * from graph where latch is null; +latch origid destid weight seq linkid +NULL 1 2 1 NULL NULL +NULL 2 1 1 NULL NULL +NULL 1 3 1 NULL NULL +NULL 3 1 1 NULL NULL +NULL 3 4 1 NULL NULL +NULL 4 3 1 NULL NULL +NULL 5 6 1 NULL NULL +NULL 6 5 1 NULL NULL +select * from graph where latch is null and origid=1; +latch origid destid weight seq linkid +NULL 1 NULL 1 2 3 +NULL 1 NULL 1 1 2 +select * from graph where latch is null and destid=2; +latch origid destid weight seq linkid +NULL NULL 2 1 1 1 +DROP TABLE graph; +DROP TABLE graph_base; diff --git a/storage/oqgraph/mysql-test/oqgraph/isnull.test b/storage/oqgraph/mysql-test/oqgraph/isnull.test new file mode 100644 index 00000000..dc7622da --- /dev/null +++ b/storage/oqgraph/mysql-test/oqgraph/isnull.test @@ -0,0 +1,38 @@ +--disable_warnings +DROP TABLE IF EXISTS graph_base; +DROP TABLE IF EXISTS graph; +DROP TABLE IF EXISTS graph2; +--enable_warnings + +# Create the backing store +CREATE TABLE graph_base ( + from_id INT UNSIGNED NOT NULL, + to_id INT UNSIGNED NOT NULL, + PRIMARY KEY (from_id,to_id), + INDEX (to_id) + ) ENGINE=MyISAM; + + +CREATE TABLE graph ( + latch VARCHAR(32) NULL, + origid BIGINT UNSIGNED NULL, + destid BIGINT UNSIGNED NULL, + weight DOUBLE NULL, + seq BIGINT UNSIGNED NULL, + linkid BIGINT UNSIGNED NULL, + KEY (latch, origid, destid) USING HASH, + KEY (latch, destid, origid) USING HASH + ) ENGINE=OQGRAPH DATA_TABLE='graph_base' ORIGID='from_id', DESTID='to_id'; + + +INSERT INTO graph_base(from_id, to_id) VALUES (1,2), (2,1); +INSERT INTO graph_base(from_id, to_id) VALUES (1,3), (3,1); +INSERT INTO graph_base(from_id, to_id) VALUES (3,4), (4,3); +INSERT INTO graph_base(from_id, to_id) VALUES (5,6), (6,5); + +select * from graph where latch is null; +select * from graph where latch is null and origid=1; +select * from graph where latch is null and destid=2; + +DROP TABLE graph; +DROP TABLE graph_base; diff --git a/storage/oqgraph/mysql-test/oqgraph/legacy_upgrade.result b/storage/oqgraph/mysql-test/oqgraph/legacy_upgrade.result new file mode 100644 index 00000000..0b437217 --- /dev/null +++ b/storage/oqgraph/mysql-test/oqgraph/legacy_upgrade.result @@ -0,0 +1,99 @@ +DROP TABLE IF EXISTS graph_base; +DROP TABLE IF EXISTS graph; +CREATE TABLE graph_base ( +from_id INT UNSIGNED NOT NULL, +to_id INT UNSIGNED NOT NULL, +PRIMARY KEY (from_id,to_id), +INDEX (to_id) +) ENGINE=MyISAM; +The next error 140 + 1005 is expected +CREATE TABLE graph ( +latch SMALLINT UNSIGNED NULL, +origid BIGINT UNSIGNED NULL, +destid BIGINT UNSIGNED NULL, +weight DOUBLE NULL, +seq BIGINT UNSIGNED NULL, +linkid BIGINT UNSIGNED NULL, +KEY (latch, origid, destid) USING HASH, +KEY (latch, destid, origid) USING HASH +) ENGINE=OQGRAPH DATA_TABLE='graph_base' ORIGID='from_id', DESTID='to_id'; +ERROR HY000: Can't create table `test`.`graph` (errno: 140 "Wrong create options") +SET GLOBAL oqgraph_allow_create_integer_latch=true; +The next warning 1287 is expected +CREATE TABLE graph ( +latch SMALLINT UNSIGNED NULL, +origid BIGINT UNSIGNED NULL, +destid BIGINT UNSIGNED NULL, +weight DOUBLE NULL, +seq BIGINT UNSIGNED NULL, +linkid BIGINT UNSIGNED NULL, +KEY (latch, origid, destid) USING HASH, +KEY (latch, destid, origid) USING HASH +) ENGINE=OQGRAPH DATA_TABLE='graph_base' ORIGID='from_id', DESTID='to_id'; +Warnings: +Warning 1287 'latch SMALLINT UNSIGNED NULL' is deprecated and will be removed in a future release. Please use 'latch VARCHAR(32) NULL' instead +SET GLOBAL oqgraph_allow_create_integer_latch=false; +The next error 140 + 1005 is expected +CREATE TABLE graph_again ( +latch SMALLINT UNSIGNED NULL, +origid BIGINT UNSIGNED NULL, +destid BIGINT UNSIGNED NULL, +weight DOUBLE NULL, +seq BIGINT UNSIGNED NULL, +linkid BIGINT UNSIGNED NULL, +KEY (latch, origid, destid) USING HASH, +KEY (latch, destid, origid) USING HASH +) ENGINE=OQGRAPH DATA_TABLE='graph_base' ORIGID='from_id', DESTID='to_id'; +ERROR HY000: Can't create table `test`.`graph_again` (errno: 140 "Wrong create options") +# Populating base table +INSERT INTO graph_base(from_id, to_id) VALUES (1,2), (2,1); +INSERT INTO graph_base(from_id, to_id) VALUES (1,3), (3,1); +INSERT INTO graph_base(from_id, to_id) VALUES (3,4), (4,3); +INSERT INTO graph_base(from_id, to_id) VALUES (5,6), (6,5); +# Exercising latch==2 +SELECT * FROM graph WHERE latch = 2 AND origid = 1 AND weight = 1; +latch origid destid weight seq linkid +2 1 NULL 1 3 3 +2 1 NULL 1 2 2 +SELECT * FROM graph WHERE latch = 2 AND origid = 1 AND weight = 2; +latch origid destid weight seq linkid +2 1 NULL 2 4 4 +SELECT * FROM graph WHERE latch = 2 AND origid = 1 AND (weight = 1 OR weight = 2); +latch origid destid weight seq linkid +2 1 NULL 2 4 4 +2 1 NULL 1 3 3 +2 1 NULL 1 2 2 +# Exercising latch==1 +SELECT * FROM graph WHERE latch=1 AND origid=1 AND destid=6; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch=1 AND origid=1 AND destid=4; +latch origid destid weight seq linkid +1 1 4 NULL 0 1 +1 1 4 1 1 3 +1 1 4 1 2 4 +SELECT * FROM graph WHERE latch=1 AND origid=4 AND destid=1; +latch origid destid weight seq linkid +1 4 1 NULL 0 4 +1 4 1 1 1 3 +1 4 1 1 2 1 +SELECT * FROM graph WHERE latch=0 and destid=2 and origid=1; +latch origid destid weight seq linkid +0 1 2 1 3 1 +0 1 2 1 2 3 +0 1 2 1 1 2 +# Adding new row to base table +INSERT INTO graph_base (from_id,to_id) VALUES (4,6); +# Deleting rows from base table +DELETE FROM graph_base WHERE from_id=5; +DELETE FROM graph_base WHERE from_id=3 AND to_id=5; +# Execising latch==1 on new data +SELECT * FROM graph WHERE latch=1 AND origid=1 AND destid=6; +latch origid destid weight seq linkid +1 1 6 NULL 0 1 +1 1 6 1 1 3 +1 1 6 1 2 4 +1 1 6 1 3 6 +SELECT * FROM graph WHERE latch=1 AND origid=6 AND destid=1; +latch origid destid weight seq linkid +DROP TABLE IF EXISTS graph; +DROP TABLE IF EXISTS graph_base; diff --git a/storage/oqgraph/mysql-test/oqgraph/legacy_upgrade.test b/storage/oqgraph/mysql-test/oqgraph/legacy_upgrade.test new file mode 100644 index 00000000..ae548b5e --- /dev/null +++ b/storage/oqgraph/mysql-test/oqgraph/legacy_upgrade.test @@ -0,0 +1,106 @@ +--disable_warnings +DROP TABLE IF EXISTS graph_base; +DROP TABLE IF EXISTS graph; +--enable_warnings + +CREATE TABLE graph_base ( + from_id INT UNSIGNED NOT NULL, + to_id INT UNSIGNED NOT NULL, + PRIMARY KEY (from_id,to_id), + INDEX (to_id) + ) ENGINE=MyISAM; + +# Backwards compatibility test +# First we ensure the scaffolding is disabled (default situation) +# and check we cant create a table with an integer latch +# Assume this is the default, so don't explicity set false yet: +# SET GLOBAL oqgraph_allow_create_integer_latch=false; +--echo The next error 140 + 1005 is expected +--error 140 +--error 1005 +CREATE TABLE graph ( + latch SMALLINT UNSIGNED NULL, + origid BIGINT UNSIGNED NULL, + destid BIGINT UNSIGNED NULL, + weight DOUBLE NULL, + seq BIGINT UNSIGNED NULL, + linkid BIGINT UNSIGNED NULL, + KEY (latch, origid, destid) USING HASH, + KEY (latch, destid, origid) USING HASH + ) ENGINE=OQGRAPH DATA_TABLE='graph_base' ORIGID='from_id', DESTID='to_id'; + +# Here we enable scaffolding to let us create a deprecated table +# so we can check that the new code will still allow queries to be performed +# on a legacy database +# It should still generate a warning (1287) - but I don't know how to test for that +# +# latch SMALLINT UNSIGNED NULL' is deprecated and will be removed in a future +# release. Please use 'latch VARCHAR(32) NULL' instead +# +SET GLOBAL oqgraph_allow_create_integer_latch=true; +--echo The next warning 1287 is expected +CREATE TABLE graph ( + latch SMALLINT UNSIGNED NULL, + origid BIGINT UNSIGNED NULL, + destid BIGINT UNSIGNED NULL, + weight DOUBLE NULL, + seq BIGINT UNSIGNED NULL, + linkid BIGINT UNSIGNED NULL, + KEY (latch, origid, destid) USING HASH, + KEY (latch, destid, origid) USING HASH + ) ENGINE=OQGRAPH DATA_TABLE='graph_base' ORIGID='from_id', DESTID='to_id'; + +# Prevent further tables being create this way again +# and make sure the set is effective ... +SET GLOBAL oqgraph_allow_create_integer_latch=false; +--echo The next error 140 + 1005 is expected +--error 140 +--error 1005 +CREATE TABLE graph_again ( + latch SMALLINT UNSIGNED NULL, + origid BIGINT UNSIGNED NULL, + destid BIGINT UNSIGNED NULL, + weight DOUBLE NULL, + seq BIGINT UNSIGNED NULL, + linkid BIGINT UNSIGNED NULL, + KEY (latch, origid, destid) USING HASH, + KEY (latch, destid, origid) USING HASH + ) ENGINE=OQGRAPH DATA_TABLE='graph_base' ORIGID='from_id', DESTID='to_id'; + +# Regression test expected v2 behaviour in this situation + +--echo # Populating base table +INSERT INTO graph_base(from_id, to_id) VALUES (1,2), (2,1); +INSERT INTO graph_base(from_id, to_id) VALUES (1,3), (3,1); +INSERT INTO graph_base(from_id, to_id) VALUES (3,4), (4,3); +INSERT INTO graph_base(from_id, to_id) VALUES (5,6), (6,5); + +--echo # Exercising latch==2 +SELECT * FROM graph WHERE latch = 2 AND origid = 1 AND weight = 1; +SELECT * FROM graph WHERE latch = 2 AND origid = 1 AND weight = 2; +SELECT * FROM graph WHERE latch = 2 AND origid = 1 AND (weight = 1 OR weight = 2); +--echo # Exercising latch==1 +SELECT * FROM graph WHERE latch=1 AND origid=1 AND destid=6; +SELECT * FROM graph WHERE latch=1 AND origid=1 AND destid=4; +SELECT * FROM graph WHERE latch=1 AND origid=4 AND destid=1; + +SELECT * FROM graph WHERE latch=0 and destid=2 and origid=1; + + +--echo # Adding new row to base table +INSERT INTO graph_base (from_id,to_id) VALUES (4,6); + +--echo # Deleting rows from base table +DELETE FROM graph_base WHERE from_id=5; +DELETE FROM graph_base WHERE from_id=3 AND to_id=5; + +--echo # Execising latch==1 on new data +SELECT * FROM graph WHERE latch=1 AND origid=1 AND destid=6; + +SELECT * FROM graph WHERE latch=1 AND origid=6 AND destid=1; + +# FIXME - if the following DROPs are missing then mysql will segfault on exit +# indicating an ordering dependency on destruction somewhere... +DROP TABLE IF EXISTS graph; +DROP TABLE IF EXISTS graph_base; + diff --git a/storage/oqgraph/mysql-test/oqgraph/maintainer-general-record.sh b/storage/oqgraph/mysql-test/oqgraph/maintainer-general-record.sh new file mode 100755 index 00000000..7af12013 --- /dev/null +++ b/storage/oqgraph/mysql-test/oqgraph/maintainer-general-record.sh @@ -0,0 +1,6 @@ +#!/bin/sh +# This is a maintainer generated file. Generated at Wednesday 5 February 22:26:12 CST 2014. +mysql-test/mysql-test-run --record oqgraph.general-MyISAM +mysql-test/mysql-test-run --record oqgraph.general-MEMORY +mysql-test/mysql-test-run --record oqgraph.general-Aria +mysql-test/mysql-test-run --record oqgraph.general-innodb diff --git a/storage/oqgraph/mysql-test/oqgraph/regression_1133093.result b/storage/oqgraph/mysql-test/oqgraph/regression_1133093.result new file mode 100644 index 00000000..e5a99d39 --- /dev/null +++ b/storage/oqgraph/mysql-test/oqgraph/regression_1133093.result @@ -0,0 +1,44 @@ +DROP TABLE IF EXISTS graph_base; +DROP TABLE IF EXISTS graph; +CREATE TABLE graph_base ( +from_id INT UNSIGNED NOT NULL, +to_id INT UNSIGNED NOT NULL, +another_id INT UNSIGNED NOT NULL DEFAULT 1, +w DOUBLE NOT NULL DEFAULT 1, +PRIMARY KEY (from_id,to_id), +INDEX (to_id) +) ENGINE=MyISAM; +CREATE TABLE graph ( +latch VARCHAR(32) NULL, +origid BIGINT UNSIGNED NULL, +destid BIGINT UNSIGNED NULL, +weight DOUBLE NULL, +seq BIGINT UNSIGNED NULL, +linkid BIGINT UNSIGNED NULL, +KEY (latch, origid, destid) USING HASH, +KEY (latch, destid, origid) USING HASH +) ENGINE=OQGRAPH DATA_TABLE='graph_base' ORIGID='from_id', DESTID='to_id', WEIGHT='w'; +INSERT INTO graph_base(from_id, to_id) VALUES (1,2), (2,1); +INSERT INTO graph_base(from_id, to_id) VALUES (1,3), (3,1); +INSERT INTO graph_base(from_id, to_id) VALUES (1,4), (4,1); +INSERT INTO graph_base(from_id, to_id) VALUES (3,4), (4,3); +SELECT * from graph; +latch origid destid weight seq linkid +NULL 1 2 1 NULL NULL +NULL 2 1 1 NULL NULL +NULL 1 3 1 NULL NULL +NULL 3 1 1 NULL NULL +NULL 1 4 1 NULL NULL +NULL 4 1 1 NULL NULL +NULL 3 4 1 NULL NULL +NULL 4 3 1 NULL NULL +SELECT * FROM graph WHERE latch='1' and destid=2 and origid=1; +latch origid destid weight seq linkid +1 1 2 NULL 0 1 +1 1 2 1 1 2 +SELECT * FROM graph WHERE latch='1' and destid=2 and origid=1 order by seq; +latch origid destid weight seq linkid +1 1 2 NULL 0 1 +1 1 2 1 1 2 +DROP TABLE graph; +DROP TABLE graph_base; diff --git a/storage/oqgraph/mysql-test/oqgraph/regression_1133093.test b/storage/oqgraph/mysql-test/oqgraph/regression_1133093.test new file mode 100644 index 00000000..c3a9a996 --- /dev/null +++ b/storage/oqgraph/mysql-test/oqgraph/regression_1133093.test @@ -0,0 +1,46 @@ +# Regression test for https://bugs.launchpad.net/oqgraph/+bug/1133093 +# Reproduce bug where order by seq crashes +--disable_warnings +DROP TABLE IF EXISTS graph_base; +DROP TABLE IF EXISTS graph; +--enable_warnings + + +# Create the backing store +CREATE TABLE graph_base ( + from_id INT UNSIGNED NOT NULL, + to_id INT UNSIGNED NOT NULL, + another_id INT UNSIGNED NOT NULL DEFAULT 1, + w DOUBLE NOT NULL DEFAULT 1, + PRIMARY KEY (from_id,to_id), + INDEX (to_id) + ) ENGINE=MyISAM; + +CREATE TABLE graph ( + latch VARCHAR(32) NULL, + origid BIGINT UNSIGNED NULL, + destid BIGINT UNSIGNED NULL, + weight DOUBLE NULL, + seq BIGINT UNSIGNED NULL, + linkid BIGINT UNSIGNED NULL, + KEY (latch, origid, destid) USING HASH, + KEY (latch, destid, origid) USING HASH + ) ENGINE=OQGRAPH DATA_TABLE='graph_base' ORIGID='from_id', DESTID='to_id', WEIGHT='w'; + +# -- do some stuff + +INSERT INTO graph_base(from_id, to_id) VALUES (1,2), (2,1); +INSERT INTO graph_base(from_id, to_id) VALUES (1,3), (3,1); +INSERT INTO graph_base(from_id, to_id) VALUES (1,4), (4,1); +INSERT INTO graph_base(from_id, to_id) VALUES (3,4), (4,3); + +SELECT * from graph; +SELECT * FROM graph WHERE latch='1' and destid=2 and origid=1; +SELECT * FROM graph WHERE latch='1' and destid=2 and origid=1 order by seq; + +DROP TABLE graph; +DROP TABLE graph_base; + + +# Probably a separate issue: if the test is exited without dropping the tables at all +# then there is a memory leak reported diff --git a/storage/oqgraph/mysql-test/oqgraph/regression_1134355.result b/storage/oqgraph/mysql-test/oqgraph/regression_1134355.result new file mode 100644 index 00000000..015b42ab --- /dev/null +++ b/storage/oqgraph/mysql-test/oqgraph/regression_1134355.result @@ -0,0 +1,46 @@ +DROP TABLE IF EXISTS graph_base; +DROP TABLE IF EXISTS graph; +CREATE TABLE graph_base ( +from_id INT UNSIGNED NOT NULL, +to_id INT UNSIGNED NOT NULL, +another_id INT UNSIGNED NOT NULL DEFAULT 1, +w DOUBLE NOT NULL DEFAULT 1, +PRIMARY KEY (from_id,to_id), +INDEX (to_id) +) ENGINE=MyISAM; +CREATE TABLE graph ( +latch VARCHAR(32) NULL, +origid BIGINT UNSIGNED NULL, +destid BIGINT UNSIGNED NULL, +weight DOUBLE NULL, +seq BIGINT UNSIGNED NULL, +linkid BIGINT UNSIGNED NULL, +KEY (latch, origid, destid) USING HASH, +KEY (latch, destid, origid) USING HASH +) ENGINE=OQGRAPH DATA_TABLE='graph_base' ORIGID='from_id', DESTID='to_id', WEIGHT='w'; +INSERT INTO graph_base(from_id, to_id) VALUES (1,2), (2,1); +INSERT INTO graph_base(from_id, to_id) VALUES (1,3), (3,1); +INSERT INTO graph_base(from_id, to_id) VALUES (1,4), (4,1); +INSERT INTO graph_base(from_id, to_id) VALUES (3,4), (4,3); +SELECT * from graph; +latch origid destid weight seq linkid +NULL 1 2 1 NULL NULL +NULL 2 1 1 NULL NULL +NULL 1 3 1 NULL NULL +NULL 3 1 1 NULL NULL +NULL 1 4 1 NULL NULL +NULL 4 1 1 NULL NULL +NULL 3 4 1 NULL NULL +NULL 4 3 1 NULL NULL +SELECT * FROM graph WHERE destid=2 and origid=1; +latch origid destid weight seq linkid +NULL 1 2 1 NULL NULL +alter table graph ORIGID = 'another_id'; +ERROR HY000: Storage engine OQGRAPH of the table `test`.`graph` doesn't have this option +alter table graph ORIGID = 'something_else'; +ERROR HY000: Storage engine OQGRAPH of the table `test`.`graph` doesn't have this option +DELETE FROM graph_base; +FLUSH TABLES; +TRUNCATE TABLE graph_base; +DROP TABLE graph_base; +DROP TABLE graph; diff --git a/storage/oqgraph/mysql-test/oqgraph/regression_1134355.test b/storage/oqgraph/mysql-test/oqgraph/regression_1134355.test new file mode 100644 index 00000000..ca9c7e36 --- /dev/null +++ b/storage/oqgraph/mysql-test/oqgraph/regression_1134355.test @@ -0,0 +1,59 @@ +# Regression test for https://bugs.launchpad.net/oqgraph/+bug/1134355 +#--reproduce bug where renaming a column in the graph crashes instead of returning an error +--disable_warnings +DROP TABLE IF EXISTS graph_base; +DROP TABLE IF EXISTS graph; +--enable_warnings + +# Create the backing store +CREATE TABLE graph_base ( + from_id INT UNSIGNED NOT NULL, + to_id INT UNSIGNED NOT NULL, + another_id INT UNSIGNED NOT NULL DEFAULT 1, + w DOUBLE NOT NULL DEFAULT 1, + PRIMARY KEY (from_id,to_id), + INDEX (to_id) + ) ENGINE=MyISAM; + + +CREATE TABLE graph ( + latch VARCHAR(32) NULL, + origid BIGINT UNSIGNED NULL, + destid BIGINT UNSIGNED NULL, + weight DOUBLE NULL, + seq BIGINT UNSIGNED NULL, + linkid BIGINT UNSIGNED NULL, + KEY (latch, origid, destid) USING HASH, + KEY (latch, destid, origid) USING HASH + ) ENGINE=OQGRAPH DATA_TABLE='graph_base' ORIGID='from_id', DESTID='to_id', WEIGHT='w'; + +# -- do some stuff + +INSERT INTO graph_base(from_id, to_id) VALUES (1,2), (2,1); +INSERT INTO graph_base(from_id, to_id) VALUES (1,3), (3,1); +INSERT INTO graph_base(from_id, to_id) VALUES (1,4), (4,1); +INSERT INTO graph_base(from_id, to_id) VALUES (3,4), (4,3); + +SELECT * from graph; +SELECT * FROM graph WHERE destid=2 and origid=1; + +# We cant do this anyway because of read onlyness of table.... 1036 == read only +# In any case I changed the flags to make alter unsupported; later we can try and work out why the core doesnt help us clean up properly +# --error 1036 +--error 1031 +alter table graph ORIGID = 'another_id'; + +# But we need that to hold even in an invalid situation! +# -- bug was: the following alter table would crash, instead of returning error 1296 +# -- currently following may not crash, but does with the previous error 1036 causing statement present +# 'attribute not set to a valid column of 'xxx' - note currently truncating to graph_b instead of graph_base for some reason... +#--error 1296 +--error 1031 +alter table graph ORIGID = 'something_else'; + +DELETE FROM graph_base; +FLUSH TABLES; +TRUNCATE TABLE graph_base; +DROP TABLE graph_base; +DROP TABLE graph; + diff --git a/storage/oqgraph/mysql-test/oqgraph/regression_1195735.result b/storage/oqgraph/mysql-test/oqgraph/regression_1195735.result new file mode 100644 index 00000000..67aa885d --- /dev/null +++ b/storage/oqgraph/mysql-test/oqgraph/regression_1195735.result @@ -0,0 +1,32 @@ +DROP TABLE IF EXISTS graph_base; +DROP TABLE IF EXISTS graph; +CREATE TABLE graph_base ( +from_id INT UNSIGNED NOT NULL, +to_id INT UNSIGNED NOT NULL, +PRIMARY KEY (from_id,to_id), +INDEX (to_id) +) ENGINE=MyISAM; +CREATE TABLE graph ( +latch VARCHAR(32) NULL, +origid BIGINT UNSIGNED NULL, +destid BIGINT UNSIGNED NULL, +weight DOUBLE NULL, +seq BIGINT UNSIGNED NULL, +linkid BIGINT UNSIGNED NULL, +KEY (latch, origid, destid) USING HASH, +KEY (latch, destid, origid) USING HASH +) ENGINE=OQGRAPH DATA_TABLE='graph_base' ORIGID='from_id', DESTID='to_id'; +INSERT INTO graph_base(from_id, to_id) VALUES (1,2), (2,1); +One select of any clauses at all on graph here caused a hang on the select after the DELETE FROM +SELECT * FROM graph WHERE destid=2 and origid=1; +latch origid destid weight seq linkid +NULL 1 2 1 NULL NULL +DELETE FROM graph_base; +SELECT * from graph; +latch origid destid weight seq linkid +FLUSH TABLES; +TRUNCATE TABLE graph_base; +DROP TABLE graph_base; +SELECT * FROM graph WHERE latch='dijkstras' AND origid=1 AND destid=6; +ERROR 42S02: Table 'test.graph_base' doesn't exist +DROP TABLE graph; diff --git a/storage/oqgraph/mysql-test/oqgraph/regression_1195735.test b/storage/oqgraph/mysql-test/oqgraph/regression_1195735.test new file mode 100644 index 00000000..12ab7ecb --- /dev/null +++ b/storage/oqgraph/mysql-test/oqgraph/regression_1195735.test @@ -0,0 +1,44 @@ +# Regression test for https://bugs.launchpad.net/oqgraph/+bug/1195735 +#--reproduce bug where select * from graph after delete from graph_base hangs the server +--disable_warnings +DROP TABLE IF EXISTS graph_base; +DROP TABLE IF EXISTS graph; +--enable_warnings + +# Create the backing store +CREATE TABLE graph_base ( + from_id INT UNSIGNED NOT NULL, + to_id INT UNSIGNED NOT NULL, + PRIMARY KEY (from_id,to_id), + INDEX (to_id) + ) ENGINE=MyISAM; + + +CREATE TABLE graph ( + latch VARCHAR(32) NULL, + origid BIGINT UNSIGNED NULL, + destid BIGINT UNSIGNED NULL, + weight DOUBLE NULL, + seq BIGINT UNSIGNED NULL, + linkid BIGINT UNSIGNED NULL, + KEY (latch, origid, destid) USING HASH, + KEY (latch, destid, origid) USING HASH + ) ENGINE=OQGRAPH DATA_TABLE='graph_base' ORIGID='from_id', DESTID='to_id'; + + +INSERT INTO graph_base(from_id, to_id) VALUES (1,2), (2,1); + +--echo One select of any clauses at all on graph here caused a hang on the select after the DELETE FROM +#-- even this if it is the only one - but it doesnt hang here ... SELECT * FROM graph; +SELECT * FROM graph WHERE destid=2 and origid=1; + +DELETE FROM graph_base; +#-- Bug 1195735 hangs on the next line +SELECT * from graph; +FLUSH TABLES; +TRUNCATE TABLE graph_base; +DROP TABLE graph_base; +--error S42S02 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=1 AND destid=6; +DROP TABLE graph; + diff --git a/storage/oqgraph/mysql-test/oqgraph/regression_1196020.result b/storage/oqgraph/mysql-test/oqgraph/regression_1196020.result new file mode 100644 index 00000000..3ffc5a0e --- /dev/null +++ b/storage/oqgraph/mysql-test/oqgraph/regression_1196020.result @@ -0,0 +1,68 @@ +DROP TABLE IF EXISTS graph_base; +DROP TABLE IF EXISTS graph; +CREATE TABLE graph_base ( +from_id INT UNSIGNED NOT NULL, +to_id INT UNSIGNED NOT NULL, +PRIMARY KEY (from_id,to_id), +INDEX (to_id) +) ENGINE=MyISAM; +CREATE TABLE graph ( +latch VARCHAR(32) NULL, +origid BIGINT UNSIGNED NULL, +destid BIGINT UNSIGNED NULL, +weight DOUBLE NULL, +seq BIGINT UNSIGNED NULL, +linkid BIGINT UNSIGNED NULL, +KEY (latch, origid, destid) USING HASH, +KEY (latch, destid, origid) USING HASH +) ENGINE=OQGRAPH DATA_TABLE='graph_base' ORIGID='from_id', DESTID='to_id'; +INSERT INTO graph_base(from_id, to_id) VALUES (1,2), (2,1); +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 666; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 666; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'dijkstras' AND origid = 666; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '1' AND origid = 666; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 666; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND destid = 666; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'dijkstras' AND destid = 666; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '1' AND destid = 666; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 666 and weight = 1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 666 and weight = 1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'dijkstras' AND origid = 666 and weight = 1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '1' AND origid = 666 and weight = 1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 666 and weight = 1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND destid = 666 and weight = 1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'dijkstras' AND destid = 666 and weight = 1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '1' AND destid = 666 and weight = 1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '' AND origid = 666; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '0' AND origid = 666; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch is NULL AND origid = 666; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '' AND destid = 666; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '0' AND destid = 666; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch is NULL AND destid = 666; +latch origid destid weight seq linkid +DELETE FROM graph_base; +FLUSH TABLES; +TRUNCATE TABLE graph_base; +DROP TABLE graph_base; +DROP TABLE graph; diff --git a/storage/oqgraph/mysql-test/oqgraph/regression_1196020.test b/storage/oqgraph/mysql-test/oqgraph/regression_1196020.test new file mode 100644 index 00000000..a4df1790 --- /dev/null +++ b/storage/oqgraph/mysql-test/oqgraph/regression_1196020.test @@ -0,0 +1,71 @@ +# Regression test for https://bugs.launchpad.net/oqgraph/+bug/1196020 +#-- bug where select blah with origid = X where X does not exist, returns a row +#-- bug where select blah with destid = X where X does not exist, returns a row +--disable_warnings +DROP TABLE IF EXISTS graph_base; +DROP TABLE IF EXISTS graph; +--enable_warnings + +# Create the backing store +CREATE TABLE graph_base ( + from_id INT UNSIGNED NOT NULL, + to_id INT UNSIGNED NOT NULL, + PRIMARY KEY (from_id,to_id), + INDEX (to_id) + ) ENGINE=MyISAM; + + +CREATE TABLE graph ( + latch VARCHAR(32) NULL, + origid BIGINT UNSIGNED NULL, + destid BIGINT UNSIGNED NULL, + weight DOUBLE NULL, + seq BIGINT UNSIGNED NULL, + linkid BIGINT UNSIGNED NULL, + KEY (latch, origid, destid) USING HASH, + KEY (latch, destid, origid) USING HASH + ) ENGINE=OQGRAPH DATA_TABLE='graph_base' ORIGID='from_id', DESTID='to_id'; + + +INSERT INTO graph_base(from_id, to_id) VALUES (1,2), (2,1); + +# All the following should return no result because no vertex 666 exists in the graph + +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 666; +SELECT * FROM graph WHERE latch = '2' AND origid = 666; +SELECT * FROM graph WHERE latch = 'dijkstras' AND origid = 666; +SELECT * FROM graph WHERE latch = '1' AND origid = 666; + +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 666; +SELECT * FROM graph WHERE latch = '2' AND destid = 666; +SELECT * FROM graph WHERE latch = 'dijkstras' AND destid = 666; +SELECT * FROM graph WHERE latch = '1' AND destid = 666; + +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 666 and weight = 1; +SELECT * FROM graph WHERE latch = '2' AND origid = 666 and weight = 1; +SELECT * FROM graph WHERE latch = 'dijkstras' AND origid = 666 and weight = 1; +SELECT * FROM graph WHERE latch = '1' AND origid = 666 and weight = 1; + +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 666 and weight = 1; +SELECT * FROM graph WHERE latch = '2' AND destid = 666 and weight = 1; +SELECT * FROM graph WHERE latch = 'dijkstras' AND destid = 666 and weight = 1; +SELECT * FROM graph WHERE latch = '1' AND destid = 666 and weight = 1; + +# Sanity check for no-search +SELECT * FROM graph WHERE latch = '' AND origid = 666; +SELECT * FROM graph WHERE latch = '0' AND origid = 666; +SELECT * FROM graph WHERE latch is NULL AND origid = 666; + +SELECT * FROM graph WHERE latch = '' AND destid = 666; +SELECT * FROM graph WHERE latch = '0' AND destid = 666; +SELECT * FROM graph WHERE latch is NULL AND destid = 666; + + + +DELETE FROM graph_base; +FLUSH TABLES; +TRUNCATE TABLE graph_base; + +DROP TABLE graph_base; +DROP TABLE graph; + diff --git a/storage/oqgraph/mysql-test/oqgraph/regression_1196027.result b/storage/oqgraph/mysql-test/oqgraph/regression_1196027.result new file mode 100644 index 00000000..6c42374d --- /dev/null +++ b/storage/oqgraph/mysql-test/oqgraph/regression_1196027.result @@ -0,0 +1,56 @@ +DROP TABLE IF EXISTS graph_base; +DROP TABLE IF EXISTS graph; +CREATE TABLE graph_base ( +from_id INT UNSIGNED NOT NULL, +to_id INT UNSIGNED NOT NULL, +PRIMARY KEY (from_id,to_id), +INDEX (to_id) +) ENGINE=MyISAM; +CREATE TABLE graph ( +latch VARCHAR(32) NULL, +origid BIGINT UNSIGNED NULL, +destid BIGINT UNSIGNED NULL, +weight DOUBLE NULL, +seq BIGINT UNSIGNED NULL, +linkid BIGINT UNSIGNED NULL, +KEY (latch, origid, destid) USING HASH, +KEY (latch, destid, origid) USING HASH +) ENGINE=OQGRAPH DATA_TABLE='graph_base' ORIGID='from_id', DESTID='to_id'; +INSERT INTO graph_base(from_id, to_id) VALUES (1,2), (2,1); +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 1; +latch origid destid weight seq linkid +breadth_first NULL 1 1 2 2 +breadth_first NULL 1 0 1 1 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 2; +latch origid destid weight seq linkid +breadth_first NULL 2 1 2 1 +breadth_first NULL 2 0 1 2 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 1; +latch origid destid weight seq linkid +breadth_first 1 NULL 1 2 2 +breadth_first 1 NULL 0 1 1 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 2; +latch origid destid weight seq linkid +breadth_first 2 NULL 1 2 1 +breadth_first 2 NULL 0 1 2 +SELECT * FROM graph WHERE latch = '2' AND destid = 1; +latch origid destid weight seq linkid +2 NULL 1 1 2 2 +2 NULL 1 0 1 1 +SELECT * FROM graph WHERE latch = '2' AND destid = 2; +latch origid destid weight seq linkid +2 NULL 2 1 2 1 +2 NULL 2 0 1 2 +SELECT * FROM graph WHERE latch = '2' AND origid = 1; +latch origid destid weight seq linkid +2 1 NULL 1 2 2 +2 1 NULL 0 1 1 +SELECT * FROM graph WHERE latch = '2' AND origid = 2; +latch origid destid weight seq linkid +2 2 NULL 1 2 1 +2 2 NULL 0 1 2 +DELETE FROM graph_base; +FLUSH TABLES; +TRUNCATE TABLE graph_base; +DROP TABLE graph_base; +DROP TABLE graph; diff --git a/storage/oqgraph/mysql-test/oqgraph/regression_1196027.test b/storage/oqgraph/mysql-test/oqgraph/regression_1196027.test new file mode 100644 index 00000000..5e7017bd --- /dev/null +++ b/storage/oqgraph/mysql-test/oqgraph/regression_1196027.test @@ -0,0 +1,51 @@ +# Regression test for https://bugs.launchpad.net/oqgraph/+bug/1196027 +#-- These were returning NULL which is incorrect +#-- https://bugs.launchpad.net/oqgraph/+bug/1196027 +--disable_warnings +DROP TABLE IF EXISTS graph_base; +DROP TABLE IF EXISTS graph; +--enable_warnings + +# Create the backing store +CREATE TABLE graph_base ( + from_id INT UNSIGNED NOT NULL, + to_id INT UNSIGNED NOT NULL, + PRIMARY KEY (from_id,to_id), + INDEX (to_id) + ) ENGINE=MyISAM; + + +CREATE TABLE graph ( + latch VARCHAR(32) NULL, + origid BIGINT UNSIGNED NULL, + destid BIGINT UNSIGNED NULL, + weight DOUBLE NULL, + seq BIGINT UNSIGNED NULL, + linkid BIGINT UNSIGNED NULL, + KEY (latch, origid, destid) USING HASH, + KEY (latch, destid, origid) USING HASH + ) ENGINE=OQGRAPH DATA_TABLE='graph_base' ORIGID='from_id', DESTID='to_id'; + + +INSERT INTO graph_base(from_id, to_id) VALUES (1,2), (2,1); + +# All the following should return no result because no vertex 666 exists in the graph + +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 1; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 2; +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 = '2' AND destid = 1; +SELECT * FROM graph WHERE latch = '2' AND destid = 2; +SELECT * FROM graph WHERE latch = '2' AND origid = 1; +SELECT * FROM graph WHERE latch = '2' AND origid = 2; + + +DELETE FROM graph_base; +FLUSH TABLES; +TRUNCATE TABLE graph_base; + +DROP TABLE graph_base; +DROP TABLE graph; + diff --git a/storage/oqgraph/mysql-test/oqgraph/regression_1196036.result b/storage/oqgraph/mysql-test/oqgraph/regression_1196036.result new file mode 100644 index 00000000..c372a0c0 --- /dev/null +++ b/storage/oqgraph/mysql-test/oqgraph/regression_1196036.result @@ -0,0 +1,103 @@ +DROP TABLE IF EXISTS graph_base; +DROP TABLE IF EXISTS graph; +CREATE TABLE graph_base ( +from_id INT UNSIGNED NOT NULL, +to_id INT UNSIGNED NOT NULL, +weight FLOAT NOT NULL, +PRIMARY KEY (from_id,to_id), +INDEX (to_id) +) ENGINE=MyISAM; +CREATE TABLE graph ( +latch VARCHAR(32) NULL, +origid BIGINT UNSIGNED NULL, +destid BIGINT UNSIGNED NULL, +weight DOUBLE NULL, +seq BIGINT UNSIGNED NULL, +linkid BIGINT UNSIGNED NULL, +KEY (latch, origid, destid) USING HASH, +KEY (latch, destid, origid) USING HASH +) ENGINE=OQGRAPH DATA_TABLE='graph_base' ORIGID='from_id', DESTID='to_id', WEIGHT='weight'; +INSERT INTO graph_base(from_id, to_id, weight) VALUES (1,2,16), (2,1,16); +INSERT INTO graph_base(from_id, to_id, weight) VALUES (2,3,256), (3,2,256); +INSERT INTO graph_base(from_id, to_id, weight) VALUES (3,4,65536), (4,3,65536); +INSERT INTO graph_base(from_id, to_id, weight) VALUES (2,4,768); +SELECT * FROM graph WHERE latch = 'dijkstras' AND origid = 1; +latch origid destid weight seq linkid +dijkstras 1 NULL 784 4 4 +dijkstras 1 NULL 272 3 3 +dijkstras 1 NULL 16 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 768 4 4 +dijkstras 2 NULL 256 3 3 +dijkstras 2 NULL 16 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 1024 4 4 +dijkstras 3 NULL 272 3 1 +dijkstras 3 NULL 256 2 2 +dijkstras 3 NULL 0 1 3 +SELECT * FROM graph WHERE latch = 'dijkstras' AND destid = 1; +latch origid destid weight seq linkid +dijkstras NULL 1 65808 4 4 +dijkstras NULL 1 272 3 3 +dijkstras NULL 1 16 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 65792 4 4 +dijkstras NULL 2 256 3 3 +dijkstras NULL 2 16 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 65536 4 4 +dijkstras NULL 3 272 3 1 +dijkstras NULL 3 256 2 2 +dijkstras NULL 3 0 1 3 +SELECT * FROM graph WHERE latch = 'dijkstras' AND origid = 1 and destid=3; +latch origid destid weight seq linkid +dijkstras 1 3 NULL 0 1 +dijkstras 1 3 16 1 2 +dijkstras 1 3 256 2 3 +SELECT * FROM graph WHERE latch = 'dijkstras' AND origid = 1 and destid=4; +latch origid destid weight seq linkid +dijkstras 1 4 NULL 0 1 +dijkstras 1 4 16 1 2 +dijkstras 1 4 768 2 4 +SELECT * FROM graph WHERE latch = 'dijkstras' AND origid = 1 and weight=1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'dijkstras' AND origid = 2 and weight=1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'dijkstras' AND origid = 3 and weight=1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'dijkstras' AND origid = 1 and weight=16; +latch origid destid weight seq linkid +dijkstras 1 NULL 16 2 2 +SELECT * FROM graph WHERE latch = 'dijkstras' AND origid = 2 and weight=16; +latch origid destid weight seq linkid +dijkstras 2 NULL 16 2 1 +SELECT * FROM graph WHERE latch = 'dijkstras' AND origid = 3 and weight=16; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'dijkstras' AND origid = 1 and weight=784; +latch origid destid weight seq linkid +dijkstras 1 NULL 784 4 4 +SELECT * FROM graph WHERE latch = 'dijkstras' AND origid = 2 and weight=784; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'dijkstras' AND origid = 3 and weight=784; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'dijkstras' AND origid = 1 and weight=256; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'dijkstras' AND origid = 2 and weight=256; +latch origid destid weight seq linkid +dijkstras 2 NULL 256 3 3 +SELECT * FROM graph WHERE latch = 'dijkstras' AND origid = 3 and weight=256; +latch origid destid weight seq linkid +dijkstras 3 NULL 256 2 2 +DELETE FROM graph_base; +FLUSH TABLES; +TRUNCATE TABLE graph_base; +DROP TABLE graph_base; +DROP TABLE graph; diff --git a/storage/oqgraph/mysql-test/oqgraph/regression_1196036.test b/storage/oqgraph/mysql-test/oqgraph/regression_1196036.test new file mode 100644 index 00000000..a95a1c6d --- /dev/null +++ b/storage/oqgraph/mysql-test/oqgraph/regression_1196036.test @@ -0,0 +1,68 @@ +# Regression test for https://bugs.launchpad.net/oqgraph/+bug/1196036 +#-- bug with Djikstras algorithm - find reachable vertices (origid=X) returns weight=0 instead of weight=count of hops +--disable_warnings +DROP TABLE IF EXISTS graph_base; +DROP TABLE IF EXISTS graph; +--enable_warnings + +# Create the backing store +CREATE TABLE graph_base ( + from_id INT UNSIGNED NOT NULL, + to_id INT UNSIGNED NOT NULL, + weight FLOAT NOT NULL, + PRIMARY KEY (from_id,to_id), + INDEX (to_id) + ) ENGINE=MyISAM; + + +CREATE TABLE graph ( + latch VARCHAR(32) NULL, + origid BIGINT UNSIGNED NULL, + destid BIGINT UNSIGNED NULL, + weight DOUBLE NULL, + seq BIGINT UNSIGNED NULL, + linkid BIGINT UNSIGNED NULL, + KEY (latch, origid, destid) USING HASH, + KEY (latch, destid, origid) USING HASH + ) ENGINE=OQGRAPH DATA_TABLE='graph_base' ORIGID='from_id', DESTID='to_id', WEIGHT='weight'; + + +INSERT INTO graph_base(from_id, to_id, weight) VALUES (1,2,16), (2,1,16); +INSERT INTO graph_base(from_id, to_id, weight) VALUES (2,3,256), (3,2,256); +INSERT INTO graph_base(from_id, to_id, weight) VALUES (3,4,65536), (4,3,65536); +INSERT INTO graph_base(from_id, to_id, weight) VALUES (2,4,768); + +SELECT * FROM graph WHERE latch = 'dijkstras' AND origid = 1; +SELECT * FROM graph WHERE latch = 'dijkstras' AND origid = 2; +SELECT * FROM graph WHERE latch = 'dijkstras' AND origid = 3; + +SELECT * FROM graph WHERE latch = 'dijkstras' AND destid = 1; +SELECT * FROM graph WHERE latch = 'dijkstras' AND destid = 2; +SELECT * FROM graph WHERE latch = 'dijkstras' AND destid = 3; + +SELECT * FROM graph WHERE latch = 'dijkstras' AND origid = 1 and destid=3; +SELECT * FROM graph WHERE latch = 'dijkstras' AND origid = 1 and destid=4; + +SELECT * FROM graph WHERE latch = 'dijkstras' AND origid = 1 and weight=1; # <-- should return nothing +SELECT * FROM graph WHERE latch = 'dijkstras' AND origid = 2 and weight=1; # <-- should return nothing +SELECT * FROM graph WHERE latch = 'dijkstras' AND origid = 3 and weight=1; # <-- should return nothing + +SELECT * FROM graph WHERE latch = 'dijkstras' AND origid = 1 and weight=16; +SELECT * FROM graph WHERE latch = 'dijkstras' AND origid = 2 and weight=16; +SELECT * FROM graph WHERE latch = 'dijkstras' AND origid = 3 and weight=16; # <-- should return nothing + +SELECT * FROM graph WHERE latch = 'dijkstras' AND origid = 1 and weight=784; +SELECT * FROM graph WHERE latch = 'dijkstras' AND origid = 2 and weight=784; # <-- should return nothing +SELECT * FROM graph WHERE latch = 'dijkstras' AND origid = 3 and weight=784; # <-- should return nothing + +SELECT * FROM graph WHERE latch = 'dijkstras' AND origid = 1 and weight=256; # <-- should return nothing +SELECT * FROM graph WHERE latch = 'dijkstras' AND origid = 2 and weight=256; +SELECT * FROM graph WHERE latch = 'dijkstras' AND origid = 3 and weight=256; + +DELETE FROM graph_base; +FLUSH TABLES; +TRUNCATE TABLE graph_base; + +DROP TABLE graph_base; +DROP TABLE graph; + diff --git a/storage/oqgraph/mysql-test/oqgraph/regression_1213120.result b/storage/oqgraph/mysql-test/oqgraph/regression_1213120.result new file mode 100644 index 00000000..642c0aa3 --- /dev/null +++ b/storage/oqgraph/mysql-test/oqgraph/regression_1213120.result @@ -0,0 +1,1345 @@ +DROP TABLE IF EXISTS graph_base; +DROP TABLE IF EXISTS graph; +DROP TABLE IF EXISTS graph2; +CREATE TABLE graph_base ( +from_id INT UNSIGNED NOT NULL, +to_id INT UNSIGNED NOT NULL, +PRIMARY KEY (from_id,to_id), +INDEX (to_id) +) ENGINE=MyISAM; +CREATE TABLE graph ( +latch VARCHAR(32) NULL, +origid BIGINT UNSIGNED NULL, +destid BIGINT UNSIGNED NULL, +weight DOUBLE NULL, +seq BIGINT UNSIGNED NULL, +linkid BIGINT UNSIGNED NULL, +KEY (latch, origid, destid) USING HASH, +KEY (latch, destid, origid) USING HASH +) ENGINE=OQGRAPH DATA_TABLE='graph_base' ORIGID='from_id', DESTID='to_id'; +INSERT INTO graph_base(from_id, to_id) VALUES (1,2), (2,1); +INSERT INTO graph_base(from_id, to_id) VALUES (1,3), (3,1); +INSERT INTO graph_base(from_id, to_id) VALUES (3,4), (4,3); +INSERT INTO graph_base(from_id, to_id) VALUES (5,6), (6,5); +INSERT INTO graph_base(from_id, to_id) VALUES (5,7); +INSERT INTO graph_base(from_id, to_id) VALUES (9,9); +INSERT INTO graph_base(from_id, to_id) VALUES (10,11); +INSERT INTO graph_base(from_id, to_id) VALUES (11,12); +INSERT INTO graph_base(from_id, to_id) VALUES (12,10); +# Return all edges +SELECT * FROM graph; +latch origid destid weight seq linkid +NULL 1 2 1 NULL NULL +NULL 2 1 1 NULL NULL +NULL 1 3 1 NULL NULL +NULL 3 1 1 NULL NULL +NULL 3 4 1 NULL NULL +NULL 4 3 1 NULL NULL +NULL 5 6 1 NULL NULL +NULL 6 5 1 NULL NULL +NULL 5 7 1 NULL NULL +NULL 9 9 1 NULL NULL +NULL 10 11 1 NULL NULL +NULL 11 12 1 NULL NULL +NULL 12 10 1 NULL NULL +# Currently count should be 13 +SELECT count(*) FROM graph; +count(*) +13 +SELECT count(*) FROM graph_base; +count(*) +13 +# Return all edges when latch is NULL - this is different to latch='' and same as no where clause +SELECT * FROM graph where latch is NULL; +latch origid destid weight seq linkid +NULL 1 2 1 NULL NULL +NULL 2 1 1 NULL NULL +NULL 1 3 1 NULL NULL +NULL 3 1 1 NULL NULL +NULL 3 4 1 NULL NULL +NULL 4 3 1 NULL NULL +NULL 5 6 1 NULL NULL +NULL 6 5 1 NULL NULL +NULL 5 7 1 NULL NULL +NULL 9 9 1 NULL NULL +NULL 10 11 1 NULL NULL +NULL 11 12 1 NULL NULL +NULL 12 10 1 NULL NULL +# Return all vertices, and subsets of vertices +SELECT * FROM graph where latch=''; +latch origid destid weight seq linkid + NULL NULL NULL NULL 1 + NULL NULL NULL NULL 2 + NULL NULL NULL NULL 3 + NULL NULL NULL NULL 4 + NULL NULL NULL NULL 5 + NULL NULL NULL NULL 6 + NULL NULL NULL NULL 7 + NULL NULL NULL NULL 9 + NULL NULL NULL NULL 10 + NULL NULL NULL NULL 11 + NULL NULL NULL NULL 12 +SELECT * FROM graph where latch='0'; +latch origid destid weight seq linkid +0 NULL NULL NULL NULL 1 +0 NULL NULL NULL NULL 2 +0 NULL NULL NULL NULL 3 +0 NULL NULL NULL NULL 4 +0 NULL NULL NULL NULL 5 +0 NULL NULL NULL NULL 6 +0 NULL NULL NULL NULL 7 +0 NULL NULL NULL NULL 9 +0 NULL NULL NULL NULL 10 +0 NULL NULL NULL NULL 11 +0 NULL NULL NULL NULL 12 +# Currently count should be 11 +SELECT count(*) FROM graph where latch=''; +count(*) +11 +SELECT * FROM graph where latch='' and linkid = 2; +latch origid destid weight seq linkid + NULL NULL NULL NULL 2 +SELECT * FROM graph where latch='' and (linkid > 2 and linkid < 6); +latch origid destid weight seq linkid + NULL NULL NULL NULL 3 + NULL NULL NULL NULL 4 + NULL NULL NULL NULL 5 +SELECT * FROM graph where latch='' and linkid = NULL; +latch origid destid weight seq linkid +SELECT * FROM graph where latch='' and linkid = 666; +latch origid destid weight seq linkid +SELECT origid as `from`, linkid as `to` FROM graph where latch='' and origid = 1; +from to +1 3 +1 2 +SELECT origid as `from`, linkid as `to` FROM graph where latch='' and origid = 2; +from to +2 1 +SELECT origid as `from`, linkid as `to` FROM graph where latch='' and origid = 4; +from to +4 3 +SELECT origid as `from`, linkid as `to` FROM graph where latch='' and origid = 9; +from to +9 9 +SELECT origid as `from`, linkid as `to` FROM graph where latch='' and origid = 10; +from to +10 11 +SELECT origid as `from`, linkid as `to` FROM graph where latch='' and origid = NULL; +from to +SELECT origid as `from`, linkid as `to` FROM graph where latch='' and origid = 666; +from to +SELECT linkid as `from`, destid as `to` FROM graph where latch='' and destid = 1; +from to +3 1 +2 1 +SELECT linkid as `from`, destid as `to` FROM graph where latch='' and destid = 2; +from to +1 2 +SELECT linkid as `from`, destid as `to` FROM graph where latch='' and destid = 4; +from to +3 4 +SELECT linkid as `from`, destid as `to` FROM graph where latch='' and destid = 9; +from to +9 9 +SELECT linkid as `from`, destid as `to` FROM graph where latch='' and destid = 10; +from to +12 10 +SELECT linkid as `from`, destid as `to` FROM graph where latch='' and destid = NULL; +from to +SELECT linkid as `from`, destid as `to` FROM graph where latch='' and destid = 666; +from to +SELECT * FROM graph where latch='0'; +latch origid destid weight seq linkid +0 NULL NULL NULL NULL 1 +0 NULL NULL NULL NULL 2 +0 NULL NULL NULL NULL 3 +0 NULL NULL NULL NULL 4 +0 NULL NULL NULL NULL 5 +0 NULL NULL NULL NULL 6 +0 NULL NULL NULL NULL 7 +0 NULL NULL NULL NULL 9 +0 NULL NULL NULL NULL 10 +0 NULL NULL NULL NULL 11 +0 NULL NULL NULL NULL 12 +SELECT count(*) FROM graph where latch='0'; +count(*) +11 +SELECT * FROM graph where latch='0' and linkid = 2; +latch origid destid weight seq linkid +0 NULL NULL NULL NULL 2 +SELECT * FROM graph where latch='0' and (linkid > 2 and linkid < 6); +latch origid destid weight seq linkid +0 NULL NULL NULL NULL 3 +0 NULL NULL NULL NULL 4 +0 NULL NULL NULL NULL 5 +SELECT origid as `from`, linkid as `to` FROM graph where latch='0' and origid = 1; +from to +1 3 +1 2 +SELECT origid as `from`, linkid as `to` FROM graph where latch='0' and origid = 2; +from to +2 1 +SELECT origid as `from`, linkid as `to` FROM graph where latch='0' and origid = 4; +from to +4 3 +SELECT origid as `from`, linkid as `to` FROM graph where latch='0' and origid = 9; +from to +9 9 +SELECT origid as `from`, linkid as `to` FROM graph where latch='0' and origid = 10; +from to +10 11 +SELECT linkid as `from`, destid as `to` FROM graph where latch='0' and destid = 1; +from to +3 1 +2 1 +SELECT linkid as `from`, destid as `to` FROM graph where latch='0' and destid = 2; +from to +1 2 +SELECT linkid as `from`, destid as `to` FROM graph where latch='0' and destid = 4; +from to +3 4 +SELECT linkid as `from`, destid as `to` FROM graph where latch='0' and destid = 9; +from to +9 9 +SELECT linkid as `from`, destid as `to` FROM graph where latch='0' and destid = 10; +from to +12 10 +# Breadth-first search tests +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 1; +latch origid destid weight seq linkid +breadth_first 1 NULL 2 4 4 +breadth_first 1 NULL 1 3 3 +breadth_first 1 NULL 1 2 2 +breadth_first 1 NULL 0 1 1 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 2; +latch origid destid weight seq linkid +breadth_first 2 NULL 3 4 4 +breadth_first 2 NULL 2 3 3 +breadth_first 2 NULL 1 2 1 +breadth_first 2 NULL 0 1 2 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 3; +latch origid destid weight seq linkid +breadth_first 3 NULL 2 4 2 +breadth_first 3 NULL 1 3 4 +breadth_first 3 NULL 1 2 1 +breadth_first 3 NULL 0 1 3 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 4; +latch origid destid weight seq linkid +breadth_first 4 NULL 3 4 2 +breadth_first 4 NULL 2 3 1 +breadth_first 4 NULL 1 2 3 +breadth_first 4 NULL 0 1 4 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 5; +latch origid destid weight seq linkid +breadth_first 5 NULL 1 3 7 +breadth_first 5 NULL 1 2 6 +breadth_first 5 NULL 0 1 5 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 6; +latch origid destid weight seq linkid +breadth_first 6 NULL 2 3 7 +breadth_first 6 NULL 1 2 5 +breadth_first 6 NULL 0 1 6 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 7; +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 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 9; +latch origid destid weight seq linkid +breadth_first 9 NULL 0 1 9 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 10; +latch origid destid weight seq linkid +breadth_first 10 NULL 2 3 12 +breadth_first 10 NULL 1 2 11 +breadth_first 10 NULL 0 1 10 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 11; +latch origid destid weight seq linkid +breadth_first 11 NULL 2 3 10 +breadth_first 11 NULL 1 2 12 +breadth_first 11 NULL 0 1 11 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 12; +latch origid destid weight seq linkid +breadth_first 12 NULL 2 3 11 +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 +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 +breadth_first 1 NULL 1 2 2 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 2 AND weight = 1; +latch origid destid weight seq linkid +breadth_first 2 NULL 1 2 1 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 3 AND weight = 1; +latch origid destid weight seq linkid +breadth_first 3 NULL 1 3 4 +breadth_first 3 NULL 1 2 1 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 4 AND weight = 1; +latch origid destid weight seq linkid +breadth_first 4 NULL 1 2 3 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 5 AND weight = 1; +latch origid destid weight seq linkid +breadth_first 5 NULL 1 3 7 +breadth_first 5 NULL 1 2 6 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 6 AND weight = 1; +latch origid destid weight seq linkid +breadth_first 6 NULL 1 2 5 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 7 AND weight = 1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 8 AND weight = 1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 9 AND weight = 1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 10 AND weight = 1; +latch origid destid weight seq linkid +breadth_first 10 NULL 1 2 11 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 11 AND weight = 1; +latch origid destid weight seq linkid +breadth_first 11 NULL 1 2 12 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 12 AND weight = 1; +latch origid destid weight seq linkid +breadth_first 12 NULL 1 2 10 +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 1 AND weight = 1; +count(*) +2 +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 2 AND weight = 1; +count(*) +1 +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 3 AND weight = 1; +count(*) +2 +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 4 AND weight = 1; +count(*) +1 +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 5 AND weight = 1; +count(*) +2 +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 6 AND weight = 1; +count(*) +1 +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 7 AND weight = 1; +count(*) +0 +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 8 AND weight = 1; +count(*) +0 +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 9 AND weight = 1; +count(*) +0 +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 10 AND weight = 1; +count(*) +1 +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 11 AND weight = 1; +count(*) +1 +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 12 AND weight = 1; +count(*) +1 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 1 AND weight = 2; +latch origid destid weight seq linkid +breadth_first 1 NULL 2 4 4 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 2 AND weight = 2; +latch origid destid weight seq linkid +breadth_first 2 NULL 2 3 3 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 3 AND weight = 2; +latch origid destid weight seq linkid +breadth_first 3 NULL 2 4 2 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 4 AND weight = 2; +latch origid destid weight seq linkid +breadth_first 4 NULL 2 3 1 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 5 AND weight = 2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 6 AND weight = 2; +latch origid destid weight seq linkid +breadth_first 6 NULL 2 3 7 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 7 AND weight = 2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 8 AND weight = 2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 9 AND weight = 2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 10 AND weight = 2; +latch origid destid weight seq linkid +breadth_first 10 NULL 2 3 12 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 11 AND weight = 2; +latch origid destid weight seq linkid +breadth_first 11 NULL 2 3 10 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 12 AND weight = 2; +latch origid destid weight seq linkid +breadth_first 12 NULL 2 3 11 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 1 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 2 AND weight = 3; +latch origid destid weight seq linkid +breadth_first 2 NULL 3 4 4 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 3 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 4 AND weight = 3; +latch origid destid weight seq linkid +breadth_first 4 NULL 3 4 2 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 5 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 6 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 7 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 8 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 9 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 10 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 11 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 12 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 1 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +breadth_first 1 NULL 2 4 4 +breadth_first 1 NULL 1 3 3 +breadth_first 1 NULL 1 2 2 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 2 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +breadth_first 2 NULL 2 3 3 +breadth_first 2 NULL 1 2 1 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 3 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +breadth_first 3 NULL 2 4 2 +breadth_first 3 NULL 1 3 4 +breadth_first 3 NULL 1 2 1 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 4 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +breadth_first 4 NULL 2 3 1 +breadth_first 4 NULL 1 2 3 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 5 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +breadth_first 5 NULL 1 3 7 +breadth_first 5 NULL 1 2 6 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 6 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +breadth_first 6 NULL 2 3 7 +breadth_first 6 NULL 1 2 5 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 7 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 8 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 9 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 10 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +breadth_first 10 NULL 2 3 12 +breadth_first 10 NULL 1 2 11 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 11 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +breadth_first 11 NULL 2 3 10 +breadth_first 11 NULL 1 2 12 +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 12 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +breadth_first 12 NULL 2 3 11 +breadth_first 12 NULL 1 2 10 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 1; +latch origid destid weight seq linkid +breadth_first NULL 1 2 4 4 +breadth_first NULL 1 1 3 3 +breadth_first NULL 1 1 2 2 +breadth_first NULL 1 0 1 1 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 2; +latch origid destid weight seq linkid +breadth_first NULL 2 3 4 4 +breadth_first NULL 2 2 3 3 +breadth_first NULL 2 1 2 1 +breadth_first NULL 2 0 1 2 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 3; +latch origid destid weight seq linkid +breadth_first NULL 3 2 4 2 +breadth_first NULL 3 1 3 4 +breadth_first NULL 3 1 2 1 +breadth_first NULL 3 0 1 3 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 4; +latch origid destid weight seq linkid +breadth_first NULL 4 3 4 2 +breadth_first NULL 4 2 3 1 +breadth_first NULL 4 1 2 3 +breadth_first NULL 4 0 1 4 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 5; +latch origid destid weight seq linkid +breadth_first NULL 5 1 2 6 +breadth_first NULL 5 0 1 5 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 6; +latch origid destid weight seq linkid +breadth_first NULL 6 1 2 5 +breadth_first NULL 6 0 1 6 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 7; +latch origid destid weight seq linkid +breadth_first NULL 7 2 3 6 +breadth_first NULL 7 1 2 5 +breadth_first NULL 7 0 1 7 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 8; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 9; +latch origid destid weight seq linkid +breadth_first NULL 9 0 1 9 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 10; +latch origid destid weight seq linkid +breadth_first NULL 10 2 3 11 +breadth_first NULL 10 1 2 12 +breadth_first NULL 10 0 1 10 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 11; +latch origid destid weight seq linkid +breadth_first NULL 11 2 3 12 +breadth_first NULL 11 1 2 10 +breadth_first NULL 11 0 1 11 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 12; +latch origid destid weight seq linkid +breadth_first NULL 12 2 3 10 +breadth_first NULL 12 1 2 11 +breadth_first NULL 12 0 1 12 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 1 and weight = 1; +latch origid destid weight seq linkid +breadth_first NULL 1 1 3 3 +breadth_first NULL 1 1 2 2 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 2 and weight = 1; +latch origid destid weight seq linkid +breadth_first NULL 2 1 2 1 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 3 and weight = 1; +latch origid destid weight seq linkid +breadth_first NULL 3 1 3 4 +breadth_first NULL 3 1 2 1 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 4 and weight = 1; +latch origid destid weight seq linkid +breadth_first NULL 4 1 2 3 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 5 and weight = 1; +latch origid destid weight seq linkid +breadth_first NULL 5 1 2 6 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 6 and weight = 1; +latch origid destid weight seq linkid +breadth_first NULL 6 1 2 5 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 7 and weight = 1; +latch origid destid weight seq linkid +breadth_first NULL 7 1 2 5 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 8 and weight = 1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 9 and weight = 1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 10 and weight = 1; +latch origid destid weight seq linkid +breadth_first NULL 10 1 2 12 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 11 and weight = 1; +latch origid destid weight seq linkid +breadth_first NULL 11 1 2 10 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 12 and weight = 1; +latch origid destid weight seq linkid +breadth_first NULL 12 1 2 11 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 1 and weight = 2; +latch origid destid weight seq linkid +breadth_first NULL 1 2 4 4 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 2 and weight = 2; +latch origid destid weight seq linkid +breadth_first NULL 2 2 3 3 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 3 and weight = 2; +latch origid destid weight seq linkid +breadth_first NULL 3 2 4 2 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 4 and weight = 2; +latch origid destid weight seq linkid +breadth_first NULL 4 2 3 1 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 5 and weight = 2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 6 and weight = 2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 7 and weight = 2; +latch origid destid weight seq linkid +breadth_first NULL 7 2 3 6 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 8 and weight = 2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 9 and weight = 2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 10 and weight = 2; +latch origid destid weight seq linkid +breadth_first NULL 10 2 3 11 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 11 and weight = 2; +latch origid destid weight seq linkid +breadth_first NULL 11 2 3 12 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 12 and weight = 2; +latch origid destid weight seq linkid +breadth_first NULL 12 2 3 10 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 1 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 2 and weight = 3; +latch origid destid weight seq linkid +breadth_first NULL 2 3 4 4 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 3 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 4 and weight = 3; +latch origid destid weight seq linkid +breadth_first NULL 4 3 4 2 +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 5 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 6 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 7 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 8 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 9 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 10 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 11 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 12 and weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = NULL; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = NULL; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND weight = 1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = 'breadth_first'; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 1; +latch origid destid weight seq linkid +2 1 NULL 2 4 4 +2 1 NULL 1 3 3 +2 1 NULL 1 2 2 +2 1 NULL 0 1 1 +SELECT * FROM graph WHERE latch = '2' AND origid = 2; +latch origid destid weight seq linkid +2 2 NULL 3 4 4 +2 2 NULL 2 3 3 +2 2 NULL 1 2 1 +2 2 NULL 0 1 2 +SELECT * FROM graph WHERE latch = '2' AND origid = 3; +latch origid destid weight seq linkid +2 3 NULL 2 4 2 +2 3 NULL 1 3 4 +2 3 NULL 1 2 1 +2 3 NULL 0 1 3 +SELECT * FROM graph WHERE latch = '2' AND origid = 4; +latch origid destid weight seq linkid +2 4 NULL 3 4 2 +2 4 NULL 2 3 1 +2 4 NULL 1 2 3 +2 4 NULL 0 1 4 +SELECT * FROM graph WHERE latch = '2' AND origid = 5; +latch origid destid weight seq linkid +2 5 NULL 1 3 7 +2 5 NULL 1 2 6 +2 5 NULL 0 1 5 +SELECT * FROM graph WHERE latch = '2' AND origid = 6; +latch origid destid weight seq linkid +2 6 NULL 2 3 7 +2 6 NULL 1 2 5 +2 6 NULL 0 1 6 +SELECT * FROM graph WHERE latch = '2' AND origid = 7; +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 +SELECT * FROM graph WHERE latch = '2' AND origid = 9; +latch origid destid weight seq linkid +2 9 NULL 0 1 9 +SELECT * FROM graph WHERE latch = '2' AND origid = 10; +latch origid destid weight seq linkid +2 10 NULL 2 3 12 +2 10 NULL 1 2 11 +2 10 NULL 0 1 10 +SELECT * FROM graph WHERE latch = '2' AND origid = 11; +latch origid destid weight seq linkid +2 11 NULL 2 3 10 +2 11 NULL 1 2 12 +2 11 NULL 0 1 11 +SELECT * FROM graph WHERE latch = '2' AND origid = 12; +latch origid destid weight seq linkid +2 12 NULL 2 3 11 +2 12 NULL 1 2 10 +2 12 NULL 0 1 12 +SELECT * FROM graph WHERE latch = '2' AND origid = 666; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 1 AND weight = 1; +latch origid destid weight seq linkid +2 1 NULL 1 3 3 +2 1 NULL 1 2 2 +SELECT * FROM graph WHERE latch = '2' AND origid = 2 AND weight = 1; +latch origid destid weight seq linkid +2 2 NULL 1 2 1 +SELECT * FROM graph WHERE latch = '2' AND origid = 3 AND weight = 1; +latch origid destid weight seq linkid +2 3 NULL 1 3 4 +2 3 NULL 1 2 1 +SELECT * FROM graph WHERE latch = '2' AND origid = 4 AND weight = 1; +latch origid destid weight seq linkid +2 4 NULL 1 2 3 +SELECT * FROM graph WHERE latch = '2' AND origid = 5 AND weight = 1; +latch origid destid weight seq linkid +2 5 NULL 1 3 7 +2 5 NULL 1 2 6 +SELECT * FROM graph WHERE latch = '2' AND origid = 6 AND weight = 1; +latch origid destid weight seq linkid +2 6 NULL 1 2 5 +SELECT * FROM graph WHERE latch = '2' AND origid = 7 AND weight = 1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 8 AND weight = 1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 9 AND weight = 1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 10 AND weight = 1; +latch origid destid weight seq linkid +2 10 NULL 1 2 11 +SELECT * FROM graph WHERE latch = '2' AND origid = 11 AND weight = 1; +latch origid destid weight seq linkid +2 11 NULL 1 2 12 +SELECT * FROM graph WHERE latch = '2' AND origid = 12 AND weight = 1; +latch origid destid weight seq linkid +2 12 NULL 1 2 10 +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 1 AND weight = 1; +count(*) +2 +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 2 AND weight = 1; +count(*) +1 +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 3 AND weight = 1; +count(*) +2 +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 4 AND weight = 1; +count(*) +1 +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 5 AND weight = 1; +count(*) +2 +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 6 AND weight = 1; +count(*) +1 +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 7 AND weight = 1; +count(*) +0 +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 8 AND weight = 1; +count(*) +0 +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 9 AND weight = 1; +count(*) +0 +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 10 AND weight = 1; +count(*) +1 +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 11 AND weight = 1; +count(*) +1 +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 12 AND weight = 1; +count(*) +1 +SELECT * FROM graph WHERE latch = '2' AND origid = 1 AND weight = 2; +latch origid destid weight seq linkid +2 1 NULL 2 4 4 +SELECT * FROM graph WHERE latch = '2' AND origid = 2 AND weight = 2; +latch origid destid weight seq linkid +2 2 NULL 2 3 3 +SELECT * FROM graph WHERE latch = '2' AND origid = 3 AND weight = 2; +latch origid destid weight seq linkid +2 3 NULL 2 4 2 +SELECT * FROM graph WHERE latch = '2' AND origid = 4 AND weight = 2; +latch origid destid weight seq linkid +2 4 NULL 2 3 1 +SELECT * FROM graph WHERE latch = '2' AND origid = 5 AND weight = 2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 6 AND weight = 2; +latch origid destid weight seq linkid +2 6 NULL 2 3 7 +SELECT * FROM graph WHERE latch = '2' AND origid = 7 AND weight = 2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 8 AND weight = 2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 9 AND weight = 2; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 10 AND weight = 2; +latch origid destid weight seq linkid +2 10 NULL 2 3 12 +SELECT * FROM graph WHERE latch = '2' AND origid = 11 AND weight = 2; +latch origid destid weight seq linkid +2 11 NULL 2 3 10 +SELECT * FROM graph WHERE latch = '2' AND origid = 12 AND weight = 2; +latch origid destid weight seq linkid +2 12 NULL 2 3 11 +SELECT * FROM graph WHERE latch = '2' AND origid = 1 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 2 AND weight = 3; +latch origid destid weight seq linkid +2 2 NULL 3 4 4 +SELECT * FROM graph WHERE latch = '2' AND origid = 3 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 4 AND weight = 3; +latch origid destid weight seq linkid +2 4 NULL 3 4 2 +SELECT * FROM graph WHERE latch = '2' AND origid = 5 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 6 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 7 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 8 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 9 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 10 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 11 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 12 AND weight = 3; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 1 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +2 1 NULL 2 4 4 +2 1 NULL 1 3 3 +2 1 NULL 1 2 2 +SELECT * FROM graph WHERE latch = '2' AND origid = 2 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +2 2 NULL 2 3 3 +2 2 NULL 1 2 1 +SELECT * FROM graph WHERE latch = '2' AND origid = 3 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +2 3 NULL 2 4 2 +2 3 NULL 1 3 4 +2 3 NULL 1 2 1 +SELECT * FROM graph WHERE latch = '2' AND origid = 4 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +2 4 NULL 2 3 1 +2 4 NULL 1 2 3 +SELECT * FROM graph WHERE latch = '2' AND origid = 5 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +2 5 NULL 1 3 7 +2 5 NULL 1 2 6 +SELECT * FROM graph WHERE latch = '2' AND origid = 6 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +2 6 NULL 2 3 7 +2 6 NULL 1 2 5 +SELECT * FROM graph WHERE latch = '2' AND origid = 7 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 8 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 9 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND origid = 10 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +2 10 NULL 2 3 12 +2 10 NULL 1 2 11 +SELECT * FROM graph WHERE latch = '2' AND origid = 11 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +2 11 NULL 2 3 10 +2 11 NULL 1 2 12 +SELECT * FROM graph WHERE latch = '2' AND origid = 12 AND (weight = 1 or weight = 2); +latch origid destid weight seq linkid +2 12 NULL 2 3 11 +2 12 NULL 1 2 10 +SELECT * FROM graph WHERE latch = '2' AND destid = 1; +latch origid destid weight seq linkid +2 NULL 1 2 4 4 +2 NULL 1 1 3 3 +2 NULL 1 1 2 2 +2 NULL 1 0 1 1 +SELECT * FROM graph WHERE latch = '2' AND destid = 12; +latch origid destid weight seq linkid +2 NULL 12 2 3 10 +2 NULL 12 1 2 11 +2 NULL 12 0 1 12 +SELECT * FROM graph WHERE latch = '2' AND destid = 1 and weight = 1; +latch origid destid weight seq linkid +2 NULL 1 1 3 3 +2 NULL 1 1 2 2 +SELECT * FROM graph WHERE latch = '2' AND origid = NULL; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND destid = NULL; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2' AND weight = 1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch = '2'; +latch origid destid weight seq linkid +# Dijkstras algorithm tests +SELECT * FROM graph WHERE latch='dijkstras' AND origid=1 AND destid=1; +latch origid destid weight seq linkid +dijkstras 1 1 NULL 0 1 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=1 AND destid=2; +latch origid destid weight seq linkid +dijkstras 1 2 NULL 0 1 +dijkstras 1 2 1 1 2 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=2 AND destid=1; +latch origid destid weight seq linkid +dijkstras 2 1 NULL 0 2 +dijkstras 2 1 1 1 1 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=1 AND destid=4; +latch origid destid weight seq linkid +dijkstras 1 4 NULL 0 1 +dijkstras 1 4 1 1 3 +dijkstras 1 4 1 2 4 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=4 AND destid=1; +latch origid destid weight seq linkid +dijkstras 4 1 NULL 0 4 +dijkstras 4 1 1 1 3 +dijkstras 4 1 1 2 1 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=1 AND destid=5; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch='dijkstras' AND origid=1 AND destid=666; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch='dijkstras' AND origid=5 AND destid=7; +latch origid destid weight seq linkid +dijkstras 5 7 NULL 0 5 +dijkstras 5 7 1 1 7 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=7 AND destid=5; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch='dijkstras' AND origid=10 AND destid=11; +latch origid destid weight seq linkid +dijkstras 10 11 NULL 0 10 +dijkstras 10 11 1 1 11 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=10 AND destid=12; +latch origid destid weight seq linkid +dijkstras 10 12 NULL 0 10 +dijkstras 10 12 1 1 11 +dijkstras 10 12 1 2 12 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=11 AND destid=10; +latch origid destid weight seq linkid +dijkstras 11 10 NULL 0 11 +dijkstras 11 10 1 1 12 +dijkstras 11 10 1 2 10 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=11 AND destid=12; +latch origid destid weight seq linkid +dijkstras 11 12 NULL 0 11 +dijkstras 11 12 1 1 12 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=12 AND destid=10; +latch origid destid weight seq linkid +dijkstras 12 10 NULL 0 12 +dijkstras 12 10 1 1 10 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=12 AND destid=11; +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 2 4 4 +dijkstras 1 NULL 1 3 3 +dijkstras 1 NULL 1 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 3 4 4 +dijkstras 2 NULL 2 3 3 +dijkstras 2 NULL 1 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 2 4 2 +dijkstras 3 NULL 1 3 4 +dijkstras 3 NULL 1 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 3 4 2 +dijkstras 4 NULL 2 3 1 +dijkstras 4 NULL 1 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 1 3 7 +dijkstras 5 NULL 1 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 2 3 7 +dijkstras 6 NULL 1 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 +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 2 3 12 +dijkstras 10 NULL 1 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 2 3 10 +dijkstras 11 NULL 1 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 2 3 11 +dijkstras 12 NULL 1 2 10 +dijkstras 12 NULL 0 1 12 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=666; +latch origid destid weight seq linkid +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 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 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 2 3 6 +dijkstras NULL 7 1 2 5 +dijkstras NULL 7 0 1 7 +SELECT * FROM graph WHERE latch='dijkstras' AND destid=8; +latch origid destid weight seq linkid +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 11 +dijkstras NULL 10 1 2 12 +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 12 +dijkstras NULL 11 1 2 10 +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 10 +dijkstras NULL 12 1 2 11 +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 +1 1 1 NULL 0 1 +SELECT * FROM graph WHERE latch='1' AND origid=1 AND destid=2; +latch origid destid weight seq linkid +1 1 2 NULL 0 1 +1 1 2 1 1 2 +SELECT * FROM graph WHERE latch='1' AND origid=2 AND destid=1; +latch origid destid weight seq linkid +1 2 1 NULL 0 2 +1 2 1 1 1 1 +SELECT * FROM graph WHERE latch='1' AND origid=1 AND destid=4; +latch origid destid weight seq linkid +1 1 4 NULL 0 1 +1 1 4 1 1 3 +1 1 4 1 2 4 +SELECT * FROM graph WHERE latch='1' AND origid=4 AND destid=1; +latch origid destid weight seq linkid +1 4 1 NULL 0 4 +1 4 1 1 1 3 +1 4 1 1 2 1 +SELECT * FROM graph WHERE latch='1' AND origid=1 AND destid=5; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch='1' AND origid=1 AND destid=666; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch='1' AND origid=5 AND destid=7; +latch origid destid weight seq linkid +1 5 7 NULL 0 5 +1 5 7 1 1 7 +SELECT * FROM graph WHERE latch='1' AND origid=7 AND destid=5; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch='1' AND origid=10 AND destid=11; +latch origid destid weight seq linkid +1 10 11 NULL 0 10 +1 10 11 1 1 11 +SELECT * FROM graph WHERE latch='1' AND origid=10 AND destid=12; +latch origid destid weight seq linkid +1 10 12 NULL 0 10 +1 10 12 1 1 11 +1 10 12 1 2 12 +SELECT * FROM graph WHERE latch='1' AND origid=11 AND destid=10; +latch origid destid weight seq linkid +1 11 10 NULL 0 11 +1 11 10 1 1 12 +1 11 10 1 2 10 +SELECT * FROM graph WHERE latch='1' AND origid=11 AND destid=12; +latch origid destid weight seq linkid +1 11 12 NULL 0 11 +1 11 12 1 1 12 +SELECT * FROM graph WHERE latch='1' AND origid=12 AND destid=10; +latch origid destid weight seq linkid +1 12 10 NULL 0 12 +1 12 10 1 1 10 +SELECT * FROM graph WHERE latch='1' AND origid=12 AND destid=11; +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 2 4 4 +1 1 NULL 1 3 3 +1 1 NULL 1 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 3 4 4 +1 2 NULL 2 3 3 +1 2 NULL 1 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 2 4 2 +1 3 NULL 1 3 4 +1 3 NULL 1 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 3 4 2 +1 4 NULL 2 3 1 +1 4 NULL 1 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 1 3 7 +1 5 NULL 1 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 2 3 7 +1 6 NULL 1 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 +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 2 3 12 +1 10 NULL 1 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 2 3 10 +1 11 NULL 1 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 2 3 11 +1 12 NULL 1 2 10 +1 12 NULL 0 1 12 +SELECT * FROM graph WHERE latch='1' AND origid=666; +latch origid destid weight seq linkid +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 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 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 2 3 6 +1 NULL 7 1 2 5 +1 NULL 7 0 1 7 +SELECT * FROM graph WHERE latch='1' AND destid=8; +latch origid destid weight seq linkid +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 11 +1 NULL 10 1 2 12 +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 12 +1 NULL 11 1 2 10 +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 10 +1 NULL 12 1 2 11 +1 NULL 12 0 1 12 +SELECT count(*) FROM graph; +count(*) +13 +SELECT count(*) FROM graph_base; +count(*) +13 +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); +SELECT * FROM graph WHERE latch='dijkstras' AND origid=10 AND destid=13; +latch origid destid weight seq linkid +dijkstras 10 13 NULL 0 10 +dijkstras 10 13 1 1 11 +dijkstras 10 13 1 2 13 +DELETE FROM graph_base where from_id=10 and to_id=11; +INSERT INTO graph_base(from_id, to_id) VALUES (10,15); +INSERT INTO graph_base(from_id, to_id) VALUES (15,13); +SELECT * FROM graph WHERE latch='dijkstras' AND origid=10 AND destid=13; +latch origid destid weight seq linkid +dijkstras 10 13 NULL 0 10 +dijkstras 10 13 1 1 14 +dijkstras 10 13 1 2 13 +INSERT INTO graph_base(from_id, to_id) VALUES (10,11); +SELECT * FROM graph WHERE latch='dijkstras' AND origid=10 AND destid=13; +latch origid destid weight seq linkid +dijkstras 10 13 NULL 0 10 +dijkstras 10 13 1 1 11 +dijkstras 10 13 1 2 13 +SELECT count(*) FROM graph; +count(*) +18 +SELECT count(*) FROM graph_base; +count(*) +18 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=1; +latch origid destid weight seq linkid +dijkstras 1 NULL 2 4 4 +dijkstras 1 NULL 1 3 3 +dijkstras 1 NULL 1 2 2 +dijkstras 1 NULL 0 1 1 +INSERT INTO graph_base(from_id, to_id) VALUES (21,22); +SELECT * FROM graph WHERE latch='dijkstras' AND origid=21; +latch origid destid weight seq linkid +dijkstras 21 NULL 1 2 22 +dijkstras 21 NULL 0 1 21 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=22; +latch origid destid weight seq linkid +dijkstras 22 NULL 0 1 22 +INSERT INTO graph_base(from_id, to_id) VALUES (4,17); +SELECT * FROM graph WHERE latch='dijkstras' AND origid=1; +latch origid destid weight seq linkid +dijkstras 1 NULL 3 5 17 +dijkstras 1 NULL 2 4 4 +dijkstras 1 NULL 1 3 3 +dijkstras 1 NULL 1 2 2 +dijkstras 1 NULL 0 1 1 +INSERT INTO graph_base(from_id, to_id) VALUES (4,16); +SELECT * FROM graph WHERE latch='dijkstras' AND origid=1; +latch origid destid weight seq linkid +dijkstras 1 NULL 3 6 17 +dijkstras 1 NULL 3 5 16 +dijkstras 1 NULL 2 4 4 +dijkstras 1 NULL 1 3 3 +dijkstras 1 NULL 1 2 2 +dijkstras 1 NULL 0 1 1 +INSERT INTO graph_base(from_id, to_id) VALUES (17,18); +SELECT * FROM graph WHERE latch='dijkstras' AND origid=1; +latch origid destid weight seq linkid +dijkstras 1 NULL 4 7 18 +dijkstras 1 NULL 3 6 17 +dijkstras 1 NULL 3 5 16 +dijkstras 1 NULL 2 4 4 +dijkstras 1 NULL 1 3 3 +dijkstras 1 NULL 1 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 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); +SELECT * FROM graph; +latch origid destid weight seq linkid +NULL 1 2 1 NULL NULL +NULL 2 1 1 NULL NULL +NULL 1 3 1 NULL NULL +NULL 3 1 1 NULL NULL +NULL 3 4 1 NULL NULL +NULL 4 3 1 NULL NULL +NULL 5 6 1 NULL NULL +NULL 6 5 1 NULL NULL +NULL 5 7 1 NULL NULL +NULL 9 9 1 NULL NULL +NULL 10 15 1 NULL NULL +NULL 11 12 1 NULL NULL +NULL 12 10 1 NULL NULL +NULL 11 13 1 NULL NULL +NULL 10 14 1 NULL NULL +NULL 14 13 1 NULL NULL +NULL 15 13 1 NULL NULL +NULL 10 11 1 NULL NULL +NULL 21 22 1 NULL NULL +NULL 4 17 1 NULL NULL +NULL 4 16 1 NULL NULL +NULL 17 18 1 NULL NULL +NULL 4 6 1 NULL NULL +SELECT count(*) FROM graph; +count(*) +23 +SELECT count(*) FROM graph_base; +count(*) +23 +# And delete all references to node 5 +DELETE FROM graph_base WHERE from_id=5; +DELETE FROM graph_base WHERE from_id=3 AND to_id=5; +# which means there is a path in one direction only 1>3>4>6 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=1 AND destid=6; +latch origid destid weight seq linkid +dijkstras 1 6 NULL 0 1 +dijkstras 1 6 1 1 3 +dijkstras 1 6 1 2 4 +dijkstras 1 6 1 3 6 +# but not 6>4>3>1 (so no result) +SELECT * FROM graph WHERE latch='dijkstras' AND origid=6 AND destid=1; +latch origid destid weight seq linkid +SELECT * FROM graph WHERE latch='1' AND origid=1 AND destid=6; +latch origid destid weight seq linkid +1 1 6 NULL 0 1 +1 1 6 1 1 3 +1 1 6 1 2 4 +1 1 6 1 3 6 +SELECT * FROM graph WHERE latch='1' AND origid=6 AND destid=1; +latch origid destid weight seq linkid +DELETE FROM graph_base; +FLUSH TABLES; +TRUNCATE TABLE graph_base; +DROP TABLE graph_base; +DROP TABLE graph; diff --git a/storage/oqgraph/mysql-test/oqgraph/regression_1213120.test b/storage/oqgraph/mysql-test/oqgraph/regression_1213120.test new file mode 100644 index 00000000..0f11f91c --- /dev/null +++ b/storage/oqgraph/mysql-test/oqgraph/regression_1213120.test @@ -0,0 +1,548 @@ +--disable_warnings +DROP TABLE IF EXISTS graph_base; +DROP TABLE IF EXISTS graph; +DROP TABLE IF EXISTS graph2; +--enable_warnings + +# Create the backing store +CREATE TABLE graph_base ( + from_id INT UNSIGNED NOT NULL, + to_id INT UNSIGNED NOT NULL, + PRIMARY KEY (from_id,to_id), + INDEX (to_id) + ) ENGINE=MyISAM; + + +CREATE TABLE graph ( + latch VARCHAR(32) NULL, + origid BIGINT UNSIGNED NULL, + destid BIGINT UNSIGNED NULL, + weight DOUBLE NULL, + seq BIGINT UNSIGNED NULL, + linkid BIGINT UNSIGNED NULL, + KEY (latch, origid, destid) USING HASH, + KEY (latch, destid, origid) USING HASH + ) ENGINE=OQGRAPH DATA_TABLE='graph_base' ORIGID='from_id', DESTID='to_id'; + +#-- +#-- ASCII art graph of this test data +#-- +-->(2) +#-- ( )<---+ +#-- (1) +#-- ( )<---+ +#-- +-->(3)<------->(4) +#-- +#-- (7)<----------(5)<--------->(6) (9) +#-- +#-- +--->(11) +#-- | | +#-- (10) | +#-- ^ v +#-- +----(12) + +INSERT INTO graph_base(from_id, to_id) VALUES (1,2), (2,1); +INSERT INTO graph_base(from_id, to_id) VALUES (1,3), (3,1); +INSERT INTO graph_base(from_id, to_id) VALUES (3,4), (4,3); +INSERT INTO graph_base(from_id, to_id) VALUES (5,6), (6,5); + +#-- extra unidirected node +INSERT INTO graph_base(from_id, to_id) VALUES (5,7); + +#-- isolated node with no loop - disallowed +#-- so origid 8 below should return an empty rowset +#-- INSERT INTO graph_base(from_id, to_id) VALUES (8,NULL); + +#-- isolated node with a (undirected) loop +#-- we have no way of representing a directed loop on an isolated node, is this valid in pure graph theory? +INSERT INTO graph_base(from_id, to_id) VALUES (9,9); + +#-- directed _cyclic_ graph triangle? +INSERT INTO graph_base(from_id, to_id) VALUES (10,11); +INSERT INTO graph_base(from_id, to_id) VALUES (11,12); +INSERT INTO graph_base(from_id, to_id) VALUES (12,10); + +--echo # Return all edges +#-- we note that when weight is NULL it defaults to 1 +SELECT * FROM graph; +--echo # Currently count should be 13 +SELECT count(*) FROM graph; +SELECT count(*) FROM graph_base; + +--echo # Return all edges when latch is NULL - this is different to latch='' and same as no where clause +SELECT * FROM graph where latch is NULL; + +--echo # Return all vertices, and subsets of vertices +SELECT * FROM graph where latch=''; +SELECT * FROM graph where latch='0'; + +--echo # Currently count should be 11 + +SELECT count(*) FROM graph where latch=''; +#-- get a subset of vertices +SELECT * FROM graph where latch='' and linkid = 2; +SELECT * FROM graph where latch='' and (linkid > 2 and linkid < 6); +SELECT * FROM graph where latch='' and linkid = NULL; +SELECT * FROM graph where latch='' and linkid = 666; + +#-- Query out-edges for vertex (no_search AND origid=N) +SELECT origid as `from`, linkid as `to` FROM graph where latch='' and origid = 1; +SELECT origid as `from`, linkid as `to` FROM graph where latch='' and origid = 2; +SELECT origid as `from`, linkid as `to` FROM graph where latch='' and origid = 4; +SELECT origid as `from`, linkid as `to` FROM graph where latch='' and origid = 9; +SELECT origid as `from`, linkid as `to` FROM graph where latch='' and origid = 10; +SELECT origid as `from`, linkid as `to` FROM graph where latch='' and origid = NULL; +SELECT origid as `from`, linkid as `to` FROM graph where latch='' and origid = 666; + +#-- Query in-edges for vertex (no_search AND destid=N) +#-- linkid will have the other end +SELECT linkid as `from`, destid as `to` FROM graph where latch='' and destid = 1; +SELECT linkid as `from`, destid as `to` FROM graph where latch='' and destid = 2; +SELECT linkid as `from`, destid as `to` FROM graph where latch='' and destid = 4; +SELECT linkid as `from`, destid as `to` FROM graph where latch='' and destid = 9; +SELECT linkid as `from`, destid as `to` FROM graph where latch='' and destid = 10; +SELECT linkid as `from`, destid as `to` FROM graph where latch='' and destid = NULL; +SELECT linkid as `from`, destid as `to` FROM graph where latch='' and destid = 666; + +# The following returns a result that makes no sense... +#-- what happens when we combined orig and dest? +#-- Bug https://bugs.launchpad.net/oqgraph/+bug/1195778 +#SELECT * FROM graph where latch='' and origid = 1; +#SELECT * FROM graph where latch='' and destid = 2; +#SELECT * FROM graph where latch='' and origid=1 and destid = 2; + +SELECT * FROM graph where latch='0'; +SELECT count(*) FROM graph where latch='0'; +SELECT * FROM graph where latch='0' and linkid = 2; +SELECT * FROM graph where latch='0' and (linkid > 2 and linkid < 6); +SELECT origid as `from`, linkid as `to` FROM graph where latch='0' and origid = 1; +SELECT origid as `from`, linkid as `to` FROM graph where latch='0' and origid = 2; +SELECT origid as `from`, linkid as `to` FROM graph where latch='0' and origid = 4; +SELECT origid as `from`, linkid as `to` FROM graph where latch='0' and origid = 9; +SELECT origid as `from`, linkid as `to` FROM graph where latch='0' and origid = 10; +SELECT linkid as `from`, destid as `to` FROM graph where latch='0' and destid = 1; +SELECT linkid as `from`, destid as `to` FROM graph where latch='0' and destid = 2; +SELECT linkid as `from`, destid as `to` FROM graph where latch='0' and destid = 4; +SELECT linkid as `from`, destid as `to` FROM graph where latch='0' and destid = 9; +SELECT linkid as `from`, destid as `to` FROM graph where latch='0' and destid = 10; + +--echo # Breadth-first search tests +#-- We are asking "Is there a path from node 'origid' to (all) other nodes?" +#-- We return a row for each other node that is reachable, with its id in 'linkid' +#-- and the weight calculated as "How many _directed_ hops to get there" +#-- If there is no path from origid to another node then there is no row for that linkid +#-- 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; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 4; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 5; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 6; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 7; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 8; # <-- note, should return nothing +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 9; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 10; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 11; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 12; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 666; # <-- note, should return nothing +#-- The above results can then be filtered by weight, so the results should be a subset for the corresponding origid above +#-- so effectively, `AND weight=1` returns the neighbours of origid in linkid +#<----- orig test harness - still returns (breadth_first 1 NULL 1 3 3), (breadth_first 1 NULL 1 2 2) +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 1 AND weight = 1; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 2 AND weight = 1; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 3 AND weight = 1; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 4 AND weight = 1; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 5 AND weight = 1; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 6 AND weight = 1; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 7 AND weight = 1; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 8 AND weight = 1; # <-- note, should return nothing +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 9 AND weight = 1; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 10 AND weight = 1; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 11 AND weight = 1; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 12 AND weight = 1; +#-- so effectively, `count(... AND weight=1)` returns the number of _reachable_ immediate neighbours +#-- included because it allows human to quickly eyeball against the visual ASCII graph for correctness... +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 1 AND weight = 1; +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 2 AND weight = 1; +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 3 AND weight = 1; +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 4 AND weight = 1; +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 5 AND weight = 1; +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 6 AND weight = 1; +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 7 AND weight = 1; +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 8 AND weight = 1; # <-- note, should return nothing +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 9 AND weight = 1; +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 10 AND weight = 1; +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 11 AND weight = 1; +SELECT count(*) FROM graph WHERE latch = 'breadth_first' AND origid = 12 AND weight = 1; +#-- so effectively, `AND weight=2` returns the second-level neighbours of origid in linkid +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 1 AND weight = 2; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 2 AND weight = 2; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 3 AND weight = 2; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 4 AND weight = 2; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 5 AND weight = 2; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 6 AND weight = 2; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 7 AND weight = 2; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 8 AND weight = 2; # <-- note, should return nothing +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 9 AND weight = 2; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 10 AND weight = 2; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 11 AND weight = 2; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 12 AND weight = 2; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 1 AND weight = 3; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 2 AND weight = 3; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 3 AND weight = 3; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 4 AND weight = 3; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 5 AND weight = 3; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 6 AND weight = 3; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 7 AND weight = 3; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 8 AND weight = 3; # <-- note, should return nothing +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 9 AND weight = 3; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 10 AND weight = 3; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 11 AND weight = 3; +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 12 AND weight = 3; + +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 1 AND (weight = 1 or weight = 2); +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 2 AND (weight = 1 or weight = 2); +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 3 AND (weight = 1 or weight = 2); +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 4 AND (weight = 1 or weight = 2); +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 5 AND (weight = 1 or weight = 2); +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 6 AND (weight = 1 or weight = 2); +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 7 AND (weight = 1 or weight = 2); +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 8 AND (weight = 1 or weight = 2); # <-- note, should return nothing +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 9 AND (weight = 1 or weight = 2); +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 10 AND (weight = 1 or weight = 2); +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 11 AND (weight = 1 or weight = 2); +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 12 AND (weight = 1 or weight = 2); + +#-- now do it in reverse - using destid find originating vertices +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 1; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 2; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 3; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 4; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 5; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 6; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 7; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 8; # <-- note, should return nothing +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 9; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 10; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 11; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 12; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 1 and weight = 1; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 2 and weight = 1; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 3 and weight = 1; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 4 and weight = 1; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 5 and weight = 1; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 6 and weight = 1; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 7 and weight = 1; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 8 and weight = 1; # <-- note, should return nothing +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 9 and weight = 1; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 10 and weight = 1; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 11 and weight = 1; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 12 and weight = 1; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 1 and weight = 2; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 2 and weight = 2; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 3 and weight = 2; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 4 and weight = 2; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 5 and weight = 2; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 6 and weight = 2; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 7 and weight = 2; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 8 and weight = 2; # <-- note, should return nothing +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 9 and weight = 2; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 10 and weight = 2; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 11 and weight = 2; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 12 and weight = 2; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 1 and weight = 3; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 2 and weight = 3; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 3 and weight = 3; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 4 and weight = 3; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 5 and weight = 3; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 6 and weight = 3; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 7 and weight = 3; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 8 and weight = 3; # <-- note, should return nothing +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 9 and weight = 3; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 10 and weight = 3; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 11 and weight = 3; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 12 and weight = 3; + +#-- These return empty sets - origid or destid must be specified and non null to get a result set +SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = NULL; +SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = NULL; +SELECT * FROM graph WHERE latch = 'breadth_first' AND weight = 1; +SELECT * FROM graph WHERE latch = 'breadth_first'; + +#-- Repeat the above with legacy string +SELECT * FROM graph WHERE latch = '2' AND origid = 1; +SELECT * FROM graph WHERE latch = '2' AND origid = 2; +SELECT * FROM graph WHERE latch = '2' AND origid = 3; +SELECT * FROM graph WHERE latch = '2' AND origid = 4; +SELECT * FROM graph WHERE latch = '2' AND origid = 5; +SELECT * FROM graph WHERE latch = '2' AND origid = 6; +SELECT * FROM graph WHERE latch = '2' AND origid = 7; +SELECT * FROM graph WHERE latch = '2' AND origid = 8; # <-- note, should return nothing +SELECT * FROM graph WHERE latch = '2' AND origid = 9; +SELECT * FROM graph WHERE latch = '2' AND origid = 10; +SELECT * FROM graph WHERE latch = '2' AND origid = 11; +SELECT * FROM graph WHERE latch = '2' AND origid = 12; +SELECT * FROM graph WHERE latch = '2' AND origid = 666; # <-- note, should return nothing +SELECT * FROM graph WHERE latch = '2' AND origid = 1 AND weight = 1; +SELECT * FROM graph WHERE latch = '2' AND origid = 2 AND weight = 1; +SELECT * FROM graph WHERE latch = '2' AND origid = 3 AND weight = 1; +SELECT * FROM graph WHERE latch = '2' AND origid = 4 AND weight = 1; +SELECT * FROM graph WHERE latch = '2' AND origid = 5 AND weight = 1; +SELECT * FROM graph WHERE latch = '2' AND origid = 6 AND weight = 1; +SELECT * FROM graph WHERE latch = '2' AND origid = 7 AND weight = 1; +SELECT * FROM graph WHERE latch = '2' AND origid = 8 AND weight = 1; # <-- note, should return nothing +SELECT * FROM graph WHERE latch = '2' AND origid = 9 AND weight = 1; +SELECT * FROM graph WHERE latch = '2' AND origid = 10 AND weight = 1; +SELECT * FROM graph WHERE latch = '2' AND origid = 11 AND weight = 1; +SELECT * FROM graph WHERE latch = '2' AND origid = 12 AND weight = 1; +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 1 AND weight = 1; +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 2 AND weight = 1; +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 3 AND weight = 1; +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 4 AND weight = 1; +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 5 AND weight = 1; +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 6 AND weight = 1; +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 7 AND weight = 1; +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 8 AND weight = 1; # <-- note, should return nothing +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 9 AND weight = 1; +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 10 AND weight = 1; +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 11 AND weight = 1; +SELECT count(*) FROM graph WHERE latch = '2' AND origid = 12 AND weight = 1; +SELECT * FROM graph WHERE latch = '2' AND origid = 1 AND weight = 2; +SELECT * FROM graph WHERE latch = '2' AND origid = 2 AND weight = 2; +SELECT * FROM graph WHERE latch = '2' AND origid = 3 AND weight = 2; +SELECT * FROM graph WHERE latch = '2' AND origid = 4 AND weight = 2; +SELECT * FROM graph WHERE latch = '2' AND origid = 5 AND weight = 2; +SELECT * FROM graph WHERE latch = '2' AND origid = 6 AND weight = 2; +SELECT * FROM graph WHERE latch = '2' AND origid = 7 AND weight = 2; +SELECT * FROM graph WHERE latch = '2' AND origid = 8 AND weight = 2; # <-- note, should return nothing +SELECT * FROM graph WHERE latch = '2' AND origid = 9 AND weight = 2; +SELECT * FROM graph WHERE latch = '2' AND origid = 10 AND weight = 2; +SELECT * FROM graph WHERE latch = '2' AND origid = 11 AND weight = 2; +SELECT * FROM graph WHERE latch = '2' AND origid = 12 AND weight = 2; +SELECT * FROM graph WHERE latch = '2' AND origid = 1 AND weight = 3; +SELECT * FROM graph WHERE latch = '2' AND origid = 2 AND weight = 3; +SELECT * FROM graph WHERE latch = '2' AND origid = 3 AND weight = 3; +SELECT * FROM graph WHERE latch = '2' AND origid = 4 AND weight = 3; +SELECT * FROM graph WHERE latch = '2' AND origid = 5 AND weight = 3; +SELECT * FROM graph WHERE latch = '2' AND origid = 6 AND weight = 3; +SELECT * FROM graph WHERE latch = '2' AND origid = 7 AND weight = 3; +SELECT * FROM graph WHERE latch = '2' AND origid = 8 AND weight = 3; # <-- note, should return nothing +SELECT * FROM graph WHERE latch = '2' AND origid = 9 AND weight = 3; +SELECT * FROM graph WHERE latch = '2' AND origid = 10 AND weight = 3; +SELECT * FROM graph WHERE latch = '2' AND origid = 11 AND weight = 3; +SELECT * FROM graph WHERE latch = '2' AND origid = 12 AND weight = 3; + +SELECT * FROM graph WHERE latch = '2' AND origid = 1 AND (weight = 1 or weight = 2); +SELECT * FROM graph WHERE latch = '2' AND origid = 2 AND (weight = 1 or weight = 2); +SELECT * FROM graph WHERE latch = '2' AND origid = 3 AND (weight = 1 or weight = 2); +SELECT * FROM graph WHERE latch = '2' AND origid = 4 AND (weight = 1 or weight = 2); +SELECT * FROM graph WHERE latch = '2' AND origid = 5 AND (weight = 1 or weight = 2); +SELECT * FROM graph WHERE latch = '2' AND origid = 6 AND (weight = 1 or weight = 2); +SELECT * FROM graph WHERE latch = '2' AND origid = 7 AND (weight = 1 or weight = 2); +SELECT * FROM graph WHERE latch = '2' AND origid = 8 AND (weight = 1 or weight = 2); # <-- note, should return nothing +SELECT * FROM graph WHERE latch = '2' AND origid = 9 AND (weight = 1 or weight = 2); +SELECT * FROM graph WHERE latch = '2' AND origid = 10 AND (weight = 1 or weight = 2); +SELECT * FROM graph WHERE latch = '2' AND origid = 11 AND (weight = 1 or weight = 2); +SELECT * FROM graph WHERE latch = '2' AND origid = 12 AND (weight = 1 or weight = 2); + +SELECT * FROM graph WHERE latch = '2' AND destid = 1; + +SELECT * FROM graph WHERE latch = '2' AND destid = 12; +SELECT * FROM graph WHERE latch = '2' AND destid = 1 and weight = 1; + + +#-- These return empty sets - origid must be specified and non null to get a result set +SELECT * FROM graph WHERE latch = '2' AND origid = NULL; +SELECT * FROM graph WHERE latch = '2' AND destid = NULL; +SELECT * FROM graph WHERE latch = '2' AND weight = 1; +SELECT * FROM graph WHERE latch = '2'; + + +--echo # Dijkstras algorithm tests +#-- We ask 'What is the shortest path (if any) between 'origid' and 'destid' +#-- This returns the number of directed hops +1 (for the starting node) +#-- 'weight' is NULL for the starting point, or 1 +#-- 'linkid' is the way point id +#-- 'seq' is the distance of the waypoint from the start (counting from zero) +#-- the default order returned is waypoints out from the start +#-- zero hop (1 row) +SELECT * FROM graph WHERE latch='dijkstras' AND origid=1 AND destid=1; +#-- one hop +SELECT * FROM graph WHERE latch='dijkstras' AND origid=1 AND destid=2; +#-- one hop in reverse +SELECT * FROM graph WHERE latch='dijkstras' AND origid=2 AND destid=1; +#-- two hops (via 3) +SELECT * FROM graph WHERE latch='dijkstras' AND origid=1 AND destid=4; +#-- two hops in reverse direction +SELECT * FROM graph WHERE latch='dijkstras' AND origid=4 AND destid=1; +#-- no result (no connection) +SELECT * FROM graph WHERE latch='dijkstras' AND origid=1 AND destid=5; +#-- no result (no destination exists) +SELECT * FROM graph WHERE latch='dijkstras' AND origid=1 AND destid=666; + +#-- one hop on a unidirected link +SELECT * FROM graph WHERE latch='dijkstras' AND origid=5 AND destid=7; +#-- zero hop in reverse direction on a unidirected link +SELECT * FROM graph WHERE latch='dijkstras' AND origid=7 AND destid=5; + +#-- Trickery - what about the cyclic loop? +SELECT * FROM graph WHERE latch='dijkstras' AND origid=10 AND destid=11; +SELECT * FROM graph WHERE latch='dijkstras' AND origid=10 AND destid=12; +SELECT * FROM graph WHERE latch='dijkstras' AND origid=11 AND destid=10; +SELECT * FROM graph WHERE latch='dijkstras' AND origid=11 AND destid=12; +SELECT * FROM graph WHERE latch='dijkstras' AND origid=12 AND destid=10; +SELECT * FROM graph WHERE latch='dijkstras' AND origid=12 AND destid=11; + +#-- reachable vertices +SELECT * FROM graph WHERE latch='dijkstras' AND origid=1; +SELECT * FROM graph WHERE latch='dijkstras' AND origid=2; +SELECT * FROM graph WHERE latch='dijkstras' AND origid=3; +SELECT * FROM graph WHERE latch='dijkstras' AND origid=4; +SELECT * FROM graph WHERE latch='dijkstras' AND origid=5; +SELECT * FROM graph WHERE latch='dijkstras' AND origid=6; +SELECT * FROM graph WHERE latch='dijkstras' AND origid=7; +SELECT * FROM graph WHERE latch='dijkstras' AND origid=8; # <-- note, should return nothing +SELECT * FROM graph WHERE latch='dijkstras' AND origid=9; +SELECT * FROM graph WHERE latch='dijkstras' AND origid=10; +SELECT * FROM graph WHERE latch='dijkstras' AND origid=11; +SELECT * FROM graph WHERE latch='dijkstras' AND origid=12; +SELECT * FROM graph WHERE latch='dijkstras' AND origid=666; # <-- note, should return nothing + +#-- originating vertices +SELECT * FROM graph WHERE latch='dijkstras' AND destid=1; +SELECT * FROM graph WHERE latch='dijkstras' AND destid=2; +SELECT * FROM graph WHERE latch='dijkstras' AND destid=3; +SELECT * FROM graph WHERE latch='dijkstras' AND destid=4; +SELECT * FROM graph WHERE latch='dijkstras' AND destid=5; +SELECT * FROM graph WHERE latch='dijkstras' AND destid=6; +SELECT * FROM graph WHERE latch='dijkstras' AND destid=7; +SELECT * FROM graph WHERE latch='dijkstras' AND destid=8; # <-- note, should return nothing +SELECT * FROM graph WHERE latch='dijkstras' AND destid=9; +SELECT * FROM graph WHERE latch='dijkstras' AND destid=10; +SELECT * FROM graph WHERE latch='dijkstras' AND destid=11; +SELECT * FROM graph WHERE latch='dijkstras' AND destid=12; + +--echo # legacy string number +SELECT * FROM graph WHERE latch='1' AND origid=1 AND destid=1; +SELECT * FROM graph WHERE latch='1' AND origid=1 AND destid=2; +SELECT * FROM graph WHERE latch='1' AND origid=2 AND destid=1; +SELECT * FROM graph WHERE latch='1' AND origid=1 AND destid=4; +SELECT * FROM graph WHERE latch='1' AND origid=4 AND destid=1; +SELECT * FROM graph WHERE latch='1' AND origid=1 AND destid=5; +SELECT * FROM graph WHERE latch='1' AND origid=1 AND destid=666; # <-- note, should return nothing +SELECT * FROM graph WHERE latch='1' AND origid=5 AND destid=7; +SELECT * FROM graph WHERE latch='1' AND origid=7 AND destid=5; +SELECT * FROM graph WHERE latch='1' AND origid=10 AND destid=11; +SELECT * FROM graph WHERE latch='1' AND origid=10 AND destid=12; +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; +SELECT * FROM graph WHERE latch='1' AND origid=8; # <-- note, should return nothing +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; +SELECT * FROM graph WHERE latch='1' AND origid=666; # <-- note, should return nothing +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; +SELECT * FROM graph WHERE latch='1' AND destid=8; # <-- note, should return nothing +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; + +SELECT count(*) FROM graph; +SELECT count(*) FROM graph_base; + +#-- What if we add two equally valid two-hop paths? +#-- +#-- +#-- +--->(14)----------+ +#-- | v +#-- | +--->(11)---->(13) +#-- | | | +#-- +-(10) | +#-- ^ v +#-- +----(12) +#-- +#-- We note it chooses 10,11,13 but will it always? +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); +SELECT * FROM graph WHERE latch='dijkstras' AND origid=10 AND destid=13; +DELETE FROM graph_base where from_id=10 and to_id=11; +INSERT INTO graph_base(from_id, to_id) VALUES (10,15); +INSERT INTO graph_base(from_id, to_id) VALUES (15,13); +SELECT * FROM graph WHERE latch='dijkstras' AND origid=10 AND destid=13; +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; + +SELECT count(*) FROM graph; +SELECT count(*) FROM graph_base; + +#-- 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; +SELECT * FROM graph WHERE latch='dijkstras' AND origid=22; +INSERT INTO graph_base(from_id, to_id) VALUES (4,17); +SELECT * FROM graph WHERE latch='dijkstras' AND origid=1; +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; +SELECT * FROM graph WHERE latch='dijkstras' AND destid=1; + +--echo # Now we add a connection from 4->6 +INSERT INTO graph_base (from_id,to_id) VALUES (4,6); + +SELECT * FROM graph; + +SELECT count(*) FROM graph; +SELECT count(*) FROM graph_base; + +--echo # And delete all references to node 5 +DELETE FROM graph_base WHERE from_id=5; +DELETE FROM graph_base WHERE from_id=3 AND to_id=5; + +#-- The following queries would currently return incorrect results +#-- 6 rows instead of 21 +#-- Maybe manifestation of https://bugs.launchpad.net/oqgraph/+bug/796647 +#-- SELECT count(*) FROM graph; +#-- SELECT count(*) FROM graph_base; + +--echo # which means there is a path in one direction only 1>3>4>6 +SELECT * FROM graph WHERE latch='dijkstras' AND origid=1 AND destid=6; +--echo # but not 6>4>3>1 (so no result) +SELECT * FROM graph WHERE latch='dijkstras' AND origid=6 AND destid=1; + +SELECT * FROM graph WHERE latch='1' AND origid=1 AND destid=6; +SELECT * FROM graph WHERE latch='1' AND origid=6 AND destid=1; + +DELETE FROM graph_base; + +#-- The following line would hang mysqld currently, see bug https://bugs.launchpad.net/oqgraph/+bug/1195735 +#-- SELECT * FROM graph; + +FLUSH TABLES; +TRUNCATE TABLE graph_base; + +DROP TABLE graph_base; +DROP TABLE graph; + diff --git a/storage/oqgraph/mysql-test/oqgraph/regression_1233113.result b/storage/oqgraph/mysql-test/oqgraph/regression_1233113.result new file mode 100644 index 00000000..2b0ea4b2 --- /dev/null +++ b/storage/oqgraph/mysql-test/oqgraph/regression_1233113.result @@ -0,0 +1,26 @@ +DROP TABLE IF EXISTS graph_base; +DROP TABLE IF EXISTS graph; +call mtr.add_suppression("graph_base is open on delete"); +CREATE TABLE graph_base ( +from_id INT UNSIGNED NOT NULL, +to_id INT UNSIGNED NOT NULL, +PRIMARY KEY (from_id,to_id), +INDEX (to_id) +) ENGINE=MyISAM; +CREATE TABLE graph ( +latch VARCHAR(32) NULL, +origid BIGINT UNSIGNED NULL, +destid BIGINT UNSIGNED NULL, +weight DOUBLE NULL, +seq BIGINT UNSIGNED NULL, +linkid BIGINT UNSIGNED NULL, +KEY (latch, origid, destid) USING HASH, +KEY (latch, destid, origid) USING HASH +) ENGINE=OQGRAPH DATA_TABLE='graph_base' ORIGID='from_id', DESTID='to_id'; +INSERT INTO graph_base(from_id, to_id) VALUES (1,2), (2,1); +INSERT INTO graph_base(from_id, to_id) VALUES (3,2), (2,3); +INSERT INTO graph_base(from_id, to_id) VALUES (1,3), (3,1); +update graph set origid=123; +ERROR HY000: Table 'graph' is read only +DROP TABLE graph_base; +DROP TABLE graph; diff --git a/storage/oqgraph/mysql-test/oqgraph/regression_1233113.test b/storage/oqgraph/mysql-test/oqgraph/regression_1233113.test new file mode 100644 index 00000000..db53b2b3 --- /dev/null +++ b/storage/oqgraph/mysql-test/oqgraph/regression_1233113.test @@ -0,0 +1,40 @@ +--disable_warnings +DROP TABLE IF EXISTS graph_base; +DROP TABLE IF EXISTS graph; +--enable_warnings + +call mtr.add_suppression("graph_base is open on delete"); + +# Create the backing store +CREATE TABLE graph_base ( + from_id INT UNSIGNED NOT NULL, + to_id INT UNSIGNED NOT NULL, + PRIMARY KEY (from_id,to_id), + INDEX (to_id) + ) ENGINE=MyISAM; + + +CREATE TABLE graph ( + latch VARCHAR(32) NULL, + origid BIGINT UNSIGNED NULL, + destid BIGINT UNSIGNED NULL, + weight DOUBLE NULL, + seq BIGINT UNSIGNED NULL, + linkid BIGINT UNSIGNED NULL, + KEY (latch, origid, destid) USING HASH, + KEY (latch, destid, origid) USING HASH + ) ENGINE=OQGRAPH DATA_TABLE='graph_base' ORIGID='from_id', DESTID='to_id'; + + +INSERT INTO graph_base(from_id, to_id) VALUES (1,2), (2,1); +INSERT INTO graph_base(from_id, to_id) VALUES (3,2), (2,3); +INSERT INTO graph_base(from_id, to_id) VALUES (1,3), (3,1); + +# The following line crashes when MTR run with --gdb, see bug https://bugs.launchpad.net/oqgraph/+bug/1233113 +--error 1036 +update graph set origid=123; + +# Otherwise, MTR hangs on the next line +DROP TABLE graph_base; +DROP TABLE graph; + diff --git a/storage/oqgraph/mysql-test/oqgraph/regression_796647.result b/storage/oqgraph/mysql-test/oqgraph/regression_796647.result new file mode 100644 index 00000000..36bd00b8 --- /dev/null +++ b/storage/oqgraph/mysql-test/oqgraph/regression_796647.result @@ -0,0 +1,40 @@ +DROP TABLE IF EXISTS graph_base; +DROP TABLE IF EXISTS graph; +CREATE TABLE graph_base ( +von INT NOT NULL, +nach INT NOT NULL, +weight DOUBLE NOT NULL, +PRIMARY KEY (von,nach), +INDEX (von) +) ENGINE=MyISAM; +CREATE TABLE graph ( +latch VARCHAR(32) NULL, +origid BIGINT UNSIGNED NULL, +destid BIGINT UNSIGNED NULL, +weight DOUBLE NULL, +seq BIGINT UNSIGNED NULL, +linkid BIGINT UNSIGNED NULL, +KEY (latch, origid, destid) USING HASH, +KEY (latch, destid, origid) USING HASH +) ENGINE=OQGRAPH DATA_TABLE='graph_base' ORIGID='von' DESTID='nach' WEIGHT='weight'; +INSERT INTO graph_base(von,nach,weight) VALUES (3,5,2), (5,4,1), (5,6,1); +SELECT * FROM graph_base; +von nach weight +3 5 2 +5 4 1 +5 6 1 +SELECT * FROM graph; +latch origid destid weight seq linkid +NULL 3 5 2 NULL NULL +NULL 5 4 1 NULL NULL +NULL 5 6 1 NULL NULL +INSERT INTO graph_base(von,nach,weight) VALUES (6,3,1); +SELECT * FROM graph; +latch origid destid weight seq linkid +NULL 3 5 2 NULL NULL +NULL 5 4 1 NULL NULL +NULL 5 6 1 NULL NULL +NULL 6 3 1 NULL NULL +FLUSH TABLES; +DROP TABLE graph_base; +DROP TABLE graph; diff --git a/storage/oqgraph/mysql-test/oqgraph/regression_796647.test b/storage/oqgraph/mysql-test/oqgraph/regression_796647.test new file mode 100644 index 00000000..aaecee74 --- /dev/null +++ b/storage/oqgraph/mysql-test/oqgraph/regression_796647.test @@ -0,0 +1,43 @@ +--disable_warnings +DROP TABLE IF EXISTS graph_base; +DROP TABLE IF EXISTS graph; +--enable_warnings + + +# Create the backing store +CREATE TABLE graph_base ( + von INT NOT NULL, + nach INT NOT NULL, + weight DOUBLE NOT NULL, + PRIMARY KEY (von,nach), + INDEX (von) + ) ENGINE=MyISAM; + + +CREATE TABLE graph ( + latch VARCHAR(32) NULL, + origid BIGINT UNSIGNED NULL, + destid BIGINT UNSIGNED NULL, + weight DOUBLE NULL, + seq BIGINT UNSIGNED NULL, + linkid BIGINT UNSIGNED NULL, + KEY (latch, origid, destid) USING HASH, + KEY (latch, destid, origid) USING HASH + ) ENGINE=OQGRAPH DATA_TABLE='graph_base' ORIGID='von' DESTID='nach' WEIGHT='weight'; + +INSERT INTO graph_base(von,nach,weight) VALUES (3,5,2), (5,4,1), (5,6,1); + +SELECT * FROM graph_base; + +SELECT * FROM graph; + +INSERT INTO graph_base(von,nach,weight) VALUES (6,3,1); + +SELECT * FROM graph; + +FLUSH TABLES; + +DROP TABLE graph_base; +DROP TABLE graph; + + diff --git a/storage/oqgraph/mysql-test/oqgraph/regression_796647b.result b/storage/oqgraph/mysql-test/oqgraph/regression_796647b.result new file mode 100644 index 00000000..2a5e632b --- /dev/null +++ b/storage/oqgraph/mysql-test/oqgraph/regression_796647b.result @@ -0,0 +1,221 @@ +DROP TABLE IF EXISTS graph_base; +DROP TABLE IF EXISTS graph; +CREATE TABLE graph_base ( +from_id INT UNSIGNED NOT NULL, +to_id INT UNSIGNED NOT NULL, +PRIMARY KEY (from_id,to_id), +INDEX (to_id) +) ENGINE=MyISAM; +CREATE TABLE graph ( +latch VARCHAR(32) NULL, +origid BIGINT UNSIGNED NULL, +destid BIGINT UNSIGNED NULL, +weight DOUBLE NULL, +seq BIGINT UNSIGNED NULL, +linkid BIGINT UNSIGNED NULL, +KEY (latch, origid, destid) USING HASH, +KEY (latch, destid, origid) USING HASH +) ENGINE=OQGRAPH DATA_TABLE='graph_base' ORIGID='from_id', DESTID='to_id'; +INSERT INTO graph_base(from_id, to_id) VALUES (1,2), (2,1); +INSERT INTO graph_base(from_id, to_id) VALUES (1,3), (3,1); +INSERT INTO graph_base(from_id, to_id) VALUES (3,4), (4,3); +INSERT INTO graph_base(from_id, to_id) VALUES (5,6), (6,5); +SELECT count(*) FROM graph; +count(*) +8 +SELECT count(*) FROM graph_base; +count(*) +8 +INSERT INTO graph_base(from_id, to_id) VALUES (5,7); +INSERT INTO graph_base(from_id, to_id) VALUES (9,9); +INSERT INTO graph_base(from_id, to_id) VALUES (10,11); +INSERT INTO graph_base(from_id, to_id) VALUES (11,12); +INSERT INTO graph_base(from_id, to_id) VALUES (12,10); +SELECT count(*) FROM graph; +count(*) +13 +SELECT count(*) FROM graph_base; +count(*) +13 +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); +SELECT count(*) FROM graph; +count(*) +16 +SELECT count(*) FROM graph_base; +count(*) +16 +DELETE FROM graph_base where from_id=10 and to_id=11; +INSERT INTO graph_base(from_id, to_id) VALUES (10,15); +INSERT INTO graph_base(from_id, to_id) VALUES (15,13); +INSERT INTO graph_base(from_id, to_id) VALUES (10,11); +SELECT count(*) FROM graph; +count(*) +18 +SELECT count(*) FROM graph_base; +count(*) +18 +INSERT INTO graph_base(from_id, to_id) VALUES (21,22); +INSERT INTO graph_base(from_id, to_id) VALUES (4,17); +INSERT INTO graph_base(from_id, to_id) VALUES (4,16); +INSERT INTO graph_base(from_id, to_id) VALUES (17,18); +INSERT INTO graph_base (from_id,to_id) VALUES (4,6); +SELECT count(*) FROM graph; +count(*) +23 +SELECT count(*) FROM graph_base; +count(*) +23 +SELECT * from graph; +latch origid destid weight seq linkid +NULL 1 2 1 NULL NULL +NULL 2 1 1 NULL NULL +NULL 1 3 1 NULL NULL +NULL 3 1 1 NULL NULL +NULL 3 4 1 NULL NULL +NULL 4 3 1 NULL NULL +NULL 5 6 1 NULL NULL +NULL 6 5 1 NULL NULL +NULL 5 7 1 NULL NULL +NULL 9 9 1 NULL NULL +NULL 10 15 1 NULL NULL +NULL 11 12 1 NULL NULL +NULL 12 10 1 NULL NULL +NULL 11 13 1 NULL NULL +NULL 10 14 1 NULL NULL +NULL 14 13 1 NULL NULL +NULL 15 13 1 NULL NULL +NULL 10 11 1 NULL NULL +NULL 21 22 1 NULL NULL +NULL 4 17 1 NULL NULL +NULL 4 16 1 NULL NULL +NULL 17 18 1 NULL NULL +NULL 4 6 1 NULL NULL +SELECT * from graph where latch='0'; +latch origid destid weight seq linkid +0 NULL NULL NULL NULL 1 +0 NULL NULL NULL NULL 2 +0 NULL NULL NULL NULL 3 +0 NULL NULL NULL NULL 4 +0 NULL NULL NULL NULL 5 +0 NULL NULL NULL NULL 6 +0 NULL NULL NULL NULL 7 +0 NULL NULL NULL NULL 9 +0 NULL NULL NULL NULL 10 +0 NULL NULL NULL NULL 15 +0 NULL NULL NULL NULL 11 +0 NULL NULL NULL NULL 12 +0 NULL NULL NULL NULL 13 +0 NULL NULL NULL NULL 14 +0 NULL NULL NULL NULL 21 +0 NULL NULL NULL NULL 22 +0 NULL NULL NULL NULL 17 +0 NULL NULL NULL NULL 16 +0 NULL NULL NULL NULL 18 +SELECT * from graph_base; +from_id to_id +1 2 +1 3 +2 1 +3 1 +3 4 +4 3 +4 6 +4 16 +4 17 +5 6 +5 7 +6 5 +9 9 +10 11 +10 14 +10 15 +11 12 +11 13 +12 10 +14 13 +15 13 +17 18 +21 22 +# And delete all references to node 5 +DELETE FROM graph_base WHERE from_id=5; +DELETE FROM graph_base WHERE from_id=3 AND to_id=5; +# This is currently bogus: +SELECT count(*) FROM graph; +count(*) +21 +SELECT count(*) FROM graph_base; +count(*) +21 +SELECT * from graph; +latch origid destid weight seq linkid +NULL 1 2 1 NULL NULL +NULL 2 1 1 NULL NULL +NULL 1 3 1 NULL NULL +NULL 3 1 1 NULL NULL +NULL 3 4 1 NULL NULL +NULL 4 3 1 NULL NULL +NULL 6 5 1 NULL NULL +NULL 9 9 1 NULL NULL +NULL 10 15 1 NULL NULL +NULL 11 12 1 NULL NULL +NULL 12 10 1 NULL NULL +NULL 11 13 1 NULL NULL +NULL 10 14 1 NULL NULL +NULL 14 13 1 NULL NULL +NULL 15 13 1 NULL NULL +NULL 10 11 1 NULL NULL +NULL 21 22 1 NULL NULL +NULL 4 17 1 NULL NULL +NULL 4 16 1 NULL NULL +NULL 17 18 1 NULL NULL +NULL 4 6 1 NULL NULL +SELECT * from graph where latch='0'; +latch origid destid weight seq linkid +0 NULL NULL NULL NULL 1 +0 NULL NULL NULL NULL 2 +0 NULL NULL NULL NULL 3 +0 NULL NULL NULL NULL 4 +0 NULL NULL NULL NULL 6 +0 NULL NULL NULL NULL 5 +0 NULL NULL NULL NULL 9 +0 NULL NULL NULL NULL 10 +0 NULL NULL NULL NULL 15 +0 NULL NULL NULL NULL 11 +0 NULL NULL NULL NULL 12 +0 NULL NULL NULL NULL 13 +0 NULL NULL NULL NULL 14 +0 NULL NULL NULL NULL 21 +0 NULL NULL NULL NULL 22 +0 NULL NULL NULL NULL 17 +0 NULL NULL NULL NULL 16 +0 NULL NULL NULL NULL 18 +SELECT * from graph_base; +from_id to_id +1 2 +1 3 +2 1 +3 1 +3 4 +4 3 +4 6 +4 16 +4 17 +6 5 +9 9 +10 11 +10 14 +10 15 +11 12 +11 13 +12 10 +14 13 +15 13 +17 18 +21 22 +DELETE FROM graph_base; +FLUSH TABLES; +TRUNCATE TABLE graph_base; +DROP TABLE graph_base; +DROP TABLE graph; diff --git a/storage/oqgraph/mysql-test/oqgraph/regression_796647b.test b/storage/oqgraph/mysql-test/oqgraph/regression_796647b.test new file mode 100644 index 00000000..c3b81fd0 --- /dev/null +++ b/storage/oqgraph/mysql-test/oqgraph/regression_796647b.test @@ -0,0 +1,97 @@ +--disable_warnings +DROP TABLE IF EXISTS graph_base; +DROP TABLE IF EXISTS graph; +--enable_warnings + +# Create the backing store +CREATE TABLE graph_base ( + from_id INT UNSIGNED NOT NULL, + to_id INT UNSIGNED NOT NULL, + PRIMARY KEY (from_id,to_id), + INDEX (to_id) + ) ENGINE=MyISAM; + + +CREATE TABLE graph ( + latch VARCHAR(32) NULL, + origid BIGINT UNSIGNED NULL, + destid BIGINT UNSIGNED NULL, + weight DOUBLE NULL, + seq BIGINT UNSIGNED NULL, + linkid BIGINT UNSIGNED NULL, + KEY (latch, origid, destid) USING HASH, + KEY (latch, destid, origid) USING HASH + ) ENGINE=OQGRAPH DATA_TABLE='graph_base' ORIGID='from_id', DESTID='to_id'; + +INSERT INTO graph_base(from_id, to_id) VALUES (1,2), (2,1); +INSERT INTO graph_base(from_id, to_id) VALUES (1,3), (3,1); +INSERT INTO graph_base(from_id, to_id) VALUES (3,4), (4,3); +INSERT INTO graph_base(from_id, to_id) VALUES (5,6), (6,5); + +SELECT count(*) FROM graph; +SELECT count(*) FROM graph_base; + +INSERT INTO graph_base(from_id, to_id) VALUES (5,7); +INSERT INTO graph_base(from_id, to_id) VALUES (9,9); +INSERT INTO graph_base(from_id, to_id) VALUES (10,11); +INSERT INTO graph_base(from_id, to_id) VALUES (11,12); +INSERT INTO graph_base(from_id, to_id) VALUES (12,10); + +SELECT count(*) FROM graph; +SELECT count(*) FROM graph_base; + +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); + +SELECT count(*) FROM graph; +SELECT count(*) FROM graph_base; + +DELETE FROM graph_base where from_id=10 and to_id=11; +INSERT INTO graph_base(from_id, to_id) VALUES (10,15); +INSERT INTO graph_base(from_id, to_id) VALUES (15,13); +INSERT INTO graph_base(from_id, to_id) VALUES (10,11); + +SELECT count(*) FROM graph; +SELECT count(*) FROM graph_base; + +INSERT INTO graph_base(from_id, to_id) VALUES (21,22); +INSERT INTO graph_base(from_id, to_id) VALUES (4,17); +INSERT INTO graph_base(from_id, to_id) VALUES (4,16); +INSERT INTO graph_base(from_id, to_id) VALUES (17,18); +INSERT INTO graph_base (from_id,to_id) VALUES (4,6); + +#-- Without this when the line immediately after gets executed +#-- we get a segfault +SELECT count(*) FROM graph; +SELECT count(*) FROM graph_base; +SELECT * from graph; +SELECT * from graph where latch='0'; +SELECT * from graph_base; + +--echo # And delete all references to node 5 +DELETE FROM graph_base WHERE from_id=5; +DELETE FROM graph_base WHERE from_id=3 AND to_id=5; + +#-- The following queries would currently return incorrect results +#-- 6 rows instead of 21 +#-- Maybe manifestation of https://bugs.launchpad.net/oqgraph/+bug/796647 +--echo # This is currently bogus: +SELECT count(*) FROM graph; +SELECT count(*) FROM graph_base; +SELECT * from graph; +SELECT * from graph where latch='0'; +SELECT * from graph_base; + +DELETE FROM graph_base; + +#-- The following line would hang mysqld currently, see bug https://bugs.launchpad.net/oqgraph/+bug/1195735 +#-- SELECT * FROM graph; + +FLUSH TABLES; +TRUNCATE TABLE graph_base; + +DROP TABLE graph_base; +DROP TABLE graph; + + diff --git a/storage/oqgraph/mysql-test/oqgraph/regression_796647c.result b/storage/oqgraph/mysql-test/oqgraph/regression_796647c.result new file mode 100644 index 00000000..d648e7ff --- /dev/null +++ b/storage/oqgraph/mysql-test/oqgraph/regression_796647c.result @@ -0,0 +1,127 @@ +DROP TABLE IF EXISTS graph_base; +DROP TABLE IF EXISTS graph; +CREATE TABLE graph_base ( +from_id INT UNSIGNED NOT NULL, +to_id INT UNSIGNED NOT NULL, +PRIMARY KEY (from_id,to_id), +INDEX (to_id) +) ENGINE=MyISAM; +CREATE TABLE graph ( +latch VARCHAR(32) NULL, +origid BIGINT UNSIGNED NULL, +destid BIGINT UNSIGNED NULL, +weight DOUBLE NULL, +seq BIGINT UNSIGNED NULL, +linkid BIGINT UNSIGNED NULL, +KEY (latch, origid, destid) USING HASH, +KEY (latch, destid, origid) USING HASH +) ENGINE=OQGRAPH DATA_TABLE='graph_base' ORIGID='from_id', DESTID='to_id'; +INSERT INTO graph_base(from_id, to_id) VALUES (1,2), (2,1); +SELECT count(*) FROM graph; +count(*) +2 +SELECT count(*) FROM graph_base; +count(*) +2 +INSERT INTO graph_base(from_id, to_id) VALUES (12,10); +SELECT count(*) FROM graph; +count(*) +3 +SELECT count(*) FROM graph_base; +count(*) +3 +INSERT INTO graph_base(from_id, to_id) VALUES (14,13); +SELECT count(*) FROM graph; +count(*) +4 +SELECT count(*) FROM graph_base; +count(*) +4 +DELETE FROM graph_base where from_id=10 and to_id=11; +INSERT INTO graph_base(from_id, to_id) VALUES (10,15); +INSERT INTO graph_base(from_id, to_id) VALUES (15,13); +INSERT INTO graph_base(from_id, to_id) VALUES (10,11); +SELECT count(*) FROM graph; +count(*) +7 +SELECT count(*) FROM graph_base; +count(*) +7 +INSERT INTO graph_base(from_id, to_id) VALUES (21,22); +INSERT INTO graph_base (from_id,to_id) VALUES (4,6); +SELECT count(*) FROM graph; +count(*) +9 +SELECT count(*) FROM graph_base; +count(*) +9 +SELECT * FROM graph where latch='0'; +latch origid destid weight seq linkid +0 NULL NULL NULL NULL 1 +0 NULL NULL NULL NULL 2 +0 NULL NULL NULL NULL 12 +0 NULL NULL NULL NULL 10 +0 NULL NULL NULL NULL 14 +0 NULL NULL NULL NULL 13 +0 NULL NULL NULL NULL 15 +0 NULL NULL NULL NULL 11 +0 NULL NULL NULL NULL 21 +0 NULL NULL NULL NULL 22 +0 NULL NULL NULL NULL 4 +0 NULL NULL NULL NULL 6 +SELECT * FROM graph_base; +from_id to_id +1 2 +2 1 +4 6 +10 11 +10 15 +12 10 +14 13 +15 13 +21 22 +# And delete all references to node 2 +DELETE FROM graph_base WHERE from_id=2; +DELETE FROM graph_base WHERE to_id=2; +SELECT count(*) FROM graph; +count(*) +7 +SELECT count(*) FROM graph_base; +count(*) +7 +SELECT * FROM graph where latch='0'; +latch origid destid weight seq linkid +0 NULL NULL NULL NULL 12 +0 NULL NULL NULL NULL 10 +0 NULL NULL NULL NULL 14 +0 NULL NULL NULL NULL 13 +0 NULL NULL NULL NULL 15 +0 NULL NULL NULL NULL 11 +0 NULL NULL NULL NULL 21 +0 NULL NULL NULL NULL 22 +0 NULL NULL NULL NULL 4 +0 NULL NULL NULL NULL 6 +SELECT * FROM graph_base; +from_id to_id +4 6 +10 11 +10 15 +12 10 +14 13 +15 13 +21 22 +DELETE FROM graph_base; +SELECT count(*) FROM graph; +count(*) +0 +SELECT count(*) FROM graph_base; +count(*) +0 +SELECT * FROM graph where latch='0'; +latch origid destid weight seq linkid +SELECT * FROM graph_base; +from_id to_id +FLUSH TABLES; +TRUNCATE TABLE graph_base; +DROP TABLE graph_base; +DROP TABLE graph; diff --git a/storage/oqgraph/mysql-test/oqgraph/regression_796647c.test b/storage/oqgraph/mysql-test/oqgraph/regression_796647c.test new file mode 100644 index 00000000..e0406122 --- /dev/null +++ b/storage/oqgraph/mysql-test/oqgraph/regression_796647c.test @@ -0,0 +1,84 @@ +--disable_warnings +DROP TABLE IF EXISTS graph_base; +DROP TABLE IF EXISTS graph; +--enable_warnings + +# Create the backing store +CREATE TABLE graph_base ( + from_id INT UNSIGNED NOT NULL, + to_id INT UNSIGNED NOT NULL, + PRIMARY KEY (from_id,to_id), + INDEX (to_id) + ) ENGINE=MyISAM; + + +CREATE TABLE graph ( + latch VARCHAR(32) NULL, + origid BIGINT UNSIGNED NULL, + destid BIGINT UNSIGNED NULL, + weight DOUBLE NULL, + seq BIGINT UNSIGNED NULL, + linkid BIGINT UNSIGNED NULL, + KEY (latch, origid, destid) USING HASH, + KEY (latch, destid, origid) USING HASH + ) ENGINE=OQGRAPH DATA_TABLE='graph_base' ORIGID='from_id', DESTID='to_id'; + +INSERT INTO graph_base(from_id, to_id) VALUES (1,2), (2,1); + +SELECT count(*) FROM graph; +SELECT count(*) FROM graph_base; + +INSERT INTO graph_base(from_id, to_id) VALUES (12,10); + +SELECT count(*) FROM graph; +SELECT count(*) FROM graph_base; + +INSERT INTO graph_base(from_id, to_id) VALUES (14,13); + +SELECT count(*) FROM graph; +SELECT count(*) FROM graph_base; + +DELETE FROM graph_base where from_id=10 and to_id=11; +INSERT INTO graph_base(from_id, to_id) VALUES (10,15); +INSERT INTO graph_base(from_id, to_id) VALUES (15,13); +INSERT INTO graph_base(from_id, to_id) VALUES (10,11); + +SELECT count(*) FROM graph; +SELECT count(*) FROM graph_base; + +INSERT INTO graph_base(from_id, to_id) VALUES (21,22); +INSERT INTO graph_base (from_id,to_id) VALUES (4,6); + +#-- Without this when the line immediately after gets executed +#-- we get a segfault +SELECT count(*) FROM graph; +SELECT count(*) FROM graph_base; +SELECT * FROM graph where latch='0'; +SELECT * FROM graph_base; + +--echo # And delete all references to node 2 +DELETE FROM graph_base WHERE from_id=2; +DELETE FROM graph_base WHERE to_id=2; + +SELECT count(*) FROM graph; +SELECT count(*) FROM graph_base; +SELECT * FROM graph where latch='0'; +SELECT * FROM graph_base; + +DELETE FROM graph_base; + +SELECT count(*) FROM graph; +SELECT count(*) FROM graph_base; +SELECT * FROM graph where latch='0'; +SELECT * FROM graph_base; + +#-- The following line would hang mysqld currently, see bug https://bugs.launchpad.net/oqgraph/+bug/1195735 +#-- SELECT * FROM graph; + +FLUSH TABLES; +TRUNCATE TABLE graph_base; + +DROP TABLE graph_base; +DROP TABLE graph; + + diff --git a/storage/oqgraph/mysql-test/oqgraph/regression_drop_after.result b/storage/oqgraph/mysql-test/oqgraph/regression_drop_after.result new file mode 100644 index 00000000..cace2c40 --- /dev/null +++ b/storage/oqgraph/mysql-test/oqgraph/regression_drop_after.result @@ -0,0 +1,29 @@ +DROP TABLE IF EXISTS graph_base; +DROP TABLE IF EXISTS graph; +call mtr.add_suppression("graph_base is open on delete"); +CREATE TABLE graph_base ( +from_id INT UNSIGNED NOT NULL, +to_id INT UNSIGNED NOT NULL, +PRIMARY KEY (from_id,to_id), +INDEX (to_id) +) ENGINE=MyISAM; +CREATE TABLE graph ( +latch VARCHAR(32) NULL, +origid BIGINT UNSIGNED NULL, +destid BIGINT UNSIGNED NULL, +weight DOUBLE NULL, +seq BIGINT UNSIGNED NULL, +linkid BIGINT UNSIGNED NULL, +KEY (latch, origid, destid) USING HASH, +KEY (latch, destid, origid) USING HASH +) ENGINE=OQGRAPH DATA_TABLE='graph_base' ORIGID='from_id', DESTID='to_id'; +INSERT INTO graph_base(from_id, to_id) VALUES (1,2), (2,1); +SELECT * FROM graph; +latch origid destid weight seq linkid +NULL 1 2 1 NULL NULL +NULL 2 1 1 NULL NULL +DROP TABLE graph_base; +FLUSH TABLES; +SELECT * FROM graph; +ERROR 42S02: Table 'test.graph_base' doesn't exist +DROP TABLE graph; diff --git a/storage/oqgraph/mysql-test/oqgraph/regression_drop_after.test b/storage/oqgraph/mysql-test/oqgraph/regression_drop_after.test new file mode 100644 index 00000000..673eb867 --- /dev/null +++ b/storage/oqgraph/mysql-test/oqgraph/regression_drop_after.test @@ -0,0 +1,40 @@ +--disable_warnings +DROP TABLE IF EXISTS graph_base; +DROP TABLE IF EXISTS graph; +--enable_warnings + +call mtr.add_suppression("graph_base is open on delete"); + +# Create the backing store +CREATE TABLE graph_base ( + from_id INT UNSIGNED NOT NULL, + to_id INT UNSIGNED NOT NULL, + PRIMARY KEY (from_id,to_id), + INDEX (to_id) + ) ENGINE=MyISAM; + + +CREATE TABLE graph ( + latch VARCHAR(32) NULL, + origid BIGINT UNSIGNED NULL, + destid BIGINT UNSIGNED NULL, + weight DOUBLE NULL, + seq BIGINT UNSIGNED NULL, + linkid BIGINT UNSIGNED NULL, + KEY (latch, origid, destid) USING HASH, + KEY (latch, destid, origid) USING HASH + ) ENGINE=OQGRAPH DATA_TABLE='graph_base' ORIGID='from_id', DESTID='to_id'; + + +INSERT INTO graph_base(from_id, to_id) VALUES (1,2), (2,1); +SELECT * FROM graph; +DROP TABLE graph_base; +FLUSH TABLES; # <-- without this, we still had it open so never see error... +--error S42S02 +SELECT * FROM graph; +DROP TABLE graph; + +# gdb script: +# bre ha_oqgraph::rnd_init +# ignore 1 1 +# run diff --git a/storage/oqgraph/mysql-test/oqgraph/regression_mdev5744.opt b/storage/oqgraph/mysql-test/oqgraph/regression_mdev5744.opt new file mode 100644 index 00000000..a4548161 --- /dev/null +++ b/storage/oqgraph/mysql-test/oqgraph/regression_mdev5744.opt @@ -0,0 +1 @@ +--query_cache_type=ON diff --git a/storage/oqgraph/mysql-test/oqgraph/regression_mdev5744.result b/storage/oqgraph/mysql-test/oqgraph/regression_mdev5744.result new file mode 100644 index 00000000..731c6726 --- /dev/null +++ b/storage/oqgraph/mysql-test/oqgraph/regression_mdev5744.result @@ -0,0 +1,42 @@ +DROP TABLE IF EXISTS graph_base; +DROP TABLE IF EXISTS graph; +call mtr.add_suppression("graph_base is open on delete"); +CREATE TABLE graph_base ( +from_id INT UNSIGNED NOT NULL, +to_id INT UNSIGNED NOT NULL, +PRIMARY KEY (from_id,to_id), +INDEX (to_id) +) ENGINE=MyISAM; +CREATE TABLE graph ( +latch VARCHAR(32) NULL, +origid BIGINT UNSIGNED NULL, +destid BIGINT UNSIGNED NULL, +weight DOUBLE NULL, +seq BIGINT UNSIGNED NULL, +linkid BIGINT UNSIGNED NULL, +KEY (latch, origid, destid) USING HASH, +KEY (latch, destid, origid) USING HASH +) ENGINE=OQGRAPH DATA_TABLE='graph_base' ORIGID='from_id', DESTID='to_id'; +INSERT INTO graph_base(from_id, to_id) VALUES (1,2), (2,1); +SET @query_cache_size.saved = @@query_cache_size; +SET GLOBAL query_cache_size = 1024*1024; +SELECT * FROM graph; +latch origid destid weight seq linkid +NULL 1 2 1 NULL NULL +NULL 2 1 1 NULL NULL +UPDATE graph_base SET to_id = 20 WHERE from_id = 1; +SELECT * FROM graph; +latch origid destid weight seq linkid +NULL 1 20 1 NULL NULL +NULL 2 1 1 NULL NULL +SELECT SQL_NO_CACHE * FROM graph; +latch origid destid weight seq linkid +NULL 1 20 1 NULL NULL +NULL 2 1 1 NULL NULL +SET GLOBAL query_cache_size = 0; +SELECT SQL_NO_CACHE * FROM graph; +latch origid destid weight seq linkid +NULL 1 20 1 NULL NULL +NULL 2 1 1 NULL NULL +DROP TABLE graph_base, graph; +SET GLOBAL query_cache_size = @query_cache_size.saved; diff --git a/storage/oqgraph/mysql-test/oqgraph/regression_mdev5744.test b/storage/oqgraph/mysql-test/oqgraph/regression_mdev5744.test new file mode 100644 index 00000000..19cbfe7d --- /dev/null +++ b/storage/oqgraph/mysql-test/oqgraph/regression_mdev5744.test @@ -0,0 +1,50 @@ +# Regression test for https://mariadb.atlassian.net/browse/MDEV-5744 +#--reproduce bug where changes to backing table data are not reflected +# in a graph table due to query caching + +--disable_warnings +DROP TABLE IF EXISTS graph_base; +DROP TABLE IF EXISTS graph; +--enable_warnings + +call mtr.add_suppression("graph_base is open on delete"); + +# Create the backing store +CREATE TABLE graph_base ( + from_id INT UNSIGNED NOT NULL, + to_id INT UNSIGNED NOT NULL, + PRIMARY KEY (from_id,to_id), + INDEX (to_id) + ) ENGINE=MyISAM; + + +CREATE TABLE graph ( + latch VARCHAR(32) NULL, + origid BIGINT UNSIGNED NULL, + destid BIGINT UNSIGNED NULL, + weight DOUBLE NULL, + seq BIGINT UNSIGNED NULL, + linkid BIGINT UNSIGNED NULL, + KEY (latch, origid, destid) USING HASH, + KEY (latch, destid, origid) USING HASH + ) ENGINE=OQGRAPH DATA_TABLE='graph_base' ORIGID='from_id', DESTID='to_id'; + + +INSERT INTO graph_base(from_id, to_id) VALUES (1,2), (2,1); + +SET @query_cache_size.saved = @@query_cache_size; +SET GLOBAL query_cache_size = 1024*1024; + +SELECT * FROM graph; +UPDATE graph_base SET to_id = 20 WHERE from_id = 1; + +SELECT * FROM graph; +SELECT SQL_NO_CACHE * FROM graph; + +SET GLOBAL query_cache_size = 0; + +SELECT SQL_NO_CACHE * FROM graph; + +DROP TABLE graph_base, graph; +SET GLOBAL query_cache_size = @query_cache_size.saved; + diff --git a/storage/oqgraph/mysql-test/oqgraph/regression_mdev5871.result b/storage/oqgraph/mysql-test/oqgraph/regression_mdev5871.result new file mode 100644 index 00000000..d2dfc46d --- /dev/null +++ b/storage/oqgraph/mysql-test/oqgraph/regression_mdev5871.result @@ -0,0 +1,86 @@ +DROP TABLE IF EXISTS graph_base; +DROP TABLE IF EXISTS graph; +CREATE TABLE graph_base ( +from_id INT UNSIGNED NOT NULL, +to_id INT UNSIGNED NOT NULL, +weight DOUBLE NOT NULL, +PRIMARY KEY (from_id,to_id), +INDEX (to_id) +) ENGINE=MyISAM; +CREATE TABLE graph ENGINE=OQGRAPH DATA_TABLE='graph_base' ORIGID='from_id' DESTID='to_id'; +DESCRIBE graph; +Field Type Null Key Default Extra +latch varchar(32) YES MUL NULL +origid bigint(20) unsigned YES NULL +destid bigint(20) unsigned YES NULL +weight double YES NULL +seq bigint(20) unsigned YES NULL +linkid bigint(20) unsigned YES NULL +DROP TABLE IF EXISTS graph; +CREATE TABLE graph ENGINE=OQGRAPH DATA_TABLE='graph_base' ORIGID='from_id' DESTID='to_id' WEIGHT='weight'; +DESCRIBE graph; +Field Type Null Key Default Extra +latch varchar(32) YES MUL NULL +origid bigint(20) unsigned YES NULL +destid bigint(20) unsigned YES NULL +weight double YES NULL +seq bigint(20) unsigned YES NULL +linkid bigint(20) unsigned YES NULL +DROP TABLE IF EXISTS graph; +CREATE TABLE graph ENGINE=OQGRAPH DATA_TABLE='graph_base_xxx' ORIGID='from_id' DESTID='to_id_xxx' WEIGHT='weight'; +# Expect 'Table 'test.graph_base_xxx' doesn't exist' +DESCRIBE graph; +ERROR 42S02: Table 'test.graph_base_xxx' doesn't exist +DROP TABLE IF EXISTS graph; +CREATE TABLE graph ENGINE=OQGRAPH DATA_TABLE='graph_base' ORIGID='from_id' DESTID='to_id' WEIGHT='weight_xxx'; +# Expect 'Invalid OQGRAPH backing store description ('graph.weight' attribute not set to a valid column of 'graph_base')' +DESCRIBE graph; +ERROR HY000: Got error -1 'Invalid OQGRAPH backing store ('graph.weight' attribute not set to a valid column of 'graph_base')' from OQGRAPH +DROP TABLE IF EXISTS graph; +CREATE TABLE graph ENGINE=OQGRAPH DATA_TABLE='graph_base' ORIGID='from_id' DESTID='to_id_xxx' WEIGHT='weight'; +# Expect 'Invalid OQGRAPH backing store description ('graph.destid' attribute not set to a valid column of 'graph_base')' +DESCRIBE graph; +ERROR HY000: Got error -1 'Invalid OQGRAPH backing store ('graph.destid' attribute not set to a valid column of 'graph_base')' from OQGRAPH +DROP TABLE IF EXISTS graph; +CREATE TABLE graph ENGINE=OQGRAPH DATA_TABLE='graph_base' ORIGID='from_id_xxx' DESTID='to_id' WEIGHT='weight'; +# Expect 'Invalid OQGRAPH backing store description ('graph.origid' attribute not set to a valid column of 'graph_base')' +DESCRIBE graph; +ERROR HY000: Got error -1 'Invalid OQGRAPH backing store ('graph.origid' attribute not set to a valid column of 'graph_base')' from OQGRAPH +DROP TABLE IF EXISTS graph; +CREATE TABLE graph ENGINE=OQGRAPH; +# Expect: 'Invalid OQGRAPH backing store description (unspecified or empty data_table attribute)' +DESCRIBE graph; +ERROR HY000: Got error -1 'Invalid OQGRAPH backing store description (unspecified or empty data_table attribute)' from OQGRAPH +DROP TABLE IF EXISTS graph; +CREATE TABLE graph ENGINE=OQGRAPH DATA_TABLE='graph_base'; +# Expect: 'Invalid OQGRAPH backing store description (unspecified or empty origid attribute)' +DESCRIBE graph; +ERROR HY000: Got error -1 'Invalid OQGRAPH backing store description (unspecified or empty origid attribute)' from OQGRAPH +DROP TABLE IF EXISTS graph; +CREATE TABLE graph ENGINE=OQGRAPH DATA_TABLE='graph_base' ORIGID='from_id'; +# Expect: 'Invalid OQGRAPH backing store description (unspecified or empty destid attribute)' +DESCRIBE graph; +ERROR HY000: Got error -1 'Invalid OQGRAPH backing store description (unspecified or empty destid attribute)' from OQGRAPH +DROP TABLE IF EXISTS graph; +CREATE TABLE graph ENGINE=OQGRAPH DATA_TABLE='graph_base' DESTID='to_id'; +# Expect: 'Invalid OQGRAPH backing store description (unspecified or empty origid attribute)' +DESCRIBE graph; +ERROR HY000: Got error -1 'Invalid OQGRAPH backing store description (unspecified or empty origid attribute)' from OQGRAPH +DROP TABLE IF EXISTS graph; +CREATE TABLE graph ENGINE=OQGRAPH ORIGID='from_id'; +# Expect: 'Invalid OQGRAPH backing store description (unspecified or empty data_table attribute)' +DESCRIBE graph; +ERROR HY000: Got error -1 'Invalid OQGRAPH backing store description (unspecified or empty data_table attribute)' from OQGRAPH +DROP TABLE IF EXISTS graph; +CREATE TABLE graph ENGINE=OQGRAPH DESTID='to_id'; +# Expect: 'Invalid OQGRAPH backing store description (unspecified or empty data_table attribute)' +DESCRIBE graph; +ERROR HY000: Got error -1 'Invalid OQGRAPH backing store description (unspecified or empty data_table attribute)' from OQGRAPH +DROP TABLE IF EXISTS graph; +CREATE TABLE graph ENGINE=OQGRAPH ORIGID='from_id', DESTID='to_id'; +# Expect: 'Invalid OQGRAPH backing store description (unspecified or empty data_table attribute)' +DESCRIBE graph; +ERROR HY000: Got error -1 'Invalid OQGRAPH backing store description (unspecified or empty data_table attribute)' from OQGRAPH +DROP TABLE IF EXISTS graph; +DROP TABLE IF EXISTS graph; +DROP TABLE IF EXISTS graph_base; diff --git a/storage/oqgraph/mysql-test/oqgraph/regression_mdev5871.test b/storage/oqgraph/mysql-test/oqgraph/regression_mdev5871.test new file mode 100644 index 00000000..15d1eff0 --- /dev/null +++ b/storage/oqgraph/mysql-test/oqgraph/regression_mdev5871.test @@ -0,0 +1,121 @@ +--disable_warnings +DROP TABLE IF EXISTS graph_base; +DROP TABLE IF EXISTS graph; +--enable_warnings + +CREATE TABLE graph_base ( + from_id INT UNSIGNED NOT NULL, + to_id INT UNSIGNED NOT NULL, + weight DOUBLE NOT NULL, + PRIMARY KEY (from_id,to_id), + INDEX (to_id) + ) ENGINE=MyISAM; + +# Since late June 2014 OQGraph supports 'assisted discovery' as per https://mariadb.atlassian.net/browse/MDEV-5871 + +CREATE TABLE graph ENGINE=OQGRAPH DATA_TABLE='graph_base' ORIGID='from_id' DESTID='to_id'; +DESCRIBE graph; +--disable_warnings +DROP TABLE IF EXISTS graph; +--enable_warnings + +CREATE TABLE graph ENGINE=OQGRAPH DATA_TABLE='graph_base' ORIGID='from_id' DESTID='to_id' WEIGHT='weight'; +DESCRIBE graph; +--disable_warnings +DROP TABLE IF EXISTS graph; +--enable_warnings + +CREATE TABLE graph ENGINE=OQGRAPH DATA_TABLE='graph_base_xxx' ORIGID='from_id' DESTID='to_id_xxx' WEIGHT='weight'; +--echo # Expect 'Table 'test.graph_base_xxx' doesn't exist' +--error 1146 +DESCRIBE graph; +--disable_warnings +DROP TABLE IF EXISTS graph; +--enable_warnings + +CREATE TABLE graph ENGINE=OQGRAPH DATA_TABLE='graph_base' ORIGID='from_id' DESTID='to_id' WEIGHT='weight_xxx'; +--echo # Expect 'Invalid OQGRAPH backing store description ('graph.weight' attribute not set to a valid column of 'graph_base')' +--error 1296 +DESCRIBE graph; +--disable_warnings +DROP TABLE IF EXISTS graph; +--enable_warnings + +CREATE TABLE graph ENGINE=OQGRAPH DATA_TABLE='graph_base' ORIGID='from_id' DESTID='to_id_xxx' WEIGHT='weight'; +--echo # Expect 'Invalid OQGRAPH backing store description ('graph.destid' attribute not set to a valid column of 'graph_base')' +--error 1296 +DESCRIBE graph; +--disable_warnings +DROP TABLE IF EXISTS graph; +--enable_warnings + +CREATE TABLE graph ENGINE=OQGRAPH DATA_TABLE='graph_base' ORIGID='from_id_xxx' DESTID='to_id' WEIGHT='weight'; +--echo # Expect 'Invalid OQGRAPH backing store description ('graph.origid' attribute not set to a valid column of 'graph_base')' +--error 1296 +DESCRIBE graph; +--disable_warnings +DROP TABLE IF EXISTS graph; +--enable_warnings + +# The following combinations should be invalid +CREATE TABLE graph ENGINE=OQGRAPH; +--echo # Expect: 'Invalid OQGRAPH backing store description (unspecified or empty data_table attribute)' +--error 1296 +DESCRIBE graph; +--disable_warnings +DROP TABLE IF EXISTS graph; +--enable_warnings + +CREATE TABLE graph ENGINE=OQGRAPH DATA_TABLE='graph_base'; +--echo # Expect: 'Invalid OQGRAPH backing store description (unspecified or empty origid attribute)' +--error 1296 +DESCRIBE graph; +--disable_warnings +DROP TABLE IF EXISTS graph; +--enable_warnings + +CREATE TABLE graph ENGINE=OQGRAPH DATA_TABLE='graph_base' ORIGID='from_id'; +--echo # Expect: 'Invalid OQGRAPH backing store description (unspecified or empty destid attribute)' +--error 1296 +DESCRIBE graph; +--disable_warnings +DROP TABLE IF EXISTS graph; +--enable_warnings + +CREATE TABLE graph ENGINE=OQGRAPH DATA_TABLE='graph_base' DESTID='to_id'; +--echo # Expect: 'Invalid OQGRAPH backing store description (unspecified or empty origid attribute)' +--error 1296 +DESCRIBE graph; +--disable_warnings +DROP TABLE IF EXISTS graph; +--enable_warnings + +CREATE TABLE graph ENGINE=OQGRAPH ORIGID='from_id'; +--echo # Expect: 'Invalid OQGRAPH backing store description (unspecified or empty data_table attribute)' +--error 1296 +DESCRIBE graph; +--disable_warnings +DROP TABLE IF EXISTS graph; +--enable_warnings + +CREATE TABLE graph ENGINE=OQGRAPH DESTID='to_id'; +--echo # Expect: 'Invalid OQGRAPH backing store description (unspecified or empty data_table attribute)' +--error 1296 +DESCRIBE graph; +--disable_warnings +DROP TABLE IF EXISTS graph; +--enable_warnings + +CREATE TABLE graph ENGINE=OQGRAPH ORIGID='from_id', DESTID='to_id'; +--echo # Expect: 'Invalid OQGRAPH backing store description (unspecified or empty data_table attribute)' +--error 1296 +DESCRIBE graph; +--disable_warnings +DROP TABLE IF EXISTS graph; +--enable_warnings + +--disable_warnings +DROP TABLE IF EXISTS graph; +DROP TABLE IF EXISTS graph_base; +--enable_warnings + diff --git a/storage/oqgraph/mysql-test/oqgraph/regression_mdev5996.inc b/storage/oqgraph/mysql-test/oqgraph/regression_mdev5996.inc new file mode 100644 index 00000000..c0e4aa75 --- /dev/null +++ b/storage/oqgraph/mysql-test/oqgraph/regression_mdev5996.inc @@ -0,0 +1,53 @@ +# Regression test for https://mariadb.atlassian.net/browse/MDEV-5996 +--echo Performing OQGraph regression test mdev5996 - using db=`$oqgraph_database_name`, table=`$oqgraph_table_name` + +--disable_warnings +use test; +if ($oqgraph_database_name) { + eval drop database if exists `$oqgraph_database_name` ; + eval create database `$oqgraph_database_name` ; + eval use `$oqgraph_database_name` ; +} +eval drop table if exists `$oqgraph_table_name` ; +drop table if exists vvvvvvv_hhhhhhh; +--enable_warnings + +eval CREATE TABLE `$oqgraph_table_name` ( + `version` varchar(10) NOT NULL, + `updateJSON` mediumtext, + `prevVersion` varchar(10) NOT NULL, + `nodeID` bigint(20) unsigned NOT NULL DEFAULT '0', + `prevNodeID` bigint(20) unsigned NOT NULL DEFAULT '0', + PRIMARY KEY (`prevNodeID`,`nodeID`), + KEY `prevVersion` (`prevVersion`) USING BTREE, + KEY `version` (`version`) USING BTREE, + KEY `nodeID` (`nodeID`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; + +eval insert into `$oqgraph_table_name` values ( 'x', 'y', 'z', 0, 0); + +eval select * from `$oqgraph_table_name`; + +eval CREATE TABLE IF NOT EXISTS vvvvvvv_hhhhhhh ( + latch VARCHAR(32) NULL, + origid BIGINT UNSIGNED NULL, + destid BIGINT UNSIGNED NULL, + weight DOUBLE NULL, + seq BIGINT UNSIGNED NULL, + linkid BIGINT UNSIGNED NULL, + KEY (latch, origid, destid) USING HASH, + KEY (latch, destid, origid) USING HASH +) ENGINE=OQGRAPH + data_table='$oqgraph_table_name' + origid='prevNodeID' + destid='nodeID'; + +select * from vvvvvvv_hhhhhhh; + +eval drop table if exists `$oqgraph_table_name`; +drop table if exists vvvvvvv_hhhhhhh; + +if ($oqgraph_database_name) { + eval drop database if exists `$oqgraph_database_name`; +} + diff --git a/storage/oqgraph/mysql-test/oqgraph/regression_mdev5996.result b/storage/oqgraph/mysql-test/oqgraph/regression_mdev5996.result new file mode 100644 index 00000000..39e476b2 --- /dev/null +++ b/storage/oqgraph/mysql-test/oqgraph/regression_mdev5996.result @@ -0,0 +1,284 @@ +call mtr.add_suppression("99999999 is open on delete"); +Performing OQGraph regression test mdev5996 - using db=``, table=`999999999` +use test; +drop table if exists `999999999` ; +drop table if exists vvvvvvv_hhhhhhh; +CREATE TABLE `999999999` ( +`version` varchar(10) NOT NULL, +`updateJSON` mediumtext, +`prevVersion` varchar(10) NOT NULL, +`nodeID` bigint(20) unsigned NOT NULL DEFAULT '0', +`prevNodeID` bigint(20) unsigned NOT NULL DEFAULT '0', +PRIMARY KEY (`prevNodeID`,`nodeID`), +KEY `prevVersion` (`prevVersion`) USING BTREE, +KEY `version` (`version`) USING BTREE, +KEY `nodeID` (`nodeID`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; +insert into `999999999` values ( 'x', 'y', 'z', 0, 0); +select * from `999999999`; +version updateJSON prevVersion nodeID prevNodeID +x y z 0 0 +CREATE TABLE IF NOT EXISTS vvvvvvv_hhhhhhh ( +latch VARCHAR(32) NULL, +origid BIGINT UNSIGNED NULL, +destid BIGINT UNSIGNED NULL, +weight DOUBLE NULL, +seq BIGINT UNSIGNED NULL, +linkid BIGINT UNSIGNED NULL, +KEY (latch, origid, destid) USING HASH, +KEY (latch, destid, origid) USING HASH +) ENGINE=OQGRAPH +data_table='999999999' + origid='prevNodeID' + destid='nodeID'; +select * from vvvvvvv_hhhhhhh; +latch origid destid weight seq linkid +NULL 0 0 1 NULL NULL +drop table if exists `999999999`; +drop table if exists vvvvvvv_hhhhhhh; +Performing OQGraph regression test mdev5996 - using db=`1`, table=`999999999` +use test; +drop database if exists `1` ; +create database `1` ; +use `1` ; +drop table if exists `999999999` ; +drop table if exists vvvvvvv_hhhhhhh; +CREATE TABLE `999999999` ( +`version` varchar(10) NOT NULL, +`updateJSON` mediumtext, +`prevVersion` varchar(10) NOT NULL, +`nodeID` bigint(20) unsigned NOT NULL DEFAULT '0', +`prevNodeID` bigint(20) unsigned NOT NULL DEFAULT '0', +PRIMARY KEY (`prevNodeID`,`nodeID`), +KEY `prevVersion` (`prevVersion`) USING BTREE, +KEY `version` (`version`) USING BTREE, +KEY `nodeID` (`nodeID`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; +insert into `999999999` values ( 'x', 'y', 'z', 0, 0); +select * from `999999999`; +version updateJSON prevVersion nodeID prevNodeID +x y z 0 0 +CREATE TABLE IF NOT EXISTS vvvvvvv_hhhhhhh ( +latch VARCHAR(32) NULL, +origid BIGINT UNSIGNED NULL, +destid BIGINT UNSIGNED NULL, +weight DOUBLE NULL, +seq BIGINT UNSIGNED NULL, +linkid BIGINT UNSIGNED NULL, +KEY (latch, origid, destid) USING HASH, +KEY (latch, destid, origid) USING HASH +) ENGINE=OQGRAPH +data_table='999999999' + origid='prevNodeID' + destid='nodeID'; +select * from vvvvvvv_hhhhhhh; +latch origid destid weight seq linkid +NULL 0 0 1 NULL NULL +drop table if exists `999999999`; +drop table if exists vvvvvvv_hhhhhhh; +drop database if exists `1`; +Performing OQGraph regression test mdev5996 - using db=`1112222233_4444444`, table=`999999999` +use test; +drop database if exists `1112222233_4444444` ; +create database `1112222233_4444444` ; +use `1112222233_4444444` ; +drop table if exists `999999999` ; +drop table if exists vvvvvvv_hhhhhhh; +CREATE TABLE `999999999` ( +`version` varchar(10) NOT NULL, +`updateJSON` mediumtext, +`prevVersion` varchar(10) NOT NULL, +`nodeID` bigint(20) unsigned NOT NULL DEFAULT '0', +`prevNodeID` bigint(20) unsigned NOT NULL DEFAULT '0', +PRIMARY KEY (`prevNodeID`,`nodeID`), +KEY `prevVersion` (`prevVersion`) USING BTREE, +KEY `version` (`version`) USING BTREE, +KEY `nodeID` (`nodeID`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; +insert into `999999999` values ( 'x', 'y', 'z', 0, 0); +select * from `999999999`; +version updateJSON prevVersion nodeID prevNodeID +x y z 0 0 +CREATE TABLE IF NOT EXISTS vvvvvvv_hhhhhhh ( +latch VARCHAR(32) NULL, +origid BIGINT UNSIGNED NULL, +destid BIGINT UNSIGNED NULL, +weight DOUBLE NULL, +seq BIGINT UNSIGNED NULL, +linkid BIGINT UNSIGNED NULL, +KEY (latch, origid, destid) USING HASH, +KEY (latch, destid, origid) USING HASH +) ENGINE=OQGRAPH +data_table='999999999' + origid='prevNodeID' + destid='nodeID'; +select * from vvvvvvv_hhhhhhh; +latch origid destid weight seq linkid +NULL 0 0 1 NULL NULL +drop table if exists `999999999`; +drop table if exists vvvvvvv_hhhhhhh; +drop database if exists `1112222233_4444444`; +Performing OQGraph regression test mdev5996 - using db=`1112222233_44444444`, table=`999999999` +use test; +drop database if exists `1112222233_44444444` ; +create database `1112222233_44444444` ; +use `1112222233_44444444` ; +drop table if exists `999999999` ; +drop table if exists vvvvvvv_hhhhhhh; +CREATE TABLE `999999999` ( +`version` varchar(10) NOT NULL, +`updateJSON` mediumtext, +`prevVersion` varchar(10) NOT NULL, +`nodeID` bigint(20) unsigned NOT NULL DEFAULT '0', +`prevNodeID` bigint(20) unsigned NOT NULL DEFAULT '0', +PRIMARY KEY (`prevNodeID`,`nodeID`), +KEY `prevVersion` (`prevVersion`) USING BTREE, +KEY `version` (`version`) USING BTREE, +KEY `nodeID` (`nodeID`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; +insert into `999999999` values ( 'x', 'y', 'z', 0, 0); +select * from `999999999`; +version updateJSON prevVersion nodeID prevNodeID +x y z 0 0 +CREATE TABLE IF NOT EXISTS vvvvvvv_hhhhhhh ( +latch VARCHAR(32) NULL, +origid BIGINT UNSIGNED NULL, +destid BIGINT UNSIGNED NULL, +weight DOUBLE NULL, +seq BIGINT UNSIGNED NULL, +linkid BIGINT UNSIGNED NULL, +KEY (latch, origid, destid) USING HASH, +KEY (latch, destid, origid) USING HASH +) ENGINE=OQGRAPH +data_table='999999999' + origid='prevNodeID' + destid='nodeID'; +select * from vvvvvvv_hhhhhhh; +latch origid destid weight seq linkid +NULL 0 0 1 NULL NULL +drop table if exists `999999999`; +drop table if exists vvvvvvv_hhhhhhh; +drop database if exists `1112222233_44444444`; +Performing OQGraph regression test mdev5996 - using db=`1112222233_444444444`, table=`999999999` +use test; +drop database if exists `1112222233_444444444` ; +create database `1112222233_444444444` ; +use `1112222233_444444444` ; +drop table if exists `999999999` ; +drop table if exists vvvvvvv_hhhhhhh; +CREATE TABLE `999999999` ( +`version` varchar(10) NOT NULL, +`updateJSON` mediumtext, +`prevVersion` varchar(10) NOT NULL, +`nodeID` bigint(20) unsigned NOT NULL DEFAULT '0', +`prevNodeID` bigint(20) unsigned NOT NULL DEFAULT '0', +PRIMARY KEY (`prevNodeID`,`nodeID`), +KEY `prevVersion` (`prevVersion`) USING BTREE, +KEY `version` (`version`) USING BTREE, +KEY `nodeID` (`nodeID`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; +insert into `999999999` values ( 'x', 'y', 'z', 0, 0); +select * from `999999999`; +version updateJSON prevVersion nodeID prevNodeID +x y z 0 0 +CREATE TABLE IF NOT EXISTS vvvvvvv_hhhhhhh ( +latch VARCHAR(32) NULL, +origid BIGINT UNSIGNED NULL, +destid BIGINT UNSIGNED NULL, +weight DOUBLE NULL, +seq BIGINT UNSIGNED NULL, +linkid BIGINT UNSIGNED NULL, +KEY (latch, origid, destid) USING HASH, +KEY (latch, destid, origid) USING HASH +) ENGINE=OQGRAPH +data_table='999999999' + origid='prevNodeID' + destid='nodeID'; +select * from vvvvvvv_hhhhhhh; +latch origid destid weight seq linkid +NULL 0 0 1 NULL NULL +drop table if exists `999999999`; +drop table if exists vvvvvvv_hhhhhhh; +drop database if exists `1112222233_444444444`; +Performing OQGraph regression test mdev5996 - using db=`1112222233_444444444`, table=`99999999` +use test; +drop database if exists `1112222233_444444444` ; +create database `1112222233_444444444` ; +use `1112222233_444444444` ; +drop table if exists `99999999` ; +drop table if exists vvvvvvv_hhhhhhh; +CREATE TABLE `99999999` ( +`version` varchar(10) NOT NULL, +`updateJSON` mediumtext, +`prevVersion` varchar(10) NOT NULL, +`nodeID` bigint(20) unsigned NOT NULL DEFAULT '0', +`prevNodeID` bigint(20) unsigned NOT NULL DEFAULT '0', +PRIMARY KEY (`prevNodeID`,`nodeID`), +KEY `prevVersion` (`prevVersion`) USING BTREE, +KEY `version` (`version`) USING BTREE, +KEY `nodeID` (`nodeID`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; +insert into `99999999` values ( 'x', 'y', 'z', 0, 0); +select * from `99999999`; +version updateJSON prevVersion nodeID prevNodeID +x y z 0 0 +CREATE TABLE IF NOT EXISTS vvvvvvv_hhhhhhh ( +latch VARCHAR(32) NULL, +origid BIGINT UNSIGNED NULL, +destid BIGINT UNSIGNED NULL, +weight DOUBLE NULL, +seq BIGINT UNSIGNED NULL, +linkid BIGINT UNSIGNED NULL, +KEY (latch, origid, destid) USING HASH, +KEY (latch, destid, origid) USING HASH +) ENGINE=OQGRAPH +data_table='99999999' + origid='prevNodeID' + destid='nodeID'; +select * from vvvvvvv_hhhhhhh; +latch origid destid weight seq linkid +NULL 0 0 1 NULL NULL +drop table if exists `99999999`; +drop table if exists vvvvvvv_hhhhhhh; +drop database if exists `1112222233_444444444`; +Performing OQGraph regression test mdev5996 - using db=`1112222233_444444444`, table=`9999999999` +use test; +drop database if exists `1112222233_444444444` ; +create database `1112222233_444444444` ; +use `1112222233_444444444` ; +drop table if exists `9999999999` ; +drop table if exists vvvvvvv_hhhhhhh; +CREATE TABLE `9999999999` ( +`version` varchar(10) NOT NULL, +`updateJSON` mediumtext, +`prevVersion` varchar(10) NOT NULL, +`nodeID` bigint(20) unsigned NOT NULL DEFAULT '0', +`prevNodeID` bigint(20) unsigned NOT NULL DEFAULT '0', +PRIMARY KEY (`prevNodeID`,`nodeID`), +KEY `prevVersion` (`prevVersion`) USING BTREE, +KEY `version` (`version`) USING BTREE, +KEY `nodeID` (`nodeID`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; +insert into `9999999999` values ( 'x', 'y', 'z', 0, 0); +select * from `9999999999`; +version updateJSON prevVersion nodeID prevNodeID +x y z 0 0 +CREATE TABLE IF NOT EXISTS vvvvvvv_hhhhhhh ( +latch VARCHAR(32) NULL, +origid BIGINT UNSIGNED NULL, +destid BIGINT UNSIGNED NULL, +weight DOUBLE NULL, +seq BIGINT UNSIGNED NULL, +linkid BIGINT UNSIGNED NULL, +KEY (latch, origid, destid) USING HASH, +KEY (latch, destid, origid) USING HASH +) ENGINE=OQGRAPH +data_table='9999999999' + origid='prevNodeID' + destid='nodeID'; +select * from vvvvvvv_hhhhhhh; +latch origid destid weight seq linkid +NULL 0 0 1 NULL NULL +drop table if exists `9999999999`; +drop table if exists vvvvvvv_hhhhhhh; +drop database if exists `1112222233_444444444`; diff --git a/storage/oqgraph/mysql-test/oqgraph/regression_mdev5996.test b/storage/oqgraph/mysql-test/oqgraph/regression_mdev5996.test new file mode 100644 index 00000000..cb4563a5 --- /dev/null +++ b/storage/oqgraph/mysql-test/oqgraph/regression_mdev5996.test @@ -0,0 +1,35 @@ +# Regression test for https://mariadb.atlassian.net/browse/MDEV-5996 +# MidSchipDB_unstable +--let $oqgraph_table_name= 999999999 + +call mtr.add_suppression("99999999 is open on delete"); + +--let $oqgraph_database_name= +--source regression_mdev5996.inc + +--let $oqgraph_database_name= 1 +--source regression_mdev5996.inc + +# Various cases - although actual bug was a broken zero termination +# name of backing store shorter, same and longer than table + +--let $oqgraph_database_name= 1112222233_4444444 +--source regression_mdev5996.inc + +--let $oqgraph_database_name= 1112222233_44444444 +--source regression_mdev5996.inc + +--let $oqgraph_database_name= 1112222233_444444444 +--source regression_mdev5996.inc + +--let $oqgraph_table_name= 99999999 +--source regression_mdev5996.inc + +--let $oqgraph_table_name= 9999999999 +--source regression_mdev5996.inc + +# Fails: + +# 1/9999 +# test/99999999 +# 1112222233_444444444/999999999 diff --git a/storage/oqgraph/mysql-test/oqgraph/regression_mdev6282.result b/storage/oqgraph/mysql-test/oqgraph/regression_mdev6282.result new file mode 100644 index 00000000..3ef61cc3 --- /dev/null +++ b/storage/oqgraph/mysql-test/oqgraph/regression_mdev6282.result @@ -0,0 +1,43 @@ +connect con1,localhost,root,,test; +CREATE TABLE `db_history` ( +`version` VARCHAR(10) NOT NULL, +`updateJSON` MEDIUMTEXT, +`prevVersion` VARCHAR(10) NOT NULL, +`nodeID` BIGINT(20) UNSIGNED NOT NULL DEFAULT '0', +`prevNodeID` BIGINT(20) UNSIGNED NOT NULL DEFAULT '0', +PRIMARY KEY (`prevNodeID`,`nodeID`), +KEY `version` (`version`) USING BTREE, +KEY `prevVersion` (`prevVersion`) USING BTREE, +KEY `nodeID` (`nodeID`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; +INSERT INTO `db_history` VALUES +('0.0.1','{}','0.0.0',1,0), +('0.0.2','{\"data\":{\"add\":{},\"update\":{},\"delete\":{}}}','0.0.1',2,1), +('0.0.3','{\"data\":{\"add\":{},\"update\":{},\"delete\":{}}}','0.0.2',3,2); +CREATE TABLE IF NOT EXISTS version_history ( +latch VARCHAR(32) NULL, +origid BIGINT UNSIGNED NULL, +destid BIGINT UNSIGNED NULL, +weight DOUBLE NULL, +seq BIGINT UNSIGNED NULL, +linkid BIGINT UNSIGNED NULL, +KEY (latch, origid, destid) USING HASH, +KEY (latch, destid, origid) USING HASH +) ENGINE=OQGRAPH DATA_TABLE='db_history' ORIGID='prevNodeID' DESTID='nodeID'; +SELECT `db`.`version`, `db`.`nodeID` +FROM `version_history` AS `v` INNER JOIN `db_history` AS `db` ON `db`.`nodeID` = `v`.`linkid` +WHERE `latch` = 'breadth_first' AND `origid` = '1' ORDER BY `weight` DESC LIMIT 1; +version nodeID +0.0.3 3 +disconnect con1; +connect con2,localhost,root,,test; +SELECT `db`.`version`, `db`.`nodeID` +FROM `version_history` AS `v` INNER JOIN `db_history` AS `db` ON `db`.`nodeID` = `v`.`linkid` +WHERE `latch` = 'breadth_first' AND `origid` = '1' ORDER BY `weight` DESC LIMIT 1; +version nodeID +0.0.3 3 +disconnect con2; +connect con3,localhost,root,,test; +DROP TABLE version_history; +DROP TABLE db_history; +disconnect con3; diff --git a/storage/oqgraph/mysql-test/oqgraph/regression_mdev6282.test b/storage/oqgraph/mysql-test/oqgraph/regression_mdev6282.test new file mode 100644 index 00000000..b8f0ae55 --- /dev/null +++ b/storage/oqgraph/mysql-test/oqgraph/regression_mdev6282.test @@ -0,0 +1,47 @@ +--connect (con1,localhost,root,,test) + + CREATE TABLE `db_history` ( + `version` VARCHAR(10) NOT NULL, + `updateJSON` MEDIUMTEXT, + `prevVersion` VARCHAR(10) NOT NULL, + `nodeID` BIGINT(20) UNSIGNED NOT NULL DEFAULT '0', + `prevNodeID` BIGINT(20) UNSIGNED NOT NULL DEFAULT '0', + PRIMARY KEY (`prevNodeID`,`nodeID`), + KEY `version` (`version`) USING BTREE, + KEY `prevVersion` (`prevVersion`) USING BTREE, + KEY `nodeID` (`nodeID`) + ) ENGINE=MyISAM DEFAULT CHARSET=utf8; + + INSERT INTO `db_history` VALUES + ('0.0.1','{}','0.0.0',1,0), + ('0.0.2','{\"data\":{\"add\":{},\"update\":{},\"delete\":{}}}','0.0.1',2,1), + ('0.0.3','{\"data\":{\"add\":{},\"update\":{},\"delete\":{}}}','0.0.2',3,2); + + CREATE TABLE IF NOT EXISTS version_history ( + latch VARCHAR(32) NULL, + origid BIGINT UNSIGNED NULL, + destid BIGINT UNSIGNED NULL, + weight DOUBLE NULL, + seq BIGINT UNSIGNED NULL, + linkid BIGINT UNSIGNED NULL, + KEY (latch, origid, destid) USING HASH, + KEY (latch, destid, origid) USING HASH + ) ENGINE=OQGRAPH DATA_TABLE='db_history' ORIGID='prevNodeID' DESTID='nodeID'; + + SELECT `db`.`version`, `db`.`nodeID` + FROM `version_history` AS `v` INNER JOIN `db_history` AS `db` ON `db`.`nodeID` = `v`.`linkid` + WHERE `latch` = 'breadth_first' AND `origid` = '1' ORDER BY `weight` DESC LIMIT 1; +--disconnect con1 + +--connect (con2,localhost,root,,test) + SELECT `db`.`version`, `db`.`nodeID` + FROM `version_history` AS `v` INNER JOIN `db_history` AS `db` ON `db`.`nodeID` = `v`.`linkid` + WHERE `latch` = 'breadth_first' AND `origid` = '1' ORDER BY `weight` DESC LIMIT 1; +--disconnect con2 + +--connect (con3,localhost,root,,test) +DROP TABLE version_history; +DROP TABLE db_history; +--disconnect con3 + + diff --git a/storage/oqgraph/mysql-test/oqgraph/regression_mdev6345.result b/storage/oqgraph/mysql-test/oqgraph/regression_mdev6345.result new file mode 100644 index 00000000..68002ce9 --- /dev/null +++ b/storage/oqgraph/mysql-test/oqgraph/regression_mdev6345.result @@ -0,0 +1,12 @@ +DROP TABLE IF EXISTS oq_backing; +DROP TABLE IF EXISTS oq_graph; +CREATE TABLE oq_backing (origid INT UNSIGNED NOT NULL, destid INT UNSIGNED NOT NULL, PRIMARY KEY (origid, destid), KEY (destid)); +INSERT INTO oq_backing(origid, destid) VALUES (1,2), (2,3), (3,4), (4,5), (2,6), (5,6); +CREATE TABLE oq_graph (latch VARCHAR(32) NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH) ENGINE=OQGRAPH data_table='oq_backing' origid='origid' destid='destid'; +SELECT * FROM oq_graph WHERE latch='breadth_first' AND origid=1 AND destid=6; +latch origid destid weight seq linkid +breadth_first 1 6 NULL 0 1 +breadth_first 1 6 1 1 2 +breadth_first 1 6 1 2 6 +DROP TABLE IF EXISTS oq_graph; +DROP TABLE IF EXISTS oq_backing; diff --git a/storage/oqgraph/mysql-test/oqgraph/regression_mdev6345.test b/storage/oqgraph/mysql-test/oqgraph/regression_mdev6345.test new file mode 100644 index 00000000..fefd03a7 --- /dev/null +++ b/storage/oqgraph/mysql-test/oqgraph/regression_mdev6345.test @@ -0,0 +1,19 @@ +#-- This test is probably not right, because the real bug manifested over a network connection on a busy server. + +--disable_warnings +DROP TABLE IF EXISTS oq_backing; +DROP TABLE IF EXISTS oq_graph; +--enable_warnings + + +CREATE TABLE oq_backing (origid INT UNSIGNED NOT NULL, destid INT UNSIGNED NOT NULL, PRIMARY KEY (origid, destid), KEY (destid)); + +INSERT INTO oq_backing(origid, destid) VALUES (1,2), (2,3), (3,4), (4,5), (2,6), (5,6); + +CREATE TABLE oq_graph (latch VARCHAR(32) NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH) ENGINE=OQGRAPH data_table='oq_backing' origid='origid' destid='destid'; + +SELECT * FROM oq_graph WHERE latch='breadth_first' AND origid=1 AND destid=6; + +DROP TABLE IF EXISTS oq_graph; +DROP TABLE IF EXISTS oq_backing; + diff --git a/storage/oqgraph/mysql-test/oqgraph/social.result b/storage/oqgraph/mysql-test/oqgraph/social.result new file mode 100644 index 00000000..9b47701f --- /dev/null +++ b/storage/oqgraph/mysql-test/oqgraph/social.result @@ -0,0 +1,111 @@ +DROP TABLE IF EXISTS rsb, rsb_graph; +CREATE TABLE rsb ( +f INT UNSIGNED NOT NULL, +t INT UNSIGNED NOT NULL, +weight FLOAT NOT NULL, +PRIMARY KEY (`f`,`t`), +KEY `t` (`t`) +) ENGINE=MyISAM; +CREATE TABLE rsb_graph ( +latch VARCHAR(32) NULL, +origid BIGINT UNSIGNED NULL, +destid BIGINT UNSIGNED NULL, +weight DOUBLE NULL, +seq BIGINT UNSIGNED NULL, +linkid BIGINT UNSIGNED NULL, +KEY (latch, origid, destid) USING HASH, +KEY (latch, destid, origid) USING HASH +) ENGINE=OQGRAPH data_table='rsb' origid='f' destid='t' weight='weight'; +DROP PROCEDURE IF EXISTS randnotx| +CREATE PROCEDURE randnotx (INOUT rseed INT, IN items INT, IN x INT, OUT rval INT) DETERMINISTIC +BEGIN +REPEAT +# Simple LCG (BSD) +SET rseed = (rseed * 1103515245 + 12345) & 2147483647; +SET rval = ((rseed >> 16) & 32767) MOD items; +UNTIL rval <> x +END REPEAT; +END;| +DROP PROCEDURE IF EXISTS randgraphproc| +CREATE PROCEDURE randgraphproc (IN items INT, IN friends INT, IN fanof INT, IN maxweight INT) DETERMINISTIC +BEGIN +DECLARE i,j,weight,rseed,rval INT; +SET rseed = items; +SET i = 0; +WHILE i < items DO +SET j = 0; +WHILE j < (friends + fanof) DO +CALL randnotx(rseed,items,i,rval); +IF (maxweight > 0) THEN +CALL randnotx(rseed,items,-1,weight); +SET weight = weight MOD maxweight; +ELSE +SET weight = 0; +END IF; +INSERT IGNORE rsb VALUES (i,rval,weight); +IF (j < friends) THEN +INSERT IGNORE rsb VALUES (rval,i,weight); +END IF; +SET j = j + 1; +END WHILE; +SET i = i + 1; +END WHILE; +END;| +CALL randgraphproc(10000,5,2,3); +SELECT GROUP_CONCAT(linkid ORDER BY seq) FROM rsb_graph WHERE latch='dijkstras' AND origid=1 AND destid=20; +GROUP_CONCAT(linkid ORDER BY seq) +1,5378,9993,8029,5613,9338,3730,7694,3546,9658,2825,6157,6461,1246,8678,8811,20 +SELECT GROUP_CONCAT(linkid ORDER BY seq) FROM rsb_graph WHERE latch='dijkstras' AND origid=1 AND destid=77; +GROUP_CONCAT(linkid ORDER BY seq) +1,5378,9993,8029,5613,9338,3730,7694,3546,2367,9994,3130,9577,7992,7995,53,8735,8654,9850,587,177,6509,8447,6927,6690,5454,1277,77 +SELECT GROUP_CONCAT(linkid ORDER BY seq) FROM rsb_graph WHERE latch='dijkstras' AND origid=1 AND destid=203; +GROUP_CONCAT(linkid ORDER BY seq) +1,5378,9993,8597,6078,2632,8846,6514,3189,8336,3327,4653,203 +SELECT GROUP_CONCAT(linkid ORDER BY seq) FROM rsb_graph WHERE latch='dijkstras' AND origid=1595 AND destid=8358; +GROUP_CONCAT(linkid ORDER BY seq) +1595,6255,7652,394,1532,3451,5615,9737,5886,8214,7462,6984,5822,5711,6363,2743,8584,7759,8683,7525,1874,212,5923,2399,3138,740,932,8358 +SELECT GROUP_CONCAT(linkid ORDER BY seq) FROM rsb_graph WHERE latch='dijkstras' AND origid=1 AND destid=9999; +GROUP_CONCAT(linkid ORDER BY seq) +1,5378,9993,8597,6078,2632,7381,6403,9177,1637,9762,2610,319,1310,3579,9999 +SELECT GROUP_CONCAT(linkid ORDER BY seq) FROM rsb_graph WHERE latch='dijkstras' AND origid=6841 AND destid=615; +GROUP_CONCAT(linkid ORDER BY seq) +6841,2979,9109,8306,7777,620,9982,8535,8151,6118,8654,9428,611,9696,3082,7219,9868,615 +SELECT GROUP_CONCAT(linkid ORDER BY seq) FROM rsb_graph WHERE latch='dijkstras' AND origid=369 AND destid=1845; +GROUP_CONCAT(linkid ORDER BY seq) +369,4586,6078,8597,9993,8029,5613,2993,1637,9177,3451,5615,9104,4004,2818,8311,8996,9023,9975,3847,4988,4480,6739,7520,6040,4585,7632,3956,1319,2427,6606,3443,9114,2907,1130,2389,8613,1534,4856,6961,6636,9136,7504,2777,8273,8215,7681,8859,1480,7167,663,3433,4719,3773,1845 +SELECT GROUP_CONCAT(linkid ORDER BY seq) FROM rsb_graph WHERE latch='dijkstras' AND origid=73 AND destid=914; +GROUP_CONCAT(linkid ORDER BY seq) +73,4247,9061,9994,3130,8274,9298,8790,8465,712,9028,646,1255,7384,6554,3193,914 +SELECT GROUP_CONCAT(linkid ORDER BY seq) FROM rsb_graph WHERE latch='dijkstras' AND origid=12345 AND destid=500; +GROUP_CONCAT(linkid ORDER BY seq) +NULL +SELECT GROUP_CONCAT(linkid ORDER BY seq) FROM rsb_graph WHERE latch='dijkstras' AND origid=300 AND destid=54321; +GROUP_CONCAT(linkid ORDER BY seq) +NULL +SELECT COUNT(*) FROM rsb_graph WHERE latch='dijkstras' AND origid=1; +COUNT(*) +10000 +SELECT COUNT(*) FROM rsb_graph WHERE latch='dijkstras' AND origid=8365; +COUNT(*) +10000 +SELECT COUNT(*) FROM rsb_graph WHERE latch='dijkstras' AND origid=976; +COUNT(*) +10000 +SELECT COUNT(*) FROM rsb_graph WHERE latch='dijkstras' AND origid=74; +COUNT(*) +10000 +SELECT COUNT(*) FROM rsb_graph WHERE latch='dijkstras' AND destid=1; +COUNT(*) +10000 +SELECT COUNT(*) FROM rsb_graph WHERE latch='dijkstras' AND destid=9999; +COUNT(*) +10000 +SELECT COUNT(*) FROM rsb_graph WHERE latch='dijkstras' AND destid=52; +COUNT(*) +10000 +SELECT COUNT(*) FROM rsb_graph WHERE latch='dijkstras' AND destid=6483; +COUNT(*) +10000 +DROP TABLE rsb_graph, rsb; +DROP PROCEDURE randgraphproc; +DROP PROCEDURE randnotx; diff --git a/storage/oqgraph/mysql-test/oqgraph/social.test b/storage/oqgraph/mysql-test/oqgraph/social.test new file mode 100644 index 00000000..a71b160c --- /dev/null +++ b/storage/oqgraph/mysql-test/oqgraph/social.test @@ -0,0 +1,134 @@ +# The test can take very long time with valgrind +--source include/not_valgrind.inc + +--disable_warnings +DROP TABLE IF EXISTS rsb, rsb_graph; +--enable_warnings + +CREATE TABLE rsb ( + f INT UNSIGNED NOT NULL, + t INT UNSIGNED NOT NULL, + weight FLOAT NOT NULL, + PRIMARY KEY (`f`,`t`), + KEY `t` (`t`) +) ENGINE=MyISAM; + +CREATE TABLE rsb_graph ( + latch VARCHAR(32) NULL, + origid BIGINT UNSIGNED NULL, + destid BIGINT UNSIGNED NULL, + weight DOUBLE NULL, + seq BIGINT UNSIGNED NULL, + linkid BIGINT UNSIGNED NULL, + KEY (latch, origid, destid) USING HASH, + KEY (latch, destid, origid) USING HASH +) ENGINE=OQGRAPH data_table='rsb' origid='f' destid='t' weight='weight'; + + +# this graph generator is designed to be deterministic +# (so we don't need to ship a large test dataset) +# --source suite/oqgraph/randgraphproc.inc + +# SQL implementation of randsocial.c for OQGRAPH +# Copyright (C) 2013 by Arjen Lentz <arjen@openquery.com> for Open Query +# GPL v2+ licensed with the rest of OQGRAPH +# for use in mysql-test +# 2013-03-01 first implementation based on randsocial.c in old oqgraph v2 tree + +delimiter |; +--disable_warnings +DROP PROCEDURE IF EXISTS randnotx| +--enable_warnings +CREATE PROCEDURE randnotx (INOUT rseed INT, IN items INT, IN x INT, OUT rval INT) DETERMINISTIC +BEGIN + REPEAT + # Simple LCG (BSD) + SET rseed = (rseed * 1103515245 + 12345) & 2147483647; + SET rval = ((rseed >> 16) & 32767) MOD items; + UNTIL rval <> x + END REPEAT; +END;| + + +# this procedure is deterministic with its private seeded random generator +--disable_warnings +DROP PROCEDURE IF EXISTS randgraphproc| +--enable_warnings +CREATE PROCEDURE randgraphproc (IN items INT, IN friends INT, IN fanof INT, IN maxweight INT) DETERMINISTIC +BEGIN + DECLARE i,j,weight,rseed,rval INT; + + SET rseed = items; + + SET i = 0; + WHILE i < items DO + SET j = 0; + WHILE j < (friends + fanof) DO + CALL randnotx(rseed,items,i,rval); + + IF (maxweight > 0) THEN + CALL randnotx(rseed,items,-1,weight); + SET weight = weight MOD maxweight; + ELSE + SET weight = 0; + END IF; + + INSERT IGNORE rsb VALUES (i,rval,weight); + + IF (j < friends) THEN + INSERT IGNORE rsb VALUES (rval,i,weight); + END IF; + + SET j = j + 1; + END WHILE; + + SET i = i + 1; + END WHILE; +END;| + +DELIMITER ;| + + +# generate social graph of 10000 people having 5 friends (two-way) and being fan of 2 others (one-way)), max weight 3 +CALL randgraphproc(10000,5,2,3); + +# some random paths +SELECT GROUP_CONCAT(linkid ORDER BY seq) FROM rsb_graph WHERE latch='dijkstras' AND origid=1 AND destid=20; +SELECT GROUP_CONCAT(linkid ORDER BY seq) FROM rsb_graph WHERE latch='dijkstras' AND origid=1 AND destid=77; +SELECT GROUP_CONCAT(linkid ORDER BY seq) FROM rsb_graph WHERE latch='dijkstras' AND origid=1 AND destid=203; +SELECT GROUP_CONCAT(linkid ORDER BY seq) FROM rsb_graph WHERE latch='dijkstras' AND origid=1595 AND destid=8358; +SELECT GROUP_CONCAT(linkid ORDER BY seq) FROM rsb_graph WHERE latch='dijkstras' AND origid=1 AND destid=9999; +SELECT GROUP_CONCAT(linkid ORDER BY seq) FROM rsb_graph WHERE latch='dijkstras' AND origid=6841 AND destid=615; +SELECT GROUP_CONCAT(linkid ORDER BY seq) FROM rsb_graph WHERE latch='dijkstras' AND origid=369 AND destid=1845; +SELECT GROUP_CONCAT(linkid ORDER BY seq) FROM rsb_graph WHERE latch='dijkstras' AND origid=73 AND destid=914; + +# nonexistent origin +SELECT GROUP_CONCAT(linkid ORDER BY seq) FROM rsb_graph WHERE latch='dijkstras' AND origid=12345 AND destid=500; + +# noexistent destination +SELECT GROUP_CONCAT(linkid ORDER BY seq) FROM rsb_graph WHERE latch='dijkstras' AND origid=300 AND destid=54321; + +# how many possible destinations from here +SELECT COUNT(*) FROM rsb_graph WHERE latch='dijkstras' AND origid=1; +SELECT COUNT(*) FROM rsb_graph WHERE latch='dijkstras' AND origid=8365; +SELECT COUNT(*) FROM rsb_graph WHERE latch='dijkstras' AND origid=976; +SELECT COUNT(*) FROM rsb_graph WHERE latch='dijkstras' AND origid=74; + +# how many possible sources to here +# this doesn't appear to work right now in v3 ? #if 0 in code. check with Antony +SELECT COUNT(*) FROM rsb_graph WHERE latch='dijkstras' AND destid=1; +SELECT COUNT(*) FROM rsb_graph WHERE latch='dijkstras' AND destid=9999; +SELECT COUNT(*) FROM rsb_graph WHERE latch='dijkstras' AND destid=52; +SELECT COUNT(*) FROM rsb_graph WHERE latch='dijkstras' AND destid=6483; + +# breadth first +# other algorithms +# joins + +# cleaning up our tables +DROP TABLE rsb_graph, rsb; + +# cleaning up procs from randgraphproc.inc +DROP PROCEDURE randgraphproc; +DROP PROCEDURE randnotx; + diff --git a/storage/oqgraph/mysql-test/oqgraph/suite.opt b/storage/oqgraph/mysql-test/oqgraph/suite.opt new file mode 100644 index 00000000..9f10d4e0 --- /dev/null +++ b/storage/oqgraph/mysql-test/oqgraph/suite.opt @@ -0,0 +1 @@ +--plugin-load-add=$HA_OQGRAPH_SO --enable-oqgraph diff --git a/storage/oqgraph/mysql-test/oqgraph/suite.pm b/storage/oqgraph/mysql-test/oqgraph/suite.pm new file mode 100644 index 00000000..118ecfa7 --- /dev/null +++ b/storage/oqgraph/mysql-test/oqgraph/suite.pm @@ -0,0 +1,14 @@ +package My::Suite::OQGraph; + +@ISA = qw(My::Suite); + +return "No OQGraph" unless $ENV{HA_OQGRAPH_SO} or + $::mysqld_variables{'oqgraph'} eq "ON"; + +# as long as OQGraph defines MYSQL_SERVER it cannot run in embedded +return "Not run for embedded server" if $::opt_embedded_server; + +sub is_default { 1 } + +bless { }; + diff --git a/storage/oqgraph/oqgraph_config.h.in b/storage/oqgraph/oqgraph_config.h.in new file mode 100644 index 00000000..18dad70a --- /dev/null +++ b/storage/oqgraph/oqgraph_config.h.in @@ -0,0 +1,73 @@ +/* src/oqgraph_config.h.in. Generated from configure.in by autoheader. */ + +/* Define to 1 if you have the <dlfcn.h> header file. */ +#undef HAVE_DLFCN_H + +/* Enables DTRACE Support */ +#undef HAVE_DTRACE + +/* Define to 1 if you have the <inttypes.h> header file. */ +#undef HAVE_INTTYPES_H + +/* Define to 1 if you have the <limits.h> header file. */ +#undef HAVE_LIMITS_H + +/* Define to 1 if you have the <memory.h> header file. */ +#undef HAVE_MEMORY_H + +/* Define to 1 if you have the <stdint.h> header file. */ +#undef HAVE_STDINT_H + +/* Define to 1 if you have the <stdlib.h> header file. */ +#undef HAVE_STDLIB_H + +/* Define to 1 if you have the <strings.h> header file. */ +#undef HAVE_STRINGS_H + +/* Define to 1 if you have the <string.h> header file. */ +#undef HAVE_STRING_H + +/* Define to 1 if you have the <syslimits.h> header file. */ +#undef HAVE_SYSLIMITS_H + +/* Define to 1 if you have the <sys/stat.h> header file. */ +#undef HAVE_SYS_STAT_H + +/* Define to 1 if you have the <sys/types.h> header file. */ +#undef HAVE_SYS_TYPES_H + +/* Define to 1 if you have the <unistd.h> header file. */ +#undef HAVE_UNISTD_H + +/* Source directory for MySQL */ +#undef MYSQL_SRC + +/* Name of package */ +#undef PACKAGE + +/* Define to the address where bug reports for this package should be sent. */ +#undef PACKAGE_BUGREPORT + +/* Define to the full name of this package. */ +#undef PACKAGE_NAME + +/* Define to the full name and version of this package. */ +#undef PACKAGE_STRING + +/* Define to the one symbol short name of this package. */ +#undef PACKAGE_TARNAME + +/* Define to the version of this package. */ +#undef PACKAGE_VERSION + +/* Define to 1 if you have the ANSI C header files. */ +#undef STDC_HEADERS + +/* Version number of package */ +#undef VERSION + +/* Define to empty if `const' does not conform to ANSI C. */ +#undef const + +/* Define to `unsigned int' if <sys/types.h> does not define. */ +#undef size_t diff --git a/storage/oqgraph/oqgraph_judy.cc b/storage/oqgraph/oqgraph_judy.cc new file mode 100644 index 00000000..0ad9f9fe --- /dev/null +++ b/storage/oqgraph/oqgraph_judy.cc @@ -0,0 +1,146 @@ +/* Copyright (C) 2007-2013 Arjen G Lentz & Antony T Curtis for Open Query + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */ + +/* ====================================================================== + Open Query Graph Computation Engine, based on a concept by Arjen Lentz + v3 implementation by Antony Curtis, Arjen Lentz, Andrew McDonnell + For more information, documentation, support, enhancement engineering, + see http://openquery.com/graph or contact graph@openquery.com + ====================================================================== +*/ + +#include "oqgraph_judy.h" + +/* + Currently the only active code that can return error is: + judy_bitset::reset()/J1U() + judy_bitset::setbit()/J1S() + + In most cases errors are either about wrong parameters passed to Judy + functions or internal structures corruption. These definitely deserve + abnormal process termination instead of exit() as it is done by original + JUDYERROR. + + TODO: there's one exception that should be handled properly though: OOM. +*/ +#include <stdio.h> +#define JUDYERROR(CallerFile, CallerLine, JudyFunc, JudyErrno, JudyErrID) \ + { \ + (void) fprintf(stderr, "File '%s', line %d: %s(), " \ + "JU_ERRNO_* == %d, ID == %d\n", \ + CallerFile, CallerLine, \ + JudyFunc, JudyErrno, JudyErrID); \ + abort(); \ + } +#include <Judy.h> + +void open_query::judy_bitset::clear() +{ + int rc; + J1FA(rc, array); +} + +bool open_query::judy_bitset::test(size_type n) const +{ + int rc; + J1T(rc, array, n); + return rc == 1; +} + +open_query::judy_bitset& open_query::judy_bitset::setbit(size_type n) +{ + int rc; + J1S(rc, array, n); + return *this; +} + +open_query::judy_bitset& open_query::judy_bitset::reset(size_type n) +{ + int rc; + J1U(rc, array, n); + return *this; +} + +open_query::judy_bitset& open_query::judy_bitset::flip(size_type n) +{ + int rc; + J1U(rc, array, n); + if (!rc) + { + J1S(rc, array, n); + } + return *this; +} + +open_query::judy_bitset::size_type open_query::judy_bitset::num_blocks() const +{ + Word_t rc; + J1MU(rc, array); + return rc; +} + +open_query::judy_bitset::size_type open_query::judy_bitset::size() const +{ + int rc; + Word_t index = (Word_t) -1; + J1L(rc, array, index); + if (!rc) + return index; + else + return npos; +} + +open_query::judy_bitset::size_type open_query::judy_bitset::count() const +{ + Word_t rc; + J1C(rc, array, 0, -1); + return rc; +} + +open_query::judy_bitset& open_query::judy_bitset::set(const judy_bitset& src) +{ + if (!src.empty()) + { + for (size_type pos= src.find_first(); pos != npos; pos= src.find_next(pos)) + { + set(pos); + } + } + return *this; +} + + +open_query::judy_bitset::size_type open_query::judy_bitset::find_first() const +{ + int rc; + Word_t index = 0; + J1F(rc, array, index); + if (!rc) + return index; + else + return npos; +} + +open_query::judy_bitset::size_type open_query::judy_bitset::find_next(size_type n) const +{ + int rc; + Word_t index = (Word_t) n; + J1N(rc, array, index); + if (!rc) + return index; + else + return npos; +} diff --git a/storage/oqgraph/oqgraph_judy.h b/storage/oqgraph/oqgraph_judy.h new file mode 100644 index 00000000..53bb4706 --- /dev/null +++ b/storage/oqgraph/oqgraph_judy.h @@ -0,0 +1,121 @@ +/* Copyright (C) 2007-2013 Arjen G Lentz & Antony T Curtis for Open Query + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */ + +/* ====================================================================== + Open Query Graph Computation Engine, based on a concept by Arjen Lentz + v3 implementation by Antony Curtis, Arjen Lentz, Andrew McDonnell + For more information, documentation, support, enhancement engineering, + see http://openquery.com/graph or contact graph@openquery.com + ====================================================================== +*/ + +#pragma once + +#include <cstddef> + +namespace open_query +{ + + class judy_bitset + { + public: + typedef std::size_t size_type; + enum { npos = (size_type) -1 }; + + judy_bitset() + : array(0) + { } + + judy_bitset(const judy_bitset& src) + : array(0) + { + set(src); + } + + ~judy_bitset() + { clear(); } + + judy_bitset& operator=(const judy_bitset& src) + { + clear(); + return set(src); + } + + void clear(); + bool empty() const { return !array; } + bool none() const { return npos == find_first(); } + + inline judy_bitset& set(size_type n, bool val = true) + { + if (!val) + return reset(n); + else + return setbit(n); + } + + judy_bitset& set(const judy_bitset& src); + + judy_bitset& reset(size_type n); + judy_bitset& flip(size_type n); + bool test(size_type) const; + size_type count() const; + size_type size() const; + size_type num_blocks() const; + + class reference + { + friend class judy_bitset; + reference(judy_bitset& array, size_type pos) + : j(array) + , n(pos) + { } + void operator&(); // not defined + public: + reference& operator=(bool value) + { j.set(n, value); return *this; } + reference& operator=(const reference& ref) + { j.set(n, ref); return *this; } + + reference& operator|=(bool value) + { if (value) j.set(n); return *this; } + reference& operator&=(bool value) + { if (!value) j.reset(n); return *this; } + reference& operator^=(bool value) + { if (value) j.flip(n); return *this; } + reference& operator-=(bool value) + { if (value) j.reset(n); return *this; } + + bool operator~() const { return !j.test(n); } + operator bool() const { return j.test(n); } + reference& flip() { j.flip(n); return *this; } + + private: + judy_bitset& j; + size_type n; + }; + + reference operator[](size_type n) { return reference(*this, n); } + bool operator[](size_type n) const { return test(n); } + + size_type find_first() const; + size_type find_next(size_type n) const; + private: + mutable void* array; + + judy_bitset& setbit(size_type n); + }; +} + diff --git a/storage/oqgraph/oqgraph_probes.d b/storage/oqgraph/oqgraph_probes.d new file mode 100644 index 00000000..db0b9cd7 --- /dev/null +++ b/storage/oqgraph/oqgraph_probes.d @@ -0,0 +1,19 @@ +/* Copyright (C) 2004-2005 MySQL AB + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */ + +provider oqgraph { + probe open(); + probe close(); +}; diff --git a/storage/oqgraph/oqgraph_shim.cc b/storage/oqgraph/oqgraph_shim.cc new file mode 100644 index 00000000..3633b034 --- /dev/null +++ b/storage/oqgraph/oqgraph_shim.cc @@ -0,0 +1,74 @@ +/* Copyright (C) 2007-2013 Arjen G Lentz & Antony T Curtis for Open Query + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */ + +/* ====================================================================== + Open Query Graph Computation Engine, based on a concept by Arjen Lentz + v3 implementation by Antony Curtis, Arjen Lentz, Andrew McDonnell + For more information, documentation, support, enhancement engineering, + see http://openquery.com/graph or contact graph@openquery.com + ====================================================================== +*/ + +#include "oqgraph_shim.h" + +bool oqgraph3::edge_iterator::seek() +{ + if (!_graph->_cursor || + _graph->_rnd_pos > _offset || + _graph->_cursor != _graph->_rnd_cursor.operator->()) + { + _graph->_rnd_pos= 0; + _graph->_rnd_cursor= new cursor(_graph); + if (_graph->_rnd_cursor->seek_to(boost::none, boost::none)) + _graph->_rnd_pos= size_t(-1); + } + while (_graph->_rnd_pos < _offset) + { + if (_graph->_rnd_cursor->seek_next()) + { + _offset = size_t(-1); + return true; + } + _graph->_rnd_pos++; + } + return false; +} + +oqgraph3::edge_iterator::value_type oqgraph3::edge_iterator::operator*() +{ + seek(); + return *_graph->_rnd_cursor; +} + +bool oqgraph3::edge_iterator::operator==(const self& x) +{ + if (_offset == size_t(-1) && x._offset != size_t(-1)) + return const_cast<edge_iterator&>(x).seek(); + if (_offset != size_t(-1) && x._offset == size_t(-1)) + return seek(); + + return _offset == x._offset; +} + +bool oqgraph3::edge_iterator::operator!=(const self& x) +{ + if (_offset == size_t(-1) && x._offset != size_t(-1)) + return !const_cast<edge_iterator&>(x).seek(); + if (_offset != size_t(-1) && x._offset == size_t(-1)) + return !seek(); + + return _offset != x._offset; +} diff --git a/storage/oqgraph/oqgraph_shim.h b/storage/oqgraph/oqgraph_shim.h new file mode 100644 index 00000000..cd63708e --- /dev/null +++ b/storage/oqgraph/oqgraph_shim.h @@ -0,0 +1,493 @@ +/* Copyright (C) 2007-2013 Arjen G Lentz & Antony T Curtis for Open Query + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */ + +/* ====================================================================== + Open Query Graph Computation Engine, based on a concept by Arjen Lentz + v3 implementation by Antony Curtis, Arjen Lentz, Andrew McDonnell + For more information, documentation, support, enhancement engineering, + see http://openquery.com/graph or contact graph@openquery.com + ====================================================================== +*/ + +#pragma once + +#include "oqgraph_judy.h" +#include "oqgraph_thunk.h" + +#include <boost/graph/directed_graph.hpp> +#include <boost/graph/adjacency_iterator.hpp> + +namespace open_query +{ + struct OQGraphTraversalCategory + : public boost::bidirectional_graph_tag + , public boost::adjacency_graph_tag + , public boost::edge_list_graph_tag + { }; + +} + +namespace oqgraph3 +{ + struct traversal_category + : public boost::adjacency_graph_tag + , public boost::bidirectional_graph_tag + , public boost::edge_list_graph_tag + { }; + + struct edge_iterator + { + typedef edge_iterator self; + typedef edge_info value_type; + typedef edge_info& reference; + typedef edge_info pointer; + typedef std::ptrdiff_t difference_type; + typedef std::input_iterator_tag iterator_category; + edge_iterator() { } + edge_iterator(const graph_ptr& graph, size_t offset=0) + : _graph(graph) + , _offset(offset) { } + edge_iterator(const edge_iterator& pos) + : _graph(pos._graph) + , _offset(pos._offset) { } + value_type operator*(); + self& operator+=(size_t n) { _offset+= n; return *this; } + self& operator++() { ++_offset; return *this; } + self operator++(int) + { size_t temp= _offset++; return edge_iterator(_graph, temp); } + bool seek(); + bool operator==(const self& x); + bool operator!=(const self& x); + graph_ptr _graph; + size_t _offset; + }; + + struct vertex_iterator + { + typedef vertex_iterator self; + typedef vertex_id value_type; + typedef vertex_id& reference; + typedef vertex_id pointer; + typedef std::ptrdiff_t difference_type; + typedef std::input_iterator_tag iterator_category; + vertex_iterator() { } + vertex_iterator(const cursor_ptr& pos) : _cursor(pos.operator->()) { } + vertex_id operator*() const + { + edge_info edge(*_cursor); + if (!_seen.test(edge.origid())) + return edge.origid(); + else + return edge.destid(); + } + + self& operator++() + { + edge_info edge(*_cursor); + if (!_seen.test(edge.origid())) + { + _seen.set(edge.origid()); + } + else + { + _seen.set(edge.destid()); + } + + while (_seen.test(edge.origid()) && _seen.test(edge.destid())) + { + if (_cursor->seek_next()) + break; + edge= _cursor; + } + return *this; + } + self operator++(int) { cursor* t(new cursor(*_cursor)); ++(*this); return vertex_iterator(t); } + bool operator==(const self& x) { return *_cursor == *x._cursor; } + bool operator!=(const self& x) { return *_cursor != *x._cursor; } + cursor_ptr _cursor; + open_query::judy_bitset _seen; + }; + + + struct out_edge_iterator + { + typedef out_edge_iterator self; + typedef edge_info value_type; + typedef edge_info& reference; + typedef edge_info pointer; + typedef std::ptrdiff_t difference_type; + typedef std::input_iterator_tag iterator_category; + out_edge_iterator() { } + out_edge_iterator(const cursor_ptr& cursor) : _cursor(cursor) { } + value_type operator*() { return value_type(_cursor); } + self& operator++() { _cursor->seek_next(); return *this; } + self operator++(int) + { cursor_ptr t(new cursor(*_cursor)); ++(*this); return out_edge_iterator(t); } + bool operator==(const self& x) { return _cursor == x._cursor; } + bool operator!=(const self& x) { return _cursor != x._cursor; } + cursor_ptr _cursor; + }; + + struct in_edge_iterator + { + typedef in_edge_iterator self; + typedef edge_info value_type; + typedef edge_info& reference; + typedef edge_info pointer; + typedef std::ptrdiff_t difference_type; + typedef std::input_iterator_tag iterator_category; + in_edge_iterator() { } + in_edge_iterator(const cursor_ptr& cursor) : _cursor(cursor) { } + value_type operator*() const { return value_type(_cursor); } + self& operator++() { _cursor->seek_next(); return *this; } + self operator++(int) + { cursor_ptr t(new cursor(*_cursor)); ++(*this); return in_edge_iterator(t); } + bool operator==(const self& x) const { return _cursor == x._cursor; } + bool operator!=(const self& x) const { return _cursor != x._cursor; } + cursor_ptr _cursor; + }; + + struct vertex_index_property_map + { + typedef vertex_id value_type; + typedef value_type reference; + typedef vertex_id key_type; + typedef boost::readable_property_map_tag category; + vertex_index_property_map(const graph& g) : _g(g) { } + const graph& _g; + + friend inline reference + get(const vertex_index_property_map&, key_type key) + { return key; } + }; + + struct edge_weight_property_map + { + typedef weight_t value_type; + typedef value_type reference; + typedef edge_info key_type; + typedef boost::readable_property_map_tag category; + edge_weight_property_map(const graph& g) : _g(g) { } + friend inline reference + get(const edge_weight_property_map& p, const key_type& key) + { return key.weight(); } + + const graph& _g; + }; + + struct edge_index_property_map + { + typedef cursor_ptr value_type; + typedef cursor_ptr reference; + typedef edge_info key_type; + typedef boost::readable_property_map_tag category; + edge_index_property_map(const graph& g) : _g(g) { } + const graph& _g; + }; +} + +namespace boost +{ + + template<> + struct graph_traits<oqgraph3::graph> + { + typedef oqgraph3::vertex_id vertex_descriptor; + typedef oqgraph3::edge_info edge_descriptor; + typedef boost::adjacency_iterator_generator< + oqgraph3::graph, + oqgraph3::vertex_id, + oqgraph3::out_edge_iterator>::type adjacency_iterator; + typedef oqgraph3::out_edge_iterator out_edge_iterator; + typedef oqgraph3::in_edge_iterator in_edge_iterator; + typedef oqgraph3::vertex_iterator vertex_iterator; + typedef oqgraph3::edge_iterator edge_iterator; + + typedef boost::directed_tag directed_category; + typedef boost::allow_parallel_edge_tag edge_parallel_category; + typedef oqgraph3::traversal_category traversal_category; + + typedef oqgraph3::vertices_size_type vertices_size_type; + typedef oqgraph3::edges_size_type edges_size_type; + typedef oqgraph3::degree_size_type degree_size_type; + + static inline oqgraph3::vertex_id null_vertex() + { return oqgraph3::vertex_id(-1); } + }; + + template<> + struct graph_traits<const oqgraph3::graph> + : public graph_traits<oqgraph3::graph> + { }; + + template <> + struct graph_property_type<oqgraph3::graph> + { + typedef no_property type; + }; + + template <> + struct vertex_property_type<oqgraph3::graph> + { + typedef no_property type; + }; + + template <> + struct edge_property_type<oqgraph3::graph> + { + typedef no_property type; + }; + +#if BOOST_VERSION < 106000 && BOOST_VERSION >= 104601 + template <> + struct graph_bundle_type<oqgraph3::graph> + { + typedef no_graph_bundle type; + }; + + template <> + struct vertex_bundle_type<oqgraph3::graph> + { + typedef no_vertex_bundle type; + }; + + template <> + struct edge_bundle_type<oqgraph3::graph> + { + typedef no_edge_bundle type; + }; +#endif + + template<> + struct property_map<oqgraph3::graph, edge_weight_t> + { + typedef void type; + typedef oqgraph3::edge_weight_property_map const_type; + }; + + template<> + struct property_map<oqgraph3::graph, vertex_index_t> + { + typedef void type; + typedef oqgraph3::vertex_index_property_map const_type; + }; + + template<> + struct property_map<oqgraph3::graph, edge_index_t> + { + typedef void type; + typedef oqgraph3::edge_index_property_map const_type; + }; + +} + +namespace oqgraph3 +{ + using namespace boost; + + inline graph_traits<oqgraph3::graph>::vertex_descriptor + source( + const graph_traits<oqgraph3::graph>::edge_descriptor& e, + const oqgraph3::graph&) + { return e.origid(); } + + inline graph_traits<oqgraph3::graph>::vertex_descriptor + target( + const graph_traits<oqgraph3::graph>::edge_descriptor& e, + const oqgraph3::graph&) + { return e.destid(); } + + inline std::pair< + graph_traits<oqgraph3::graph>::out_edge_iterator, + graph_traits<oqgraph3::graph>::out_edge_iterator> + out_edges( + graph_traits<oqgraph3::graph>::vertex_descriptor v, + const oqgraph3::graph& g) + { + oqgraph3::cursor* + end= new oqgraph3::cursor(const_cast<oqgraph3::graph*>(&g)); + oqgraph3::cursor* + start= new oqgraph3::cursor(const_cast<oqgraph3::graph*>(&g)); + start->seek_to(v, boost::none); + return std::make_pair( + graph_traits<oqgraph3::graph>::out_edge_iterator(start), + graph_traits<oqgraph3::graph>::out_edge_iterator(end)); + } + + inline graph_traits<oqgraph3::graph>::degree_size_type + out_degree( + graph_traits<oqgraph3::graph>::vertex_descriptor v, + const oqgraph3::graph& g) + { + std::size_t count = 0; + for (std::pair< + graph_traits<oqgraph3::graph>::out_edge_iterator, + graph_traits<oqgraph3::graph>::out_edge_iterator> i= out_edges(v, g); + i.first != i.second; ++i.first) + { + ++count; + } + return count; + } + + + inline std::pair< + graph_traits<oqgraph3::graph>::in_edge_iterator, + graph_traits<oqgraph3::graph>::in_edge_iterator> + in_edges( + graph_traits<oqgraph3::graph>::vertex_descriptor v, + const oqgraph3::graph& g) + { + oqgraph3::cursor* + end= new oqgraph3::cursor(const_cast<oqgraph3::graph*>(&g)); + oqgraph3::cursor* + start= new oqgraph3::cursor(const_cast<oqgraph3::graph*>(&g)); + start->seek_to(boost::none, v); + return std::make_pair( + graph_traits<oqgraph3::graph>::in_edge_iterator(start), + graph_traits<oqgraph3::graph>::in_edge_iterator(end)); + } + + inline graph_traits<oqgraph3::graph>::degree_size_type + in_degree( + graph_traits<oqgraph3::graph>::vertex_descriptor v, + const oqgraph3::graph& g) + { + std::size_t count = 0; + for (std::pair< + graph_traits<oqgraph3::graph>::in_edge_iterator, + graph_traits<oqgraph3::graph>::in_edge_iterator> it= in_edges(v, g); + it.first != it.second; ++it.first) + { + ++count; + } + return count; + } + + + // EdgeListGraph concepts + inline std::pair< + graph_traits<oqgraph3::graph>::edge_iterator, + graph_traits<oqgraph3::graph>::edge_iterator> + edges(const oqgraph3::graph& g) + { + std::size_t end= std::size_t(-1); + std::size_t start= end; + + if (g.num_edges()) + start= 0; + + return std::make_pair( + graph_traits<oqgraph3::graph>::edge_iterator( + const_cast<oqgraph3::graph*>(&g), start), + graph_traits<oqgraph3::graph>::edge_iterator( + const_cast<oqgraph3::graph*>(&g), end)); + } + + inline std::pair< + graph_traits<oqgraph3::graph>::vertex_iterator, + graph_traits<oqgraph3::graph>::vertex_iterator> + vertices(const oqgraph3::graph& g) + { + oqgraph3::cursor* + start= new oqgraph3::cursor(const_cast<oqgraph3::graph*>(&g)); + start->seek_to(boost::none, boost::none); + return std::make_pair( + graph_traits<oqgraph3::graph>::vertex_iterator(start), + graph_traits<oqgraph3::graph>::vertex_iterator( + new oqgraph3::cursor(const_cast<oqgraph3::graph*>(&g)))); + } + + inline graph_traits<oqgraph3::graph>::vertices_size_type + num_vertices(const oqgraph3::graph& g) + { + std::size_t count = 0; + for (std::pair< + graph_traits<oqgraph3::graph>::vertex_iterator, + graph_traits<oqgraph3::graph>::vertex_iterator> i= vertices(g); + i.first != i.second; ++i.first) + { + ++count; + } + return count; + } + + inline property_map< + oqgraph3::graph, + edge_weight_t>::const_type::reference + get( + edge_weight_t, + const oqgraph3::graph& g, + const property_map< + oqgraph3::graph, + edge_weight_t>::const_type::key_type& key) + { return key.weight(); } + + inline property_map< + oqgraph3::graph, + edge_weight_t>::const_type + get(edge_weight_t, + const oqgraph3::graph& g) + { return property_map<oqgraph3::graph, edge_weight_t>::const_type(g); } + + inline property_map< + oqgraph3::graph, + edge_index_t>::const_type::reference + get(edge_index_t, + const oqgraph3::graph&, + const property_map< + oqgraph3::graph, + edge_index_t>::const_type::key_type& key) + { return key._cursor; } + + inline property_map<oqgraph3::graph, edge_index_t>::const_type + get(edge_index_t, const oqgraph3::graph& g) + { return property_map<oqgraph3::graph, edge_index_t>::const_type(g); } + + inline property_map<oqgraph3::graph, edge_index_t>::const_type::reference + get(const property_map<oqgraph3::graph, edge_index_t>::const_type&, + const property_map<oqgraph3::graph, + edge_index_t>::const_type::key_type& key) + { return key._cursor; } + + inline property_map<oqgraph3::graph, vertex_index_t>::const_type::reference + get(vertex_index_t, const oqgraph3::graph&, + const property_map<oqgraph3::graph, + vertex_index_t>::const_type::key_type& key) + { return key; } + + inline property_map<oqgraph3::graph, vertex_index_t>::const_type + get(vertex_index_t, const oqgraph3::graph& g) + { return property_map<oqgraph3::graph, vertex_index_t>::const_type(g); } + + inline optional<graph_traits<oqgraph3::graph>::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_cursor = new oqgraph3::cursor(const_cast<oqgraph3::graph*>(&g)); + bool found = (found_cursor->seek_to(id, boost::none) && found_cursor->seek_to(boost::none, id)); + delete found_cursor; + if (found) { + // id is neither a from or a to in a link + return optional<graph_traits<oqgraph3::graph>::vertex_descriptor>(); + } + return id; + } + +} + diff --git a/storage/oqgraph/oqgraph_thunk.cc b/storage/oqgraph/oqgraph_thunk.cc new file mode 100644 index 00000000..bd577ecf --- /dev/null +++ b/storage/oqgraph/oqgraph_thunk.cc @@ -0,0 +1,564 @@ +/* Copyright (C) 2007-2013 Arjen G Lentz & Antony T Curtis for Open Query + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */ + +/* ====================================================================== + Open Query Graph Computation Engine, based on a concept by Arjen Lentz + v3 implementation by Antony Curtis, Arjen Lentz, Andrew McDonnell + For more information, documentation, support, enhancement engineering, + see http://openquery.com/graph or contact graph@openquery.com + ====================================================================== +*/ + +#define MYSQL_SERVER +#include <my_global.h> +#include "oqgraph_thunk.h" + +#include <boost/tuple/tuple.hpp> + +#include "unireg.h" +#include "sql_base.h" +#include "table.h" +#include "field.h" +#include "key.h" + +#if MYSQL_VERSION_ID < 100000 +// Allow compatibility with build for 5.5.32 +#define user_defined_key_parts key_parts +#endif + +static int debugid = 0; + +oqgraph3::vertex_id oqgraph3::edge_info::origid() const +{ return _cursor->get_origid(); } + +oqgraph3::vertex_id oqgraph3::edge_info::destid() const +{ return _cursor->get_destid(); } + +oqgraph3::weight_t oqgraph3::edge_info::weight() const +{ return _cursor->get_weight(); } + +bool oqgraph3::cursor_ptr::operator==(const cursor_ptr& x) const +{ + if (get() == x.get()) + return true; + return (*this)->record_position() == x->_position; +} + +bool oqgraph3::cursor_ptr::operator!=(const cursor_ptr& x) const +{ + if (get() == x.get()) + return false; + return (*this)->record_position() != x->_position; +} + +oqgraph3::cursor::cursor(const graph_ptr& graph) + : _ref_count(0) + , _graph(graph) + , _index(-1) + , _parts(0) + , _key() + , _position() + , _debugid(++debugid) +{ } + +oqgraph3::cursor::cursor(const cursor& src) + : _ref_count(0) + , _graph(src._graph) + , _index(src._index) + , _parts(src._parts) + , _key(src._key) + , _position(src.record_position()) + , _debugid(++debugid) +{ } + +oqgraph3::cursor::~cursor() +{ + if (this == _graph->_cursor) + { + if (_graph->_cursor->_index >= 0) + _graph->_table->file->ha_index_end(); + else + _graph->_table->file->ha_rnd_end(); + _graph->_cursor= 0; + _graph->_stale= false; + } +} + +const std::string& oqgraph3::cursor::record_position() const +{ + if (_graph->_stale && _graph->_cursor) + { + TABLE& table= *_graph->_table; + table.file->position(table.record[0]); + _graph->_cursor->_position.assign( + (const char*) table.file->ref, table.file->ref_length); + + if (_graph->_cursor->_index >= 0) + { + key_copy((uchar*) _graph->_cursor->_key.data(), table.record[0], + table.key_info + _index, table.key_info[_index].key_length, true); + } + + _graph->_stale= false; + } + return _position; +} + +void oqgraph3::cursor::clear_position() +{ + _position.clear(); + if (this == _graph->_cursor) + { + _graph->_cursor= 0; + _graph->_stale= false; + } +} + +void oqgraph3::cursor::save_position() +{ + record_position(); + + if (this == _graph->_cursor) + { + TABLE& table= *_graph->_table; + + if (_graph->_cursor->_index >= 0) + table.file->ha_index_end(); + else + table.file->ha_rnd_end(); + _graph->_cursor= 0; + _graph->_stale= false; + } +} + +int oqgraph3::cursor::restore_position() +{ + TABLE& table= *_graph->_table; + + if (!_position.size()) + return ENOENT; + + if (this == _graph->_cursor) + return 0; + + if (_graph->_cursor) + _graph->_cursor->save_position(); + + if (_origid || _destid) + { + if (int rc= table.file->ha_index_init(_index, 1)) + return rc; + + restore_record(&table, s->default_values); + + if (_origid) + { + bitmap_set_bit(table.write_set, _graph->_source->field_index); + _graph->_source->store(*_origid, 1); + bitmap_clear_bit(table.write_set, _graph->_source->field_index); + } + + if (_destid) + { + bitmap_set_bit(table.write_set, _graph->_target->field_index); + _graph->_target->store(*_destid, 1); + bitmap_clear_bit(table.write_set, _graph->_target->field_index); + } + + if (int rc= table.file->ha_index_init(_index, 1)) + return rc; + + if (int rc= table.file->ha_index_read_map( + table.record[0], (const uchar*) _key.data(), + (key_part_map)(1 << _parts) - 1, + table.key_info[_index].user_defined_key_parts == _parts ? + HA_READ_KEY_EXACT : HA_READ_KEY_OR_NEXT)) + { + table.file->ha_index_end(); + return rc; + } + + table.file->position(table.record[0]); + + while (memcmp(table.file->ref, _position.data(), table.file->ref_length)) + { + if (int rc= table.file->ha_index_next(table.record[0])) + { + table.file->ha_index_end(); + return rc; + } + + if ((_origid && vertex_id(_graph->_source->val_int()) != *_origid) || + (_destid && vertex_id(_graph->_target->val_int()) != *_destid)) + { + table.file->ha_index_end(); + return ENOENT; + } + table.file->position(table.record[0]); + } + + } + else + { + if (int rc= table.file->ha_rnd_init(1)) + return rc; + + if (int rc= table.file->ha_rnd_pos( + table.record[0], (uchar*) _position.data())) + { + table.file->ha_rnd_end(); + return rc; + } + } + + _graph->_cursor= this; + _graph->_stale= false; + + return 0; +} + +oqgraph3::vertex_id oqgraph3::cursor::get_origid() +{ + if (_origid) + return *_origid; + + if (this != _graph->_cursor) + { + if (restore_position()) + return -1; + } + return static_cast<vertex_id>(_graph->_source->val_int()); +} + +oqgraph3::vertex_id oqgraph3::cursor::get_destid() +{ + if (_destid) + return *_destid; + + if (this != _graph->_cursor) + { + if (restore_position()) + return -1; + } + return static_cast<vertex_id>(_graph->_target->val_int()); +} + + +oqgraph3::weight_t oqgraph3::cursor::get_weight() +{ + if (!_graph->_weight) + return 1.0; + + if (this != _graph->_cursor) + { + if (restore_position()) + return -1; + } + return static_cast<vertex_id>(_graph->_weight->val_int()); +} + +int oqgraph3::cursor::seek_next() +{ + if (this != _graph->_cursor) + { + if (int rc= restore_position()) + return rc; + } + + TABLE& table= *_graph->_table; + + if (_index < 0) + { + // We need to skip over any deleted records we encounter beyond the start of the table. Bug 796647b + int rc; + while ( ((rc= table.file->ha_rnd_next(table.record[0]))) != 0) { + if (rc == HA_ERR_RECORD_DELETED) + continue; + table.file->ha_rnd_end(); + return clear_position(rc); + } + return 0; + } + + if (int rc= table.file->ha_index_next(table.record[0])) + { + table.file->ha_index_end(); + return clear_position(rc); + } + + _graph->_stale= true; + + if ((_origid && vertex_id(_graph->_source->val_int()) != *_origid) || + (_destid && vertex_id(_graph->_target->val_int()) != *_destid)) + { + table.file->ha_index_end(); + return clear_position(ENOENT); + } + + return 0; +} + +int oqgraph3::cursor::seek_prev() +{ + if (this != _graph->_cursor) + { + if (int rc= restore_position()) + return rc; + } + + TABLE& table= *_graph->_table; + + if (_index < 0) + { + return -1; // not supported + } + + if (int rc= table.file->ha_index_prev(table.record[0])) + { + table.file->ha_index_end(); + return clear_position(rc); + } + + _graph->_stale= true; + + if ((_origid && vertex_id(_graph->_source->val_int()) != *_origid) || + (_destid && vertex_id(_graph->_target->val_int()) != *_destid)) + { + table.file->ha_index_end(); + return clear_position(ENOENT); + } + + return 0; +} + + +int oqgraph3::cursor::seek_to( + boost::optional<vertex_id> origid, + boost::optional<vertex_id> destid) +{ + if (_graph->_cursor && this != _graph->_cursor) + _graph->_cursor->save_position(); + + TABLE& table= *_graph->_table; + _index= -1; + _origid= origid; + _destid= destid; + + if (origid || destid) + { + Field *source= _graph->_source; + Field *target= _graph->_target; + + uint source_fieldpos= _graph->_source->offset(table.record[0]); + uint target_fieldpos= _graph->_target->offset(table.record[0]); + + if (!destid) + { + int i= 0; + for( ::KEY *key_info= table.key_info, + *key_end= key_info + table.s->keys; + key_info < key_end; ++key_info, ++i) + { + if (key_info->key_part[0].offset != source_fieldpos) + continue; + + if (table.file->ha_index_init(i, 1)) + continue; + + restore_record(&table, s->default_values); + + bitmap_set_bit(table.write_set, source->field_index); + source->store(*_origid, 1); + bitmap_clear_bit(table.write_set, source->field_index); + + uchar* buff= (uchar*) my_alloca(source->pack_length()); + source->get_key_image(buff, source->pack_length(), Field::itRAW); + _key.clear(); + _key.append((char*) buff, source->pack_length()); + _key.resize(key_info->key_length, '\0'); + my_afree(buff); + + _parts= 1; + _index= i; + break; + } + } + else if (!origid) + { + int i= 0; + for( ::KEY *key_info= table.key_info, + *key_end= key_info + table.s->keys; + key_info < key_end; ++key_info, ++i) + { + if (key_info->key_part[0].offset != target_fieldpos) + continue; + + if (table.file->ha_index_init(i, 1)) + continue; + + restore_record(&table, s->default_values); + + bitmap_set_bit(table.write_set, target->field_index); + target->store(*_destid, 1); + bitmap_clear_bit(table.write_set, target->field_index); + + uchar* buff= (uchar*) my_alloca(target->pack_length()); + target->get_key_image(buff, target->pack_length(), Field::itRAW); + _key.clear(); + _key.append((char*) buff, target->pack_length()); + _key.resize(key_info->key_length, '\0'); + my_afree(buff); + + _parts= 1; + _index= i; + break; + } + } + else + { + int i= 0; + for( ::KEY *key_info= table.key_info, + *key_end= key_info + table.s->keys; + key_info < key_end; ++key_info, ++i) + { + if (key_info->user_defined_key_parts < 2) + continue; + if (!((key_info->key_part[0].offset == target_fieldpos && + key_info->key_part[1].offset == source_fieldpos) || + (key_info->key_part[1].offset == target_fieldpos && + key_info->key_part[0].offset == source_fieldpos))) + continue; + + if (table.file->ha_index_init(i, 1)) + continue; + + restore_record(&table, s->default_values); + + bitmap_set_bit(table.write_set, source->field_index); + source->store(*_origid, 1); + bitmap_clear_bit(table.write_set, source->field_index); + + bitmap_set_bit(table.write_set, target->field_index); + target->store(*_destid, 1); + bitmap_clear_bit(table.write_set, target->field_index); + + Field* first= + key_info->key_part[0].offset == source_fieldpos ? + source : target; + Field* second= + key_info->key_part[0].offset == target_fieldpos ? + target : source; + + uchar* buff= (uchar*) my_alloca( + source->pack_length() + target->pack_length()); + first->get_key_image(buff, first->pack_length(), Field::itRAW); + second->get_key_image(buff + first->pack_length(), second->pack_length(), Field::itRAW); + _key.clear(); + _key.append((char*) buff, source->pack_length() + target->pack_length()); + _key.resize(key_info->key_length, '\0'); + my_afree(buff); + + _parts= 2; + _index= i; + break; + } + } + if (_index < 0) + { + // no suitable index found + return clear_position(ENXIO); + } + + if (int rc= table.file->ha_index_read_map( + table.record[0], (uchar*) _key.data(), + (key_part_map) ((1U << _parts) - 1), + table.key_info[_index].user_defined_key_parts == _parts ? + HA_READ_KEY_EXACT : HA_READ_KEY_OR_NEXT)) + { + table.file->ha_index_end(); + return clear_position(rc); + } + + if ((_origid && vertex_id(_graph->_source->val_int()) != *_origid) || + (_destid && vertex_id(_graph->_target->val_int()) != *_destid)) + { + table.file->ha_index_end(); + return clear_position(ENOENT); + } + } + else + { + int rc; + if ((rc= table.file->ha_rnd_init(true))) + return clear_position(rc); + + // We need to skip over any deleted records we encounter at the start of the table. Bug 796647c + while ( ((rc= table.file->ha_rnd_next(table.record[0]))) != 0) { + if (rc == HA_ERR_RECORD_DELETED) + continue; + table.file->ha_rnd_end(); + return clear_position(rc); + } + } + + _graph->_cursor= this; + _graph->_stale= true; + return 0; +} + +bool oqgraph3::cursor::operator==(const cursor& x) const +{ + return record_position() == x._position; +} + +bool oqgraph3::cursor::operator!=(const cursor& x) const +{ + return record_position() != x._position; +} + +::THD* oqgraph3::graph::get_table_thd() { return _table->in_use; } +void oqgraph3::graph::set_table_thd(::THD* thd) { _table->in_use = thd; } + +oqgraph3::graph::graph( + ::TABLE* table, + ::Field* source, + ::Field* target, + ::Field* weight) + : _ref_count(0) + , _cursor(0) + , _stale(false) + , _rnd_pos((size_t)-1) + , _table(table) + , _source(source) + , _target(target) + , _weight(weight) +{ + bitmap_set_bit(table->read_set, source->field_index); + bitmap_set_bit(table->read_set, target->field_index); + if (weight) + bitmap_set_bit(table->read_set, weight->field_index); + + table->file->column_bitmaps_signal(); +} + +oqgraph3::graph::~graph() +{ } + +oqgraph3::edges_size_type oqgraph3::graph::num_edges() const +{ + return _table->file->stats.records; +} + diff --git a/storage/oqgraph/oqgraph_thunk.h b/storage/oqgraph/oqgraph_thunk.h new file mode 100644 index 00000000..57c21e83 --- /dev/null +++ b/storage/oqgraph/oqgraph_thunk.h @@ -0,0 +1,172 @@ +/* Copyright (C) 2007-2013 Arjen G Lentz & Antony T Curtis for Open Query + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */ + +/* ====================================================================== + Open Query Graph Computation Engine, based on a concept by Arjen Lentz + v3 implementation by Antony Curtis, Arjen Lentz, Andrew McDonnell + For more information, documentation, support, enhancement engineering, + see http://openquery.com/graph or contact graph@openquery.com + ====================================================================== +*/ + +#pragma once + +#include <list> +#include <queue> +#include <string> +#include <utility> + +#include "graphcore-config.h" + +#include <boost/intrusive_ptr.hpp> +#include <boost/optional.hpp> +#include <boost/unordered_map.hpp> +#include <boost/unordered_set.hpp> +#include <boost/pending/queue.hpp> +#include <boost/ptr_container/ptr_deque.hpp> + +#include "graphcore-types.h" + +namespace oqgraph3 +{ + typedef open_query::VertexID vertex_id; + typedef open_query::EdgeWeight weight_t; + + typedef size_t vertices_size_type; + typedef size_t edges_size_type; + typedef size_t degree_size_type; + + struct graph; + struct cursor; + + typedef boost::intrusive_ptr<graph> graph_ptr; + + struct cursor_ptr : public boost::intrusive_ptr<cursor> + { + cursor_ptr() : boost::intrusive_ptr<cursor>() { } + cursor_ptr(cursor* pos) : boost::intrusive_ptr<cursor>(pos) { } + + operator const std::string&() const; + bool operator==(const cursor_ptr&) const; + bool operator!=(const cursor_ptr&) const; + }; + + struct edge_info + { + cursor_ptr _cursor; + + edge_info() : _cursor(0) { } + explicit edge_info(const cursor_ptr& pos) : _cursor(pos) { } + edge_info& operator=(const cursor_ptr& pos) { _cursor= pos; return *this; } + + vertex_id origid() const; + vertex_id destid() const; + weight_t weight() const; + + bool operator==(const edge_info&) const; + bool operator!=(const edge_info&) const; + }; + + struct cursor + { + mutable int _ref_count; + graph_ptr _graph; + + int _index; + unsigned _parts; + std::string _key; + std::string _position; + + int _debugid; + + boost::optional<vertex_id> _origid; + boost::optional<vertex_id> _destid; + + cursor(const graph_ptr& graph); + cursor(const cursor& src); + + ~cursor(); + + operator bool() const + { return !_position.empty(); } + + operator edge_info() const + { return edge_info(const_cast<cursor*>(this)); } + + vertex_id get_origid(); + vertex_id get_destid(); + weight_t get_weight(); + + int seek_to( + boost::optional<vertex_id> origid, + boost::optional<vertex_id> destid); + + int seek_next(); + int seek_prev(); + + void save_position(); + int restore_position(); + const std::string& record_position() const; + void clear_position(); + int clear_position(int rc) { clear_position(); return rc; } + + bool operator==(const cursor& x) const; + bool operator!=(const cursor& x) const; + + friend void intrusive_ptr_add_ref(cursor* ptr) + { ++ptr->_ref_count; } + friend void intrusive_ptr_release(cursor* ptr) + { if (!--(ptr->_ref_count)) delete ptr; } + }; + + struct graph + { + mutable int _ref_count; + cursor* _cursor; + bool _stale; + + cursor_ptr _rnd_cursor; + size_t _rnd_pos; + + ::TABLE* _table; + ::Field* _source; + ::Field* _target; + ::Field* _weight; + + ::THD* get_table_thd(); + void set_table_thd(::THD* thd); + + graph( + ::TABLE* table, + ::Field* source, + ::Field* target, + ::Field* weight= 0); + ~graph(); + + edges_size_type num_edges() const; + + friend edges_size_type num_edges(const graph& g) + { return g.num_edges(); } + + friend void intrusive_ptr_add_ref(graph* ptr) + { ptr->_ref_count++; } + + friend void intrusive_ptr_release(graph* ptr) + { ptr->_ref_count--; } + }; + +} + |