Commit 96b1b908 authored by Andrew McDonnell's avatar Andrew McDonnell

Merge changes from my oqgraph-varchar branch

parents 699e3924 86d03f63
--disable_warnings
DROP TABLE IF EXISTS graph_base;
DROP TABLE IF EXISTS graph;
DROP TABLE IF EXISTS graph2;
--enable_warnings
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;
-- expect fail as follows:
-- ERROR 1146 (42S02): Table 'test.graph_base' doesn't exist
-- because base graph is a necessary precondition at this point
DROP TABLE graph2;
CREATE TABLE graph_base (
from_id INT UNSIGNED NOT NULL,
to_id INT UNSIGNED NOT NULL,
......@@ -10,6 +28,29 @@ CREATE TABLE graph_base (
INDEX (to_id)
) ENGINE=MyISAM;
-- Backwards compat test - should provide a deprecation warning if we do show warnings
SET GLOBAL oqgraph_allow_create_integer_latch=false;
-- We need to expect the following to fail
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';
-- expected:
--| Warning | 140 | Integer latch is not supported for new tables. |
--| Error | 1005 | Can't create table 'test.graph' (errno: 140 "Wrong create options") |
-- Backwards compat testng - should provide a deprecation warning if we do
-- show warnings - and let us create a integer latch so that we can check
-- upgrade behaviour
SET GLOBAL oqgraph_allow_create_integer_latch=true;
CREATE TABLE graph (
latch SMALLINT UNSIGNED NULL,
origid BIGINT UNSIGNED NULL,
......@@ -20,6 +61,22 @@ CREATE TABLE graph (
KEY (latch, origid, destid) USING HASH,
KEY (latch, destid, origid) USING HASH
) ENGINE=OQGRAPH DATA_TABLE='graph_base' ORIGID='from_id', DESTID='to_id';
-- Expected:
-- | 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;
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';
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);
......@@ -28,14 +85,67 @@ INSERT INTO graph_base(from_id, to_id) VALUES (5,6), (6,5);
SELECT * FROM graph WHERE latch = 2 AND origid = 1 AND weight = 1;
-- expected:
-- +-------+--------+--------+--------+------+--------+
-- | latch | origid | destid | weight | seq | linkid |
-- +-------+--------+--------+--------+------+--------+
-- | 2 | 1 | NULL | 1 | 3 | 3 |
-- | 2 | 1 | NULL | 1 | 2 | 2 |
-- +-------+--------+--------+--------+------+--------+
-- reset query cache ; flush query cache;
SELECT * FROM graph2 WHERE latch = 'breadth_first' AND origid = 1 AND weight = 1; -- works
SELECT * FROM graph2 WHERE latch = '2' AND origid = 1 AND weight = 1; -- as above
-- above works, we allow stringized latch integer to ease migration
SELECT * FROM graph2 WHERE latch = 2 AND origid = 1 AND weight = 1;
-- Expect the above to fail due to autocast and use of deprecated syntax...
SELECT * FROM graph2 WHERE latch='dijkstras' AND origid=1 AND destid=6;
SELECT * FROM graph2 WHERE latch='1' AND origid=1 AND destid=6;
SELECT * FROM graph2 WHERE latch='dijkstras' AND origid=1 AND destid=4;
SELECT * FROM graph2 WHERE latch='1' AND origid=1 AND destid=4;
SELECT * FROM graph2 WHERE latch='dijkstras' AND origid=4 AND destid=1;
SELECT * FROM graph2 WHERE latch='1' AND origid=4 AND destid=1;
SELECT * FROM graph2 WHERE latch='no_search' and destid=2 and origid=1; -- works
SELECT * FROM graph2 WHERE latch=0 and destid=2 and origid=1;
-- Expect the above to fail due to autocast...
-- FIXME SELECT * FROM graph2 WHERE latch='0' and destid=2 and origid=1; -- causes assertion (at least in debug build, havent tested normal)
-- sql/mysqld(my_print_stacktrace+0x35)[0xdbbc02]
-- sql/mysqld(handle_fatal_signal+0x355)[0x7dfd05]
-- /lib/libpthread.so.0(+0xeff0)[0x7f4810addff0]
-- /lib/libc.so.6(gsignal+0x35)[0x7f480feda1b5]
-- /lib/libc.so.6(abort+0x180)[0x7f480fedcfc0]
-- /lib/libc.so.6(__assert_fail+0xf1)[0x7f480fed3301]
-- sql/mysqld(_ZN7handler8ha_resetEv+0x8b)[0x7eb6a9]
-- sql/mysqld(_Z18close_thread_tableP3THDPP5TABLE+0x297)[0x5b1207]
-- sql/mysqld[0x5b09c4]
-- sql/mysqld(_Z19close_thread_tablesP3THD+0x33f)[0x5b0f5d]
-- sql/mysqld(_Z21mysql_execute_commandP3THD+0x7fe9)[0x61cc6b]
-- sql/mysqld(_Z11mysql_parseP3THDPcjP12Parser_state+0x268)[0x61f9ec]
-- sql/mysqld(_Z16dispatch_command19enum_server_commandP3THDPcj+0xc3e)[0x6129ba]
-- sql/mysqld(_Z10do_commandP3THD+0x33f)[0x611b35]
-- sql/mysqld(_Z24do_handle_one_connectionP3THD+0x1f6)[0x721ba9]
-- sql/mysqld(handle_one_connection+0x33)[0x721651]
-- /lib/libpthread.so.0(+0x68ca)[0x7f4810ad58ca]
-- /lib/libc.so.6(clone+0x6d)[0x7f480ff7792d]
SELECT * FROM graph2 WHERE latch=NULL and destid=2 and origid=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);
SELECT * FROM graph2 WHERE latch = 'breadth_first' AND origid = 1 AND (weight = 1 OR weight = 2);
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;
INSERT INTO graph_base (from_id,to_id) VALUES (4,6);
DELETE FROM graph_base WHERE from_id=5;
......@@ -44,8 +154,16 @@ DELETE FROM graph_base WHERE from_id=3 AND to_id=5;
SELECT * FROM graph WHERE latch=1 AND origid=1 AND destid=6;
SELECT * FROM graph WHERE latch=1 AND origid=6 AND destid=1;
SELECT * FROM graph2 WHERE latch='dijkstras' AND origid=1 AND destid=6;
SELECT * FROM graph2 WHERE latch='dijkstras' AND origid=6 AND destid=1;
DELETE FROM graph_base;
FLUSH TABLES;
TRUNCATE TABLE graph_base;
DROP TABLE graph, graph_base;
SELECT * FROM graph2 WHERE latch='dijkstras' AND origid=1 AND destid=6;
-- expect fail as follows:
-- ERROR 1146 (42S02): Table 'test.graph_base' doesn't exist
-- because base graph is a necessary precondition at this point
......@@ -23,6 +23,7 @@
*/
#include <string.h>
#include <cstdlib>
#include "graphcore-config.h"
#include "graphcore-graph.h"
......@@ -46,7 +47,7 @@
using namespace open_query;
using namespace boost;
static const row empty_row = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
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;
......@@ -411,11 +412,12 @@ namespace open_query {
namespace open_query
{
inline oqgraph::oqgraph(oqgraph_share *arg) throw()
: share(arg), cursor(0)
: share(arg), cursor(0), lastRetainedLatch(NULL)
{ }
inline oqgraph::~oqgraph() throw()
{
std::free(lastRetainedLatch);
delete cursor;
}
......@@ -669,25 +671,33 @@ namespace open_query
}
#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); }
}
int oqgraph::search(int *latch, VertexID *orig_id, VertexID *dest_id) throw()
{
optional<Vertex> orig, dest;
int op= 0, seq= 0;
enum {
NO_SEARCH = 0,
DIJKSTRAS = 1,
BREADTH_FIRST = 2,
ALGORITHM = 0x0ffff,
HAVE_ORIG = 0x10000,
HAVE_DEST = 0x20000,
};
delete cursor; cursor= 0;
row_info= empty_row;
if ((row_info.latch_indicator= latch))
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))
......
......@@ -45,6 +45,8 @@ namespace open_query
bool link_indicator;
int latch;
const char* latchStringValue; // workaround for when latch is a Varchar
int latchStringValueLen;
VertexID orig;
VertexID dest;
EdgeWeight weight;
......@@ -62,6 +64,18 @@ namespace open_query
inline ~oqgraph() throw();
public:
// Integer operation flags
enum {
NO_SEARCH = 0,
DIJKSTRAS = 1,
BREADTH_FIRST = 2,
NUM_SEARCH_OP = 3,
ALGORITHM = 0x0ffff,
HAVE_ORIG = 0x10000,
HAVE_DEST = 0x20000,
};
enum error_code
{
OK= 0,
......@@ -94,6 +108,13 @@ namespace open_query
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();
......@@ -108,6 +129,8 @@ namespace open_query
static void free(oqgraph_share*) throw();
static const size_t sizeof_ref;
private:
char *lastRetainedLatch;
};
}
......
This diff is collapsed.
......@@ -110,6 +110,8 @@ public:
void fprint_error(const char* fmt, ...);
private:
int oqgraph_check_table_structure (TABLE *table_arg);
void update_key_stats();
String error_message;
};
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment