Commit af2129f9 authored by Sergey Vojtovich's avatar Sergey Vojtovich

MDEV-5319 - Request for merge of Oqgraph v3 functionality storage/oqgraph

            into 10.0
parents 03f6778d 01c514fc
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
# 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 3 7
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 2 3 7
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 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 12
breadth_first NULL 10 1 2 11
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 10
breadth_first NULL 11 1 2 12
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 11
breadth_first NULL 12 1 2 10
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 3 7
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
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 11
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 12
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 10
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
breadth_first NULL 6 2 3 7
SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 7 and weight = 2;
latch origid destid weight seq linkid
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 12
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 10
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 11
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 3 7
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 2 3 7
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 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 12
2 NULL 10 1 2 11
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 10
2 NULL 11 1 2 12
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 11
2 NULL 12 1 2 10
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 3 7
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
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 11
SELECT * FROM graph WHERE latch = '2' AND destid = 11 and weight = 1;
latch origid destid weight seq linkid
2 NULL 11 1 2 12
SELECT * FROM graph WHERE latch = '2' AND destid = 12 and weight = 1;
latch origid destid weight seq linkid
2 NULL 12 1 2 10
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
2 NULL 6 2 3 7
SELECT * FROM graph WHERE latch = '2' AND destid = 7 and weight = 2;
latch origid destid weight seq linkid
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 12
SELECT * FROM graph WHERE latch = '2' AND destid = 11 and weight = 2;
latch origid destid weight seq linkid
2 NULL 11 2 3 10
SELECT * FROM graph WHERE latch = '2' AND destid = 12 and weight = 2;
latch origid destid weight seq linkid
2 NULL 12 2 3 11
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 3 7
dijkstras NULL 5 1 2 6
dijkstras NULL 5 0 1 5
SELECT * FROM graph WHERE latch='dijkstras' AND destid=6;
latch origid destid weight seq linkid
dijkstras NULL 6 2 3 7
dijkstras NULL 6 1 2 5
dijkstras NULL 6 0 1 6
SELECT * FROM graph WHERE latch='dijkstras' AND destid=7;
latch origid destid weight seq linkid
dijkstras NULL 7 0 1 7
SELECT * FROM graph WHERE latch='dijkstras' AND destid=8;
latch origid destid weight seq linkid
SELECT * FROM graph WHERE latch='dijkstras' AND destid=9;
latch origid destid weight seq linkid
dijkstras NULL 9 0 1 9
SELECT * FROM graph WHERE latch='dijkstras' AND destid=10;
latch origid destid weight seq linkid
dijkstras NULL 10 2 3 12
dijkstras NULL 10 1 2 11
dijkstras NULL 10 0 1 10
SELECT * FROM graph WHERE latch='dijkstras' AND destid=11;
latch origid destid weight seq linkid
dijkstras NULL 11 2 3 10
dijkstras NULL 11 1 2 12
dijkstras NULL 11 0 1 11
SELECT * FROM graph WHERE latch='dijkstras' AND destid=12;
latch origid destid weight seq linkid
dijkstras NULL 12 2 3 11
dijkstras NULL 12 1 2 10
dijkstras NULL 12 0 1 12
# legacy string number
SELECT * FROM graph WHERE latch='1' AND origid=1 AND destid=1;
latch origid destid weight seq linkid
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 3 7
1 NULL 5 1 2 6
1 NULL 5 0 1 5
SELECT * FROM graph WHERE latch='1' AND destid=6;
latch origid destid weight seq linkid
1 NULL 6 2 3 7
1 NULL 6 1 2 5
1 NULL 6 0 1 6
SELECT * FROM graph WHERE latch='1' AND destid=7;
latch origid destid weight seq linkid
1 NULL 7 0 1 7
SELECT * FROM graph WHERE latch='1' AND destid=8;
latch origid destid weight seq linkid
SELECT * FROM graph WHERE latch='1' AND destid=9;
latch origid destid weight seq linkid
1 NULL 9 0 1 9
SELECT * FROM graph WHERE latch='1' AND destid=10;
latch origid destid weight seq linkid
1 NULL 10 2 3 12
1 NULL 10 1 2 11
1 NULL 10 0 1 10
SELECT * FROM graph WHERE latch='1' AND destid=11;
latch origid destid weight seq linkid
1 NULL 11 2 3 10
1 NULL 11 1 2 12
1 NULL 11 0 1 11
SELECT * FROM graph WHERE latch='1' AND destid=12;
latch origid destid weight seq linkid
1 NULL 12 2 3 11
1 NULL 12 1 2 10
1 NULL 12 0 1 12
INSERT INTO graph_base(from_id, to_id) VALUES (11,13);
INSERT INTO graph_base(from_id, to_id) VALUES (10,14);
INSERT INTO graph_base(from_id, to_id) VALUES (14,13);
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 4 7 18
dijkstras NULL 1 3 6 17
dijkstras NULL 1 3 5 16
dijkstras NULL 1 2 4 4
dijkstras NULL 1 1 3 3
dijkstras NULL 1 1 2 2
dijkstras NULL 1 0 1 1
# Now we add a connection from 4->6
INSERT INTO graph_base (from_id,to_id) VALUES (4,6);
# And delete all references to node 5
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;
--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;
--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 = 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.
DROP TABLE IF EXISTS graph_base;
DROP TABLE IF EXISTS graph;
DROP TABLE IF EXISTS graph2;
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 dont 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;
--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';
# 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 dont 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 dont 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;
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 (unspecified or empty data_table attribute)'
DESCRIBE oqtable;
ERROR HY000: Got error -1 'Invalid OQGRAPH backing store (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 (unspecified or empty data_table attribute)'
DESCRIBE oqtable;
ERROR HY000: Got error -1 'Invalid OQGRAPH backing store (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 (unspecified or empty data_table attribute)'
DESCRIBE oqtable;
ERROR HY000: Got error -1 'Invalid OQGRAPH backing store (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 (unspecified or empty data_table attribute)'
DESCRIBE oqtable;
ERROR HY000: Got error -1 'Invalid OQGRAPH backing store (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 (unspecified or empty data_table attribute)'
DESCRIBE oqtable;
ERROR HY000: Got error -1 'Invalid OQGRAPH backing store (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 (unspecified or empty origid attribute)'
DESCRIBE oqtable;
ERROR HY000: Got error -1 'Invalid OQGRAPH backing store (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 (unspecified or empty origid attribute)'
DESCRIBE oqtable;
ERROR HY000: Got error -1 'Invalid OQGRAPH backing store (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 (unspecified or empty origid attribute)'
DESCRIBE oqtable;
ERROR HY000: Got error -1 'Invalid OQGRAPH backing store (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 (unspecified or empty destid attribute)'
DESCRIBE oqtable;
ERROR HY000: Got error -1 'Invalid OQGRAPH backing store (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 (unspecified or empty destid attribute)'
DESCRIBE oqtable;
ERROR HY000: Got error -1 'Invalid OQGRAPH backing store (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 origi' 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;
--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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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
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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 origi' 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' 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;
--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 dont 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;
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 (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;
--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 (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;
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_base;
DROP TABLE graph;
--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_base;
DROP TABLE graph;
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;
--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 dont 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 dont 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;
drop table if exists graph;
Warnings:
Note 1051 Unknown table 'test.graph'
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;
delete from graph;
insert into graph(origid, destid) values (1,2), (2,1);
insert into graph(origid, destid) values (1,3), (3,1);
insert into graph(origid, destid) values (3,4), (4,3);
insert into graph(origid, destid) values (3,5), (5,3);
insert into graph(origid, destid) values (5,6), (6,5);
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 5 5
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 5 5
2 1 NULL 2 4 4
2 1 NULL 1 3 3
2 1 NULL 1 2 2
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 5
1 1 6 1 3 6
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
insert into graph (origid,destid) values (4,6);
delete from graph where origid=5;
delete from graph where origid=3 and destid=5;
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
truncate table graph;
drop table graph;
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;
# 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
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;
# 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;
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;
# 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;
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;
# 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;
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;
# 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;
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 784 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 768 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 1024 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;
# 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;
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 3 7
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 2 3 7
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 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 12
breadth_first NULL 10 1 2 11
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 10
breadth_first NULL 11 1 2 12
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 11
breadth_first NULL 12 1 2 10
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 3 7
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
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 11
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 12
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 10
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
breadth_first NULL 6 2 3 7
SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 7 and weight = 2;
latch origid destid weight seq linkid
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 12
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 10
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 11
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 11
2 NULL 12 1 2 10
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 3 7
dijkstras NULL 5 1 2 6
dijkstras NULL 5 0 1 5
SELECT * FROM graph WHERE latch='dijkstras' AND destid=6;
latch origid destid weight seq linkid
dijkstras NULL 6 2 3 7
dijkstras NULL 6 1 2 5
dijkstras NULL 6 0 1 6
SELECT * FROM graph WHERE latch='dijkstras' AND destid=7;
latch origid destid weight seq linkid
dijkstras NULL 7 0 1 7
SELECT * FROM graph WHERE latch='dijkstras' AND destid=8;
latch origid destid weight seq linkid
SELECT * FROM graph WHERE latch='dijkstras' AND destid=9;
latch origid destid weight seq linkid
dijkstras NULL 9 0 1 9
SELECT * FROM graph WHERE latch='dijkstras' AND destid=10;
latch origid destid weight seq linkid
dijkstras NULL 10 2 3 12
dijkstras NULL 10 1 2 11
dijkstras NULL 10 0 1 10
SELECT * FROM graph WHERE latch='dijkstras' AND destid=11;
latch origid destid weight seq linkid
dijkstras NULL 11 2 3 10
dijkstras NULL 11 1 2 12
dijkstras NULL 11 0 1 11
SELECT * FROM graph WHERE latch='dijkstras' AND destid=12;
latch origid destid weight seq linkid
dijkstras NULL 12 2 3 11
dijkstras NULL 12 1 2 10
dijkstras NULL 12 0 1 12
# legacy string number
SELECT * FROM graph WHERE latch='1' AND origid=1 AND destid=1;
latch origid destid weight seq linkid
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 3 7
1 NULL 5 1 2 6
1 NULL 5 0 1 5
SELECT * FROM graph WHERE latch='1' AND destid=6;
latch origid destid weight seq linkid
1 NULL 6 2 3 7
1 NULL 6 1 2 5
1 NULL 6 0 1 6
SELECT * FROM graph WHERE latch='1' AND destid=7;
latch origid destid weight seq linkid
1 NULL 7 0 1 7
SELECT * FROM graph WHERE latch='1' AND destid=8;
latch origid destid weight seq linkid
SELECT * FROM graph WHERE latch='1' AND destid=9;
latch origid destid weight seq linkid
1 NULL 9 0 1 9
SELECT * FROM graph WHERE latch='1' AND destid=10;
latch origid destid weight seq linkid
1 NULL 10 2 3 12
1 NULL 10 1 2 11
1 NULL 10 0 1 10
SELECT * FROM graph WHERE latch='1' AND destid=11;
latch origid destid weight seq linkid
1 NULL 11 2 3 10
1 NULL 11 1 2 12
1 NULL 11 0 1 11
SELECT * FROM graph WHERE latch='1' AND destid=12;
latch origid destid weight seq linkid
1 NULL 12 2 3 11
1 NULL 12 1 2 10
1 NULL 12 0 1 12
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 4 7 18
dijkstras NULL 1 3 6 17
dijkstras NULL 1 3 5 16
dijkstras NULL 1 2 4 4
dijkstras NULL 1 1 3 3
dijkstras NULL 1 1 2 2
dijkstras NULL 1 0 1 1
# Now we add a connection from 4->6
INSERT INTO graph_base (from_id,to_id) VALUES (4,6);
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;
--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;
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 (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;
--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 (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;
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;
-- source include/have_log_bin.inc
--disable_warnings
drop table if exists graph;
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 SMALLINT UNSIGNED NULL,
latch VARCHAR(32) NULL,
origid BIGINT UNSIGNED NULL,
destid BIGINT UNSIGNED NULL,
weight DOUBLE NULL,
......@@ -13,15 +23,21 @@ CREATE TABLE graph (
linkid BIGINT UNSIGNED NULL,
KEY (latch, origid, destid) USING HASH,
KEY (latch, destid, origid) USING HASH
) ENGINE=OQGRAPH;
# MBug#524625: OQGraph error with binary logging enabled
# Test that OQGraph works with different binlogging modes.
SET binlog_format = row;
insert into graph(origid, destid) values (1,3), (3,1);
SET binlog_format = statement;
insert into graph(origid, destid) values (3,4), (4,3);
SET binlog_format = mixed;
insert into graph(origid, destid) values (3,5), (5,3);
drop table graph;
) 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;
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;
--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;
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;
--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;
drop table if exists graph;
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 SMALLINT UNSIGNED NULL,
latch VARCHAR(32) NULL,
origid BIGINT UNSIGNED NULL,
destid BIGINT UNSIGNED NULL,
weight DOUBLE NULL,
......@@ -8,11 +15,14 @@ seq BIGINT UNSIGNED NULL,
linkid BIGINT UNSIGNED NULL,
KEY (latch, origid, destid) USING HASH,
KEY (latch, destid, origid) USING HASH
) ENGINE=OQGRAPH;
SET binlog_format = row;
insert into graph(origid, destid) values (1,3), (3,1);
SET binlog_format = statement;
insert into graph(origid, destid) values (3,4), (4,3);
SET binlog_format = mixed;
insert into graph(origid, destid) values (3,5), (5,3);
drop table graph;
) 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;
--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 * 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
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;
--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;
drop table if exists graph;
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;
delete from graph;
insert into graph(origid, destid) values (1,2), (2,1);
insert into graph(origid, destid) values (1,3), (3,1);
insert into graph(origid, destid) values (3,4), (4,3);
insert into graph(origid, destid) values (3,5), (5,3);
insert into graph(origid, destid) values (5,6), (6,5);
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);
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 (origid,destid) values (4,6);
delete from graph where origid=5;
delete from graph where origid=3 and destid=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;
truncate table graph;
drop table graph;
FIND_PACKAGE(Boost 1.40.0)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
MESSAGE(STATUS "Configuring OQGraph")
FIND_PACKAGE(Boost)
IF(NOT Boost_FOUND)
MESSAGE(STATUS "Boost not found")
RETURN()
ENDIF()
INCLUDE_DIRECTORIES(BEFORE ${Boost_INCLUDE_DIRS})
SET(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${Boost_INCLUDE_DIRS})
FIND_PACKAGE(Judy)
IF(NOT Judy_FOUND)
MESSAGE(STATUS "Judy not found")
RETURN()
ENDIF()
INCLUDE_DIRECTORIES(${Judy_INCLUDE_DIR})
IF(MSVC)
# lp:756966 OQGRAPH on Win64 does not compile
......@@ -16,6 +26,8 @@ ELSE()
# See if that works. On old gcc it'll fail because of -fno-rtti
CHECK_CXX_SOURCE_COMPILES(
"
#define BOOST_NO_RTTI 1
#define BOOST_NO_TYPEID 1
#include <boost/config.hpp>
#include <boost/property_map/property_map.hpp>
int main() { return 0; }
......@@ -27,13 +39,19 @@ IF(BOOST_OK)
IF(MSVC)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc")
ELSE(MSVC)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated -fno-strict-aliasing")
# Fix lp bug 1221555 with -fpermissive, so that errors in gcc 4.7 become warnings for the time being
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated -fno-strict-aliasing -fpermissive")
STRING(REPLACE "-fno-exceptions" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
STRING(REPLACE "-fno-implicit-templates" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
ENDIF(MSVC)
SET(OQGRAPH_DEB_FILES "usr/lib/mysql/plugin/ha_oqgraph.so" PARENT_SCOPE)
ADD_DEFINITIONS(-DBOOST_NO_RTTI=1 -DBOOST_NO_TYPEID=1 -DBOOST_DISABLE_ASSERTS=1)
MYSQL_ADD_PLUGIN(oqgraph ha_oqgraph.cc graphcore.cc STORAGE_ENGINE
MODULE_ONLY)
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
LINK_LIBRARIES ${Judy_LIBRARIES})
ELSE(BOOST_OK)
MESSAGE(STATUS "Requisites for OQGraph not met")
ENDIF(BOOST_OK)
OQGraph storage engine
Copyright (C) 2007-2009 Arjen G Lentz & Antony T Curtis for Open Query
OQGraph storage engine v3
Copyright (C) 2007-2013 Arjen G Lentz & Antony T Curtis for Open Query
The Open Query GRAPH engine (OQGRAPH) is a computation engine allowing
hierarchies and more complex graph structures to be handled in a
......@@ -7,7 +7,11 @@ 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.
See http://openquery.com/graph for more information.
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
......
# - Try to find 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 (Judy_INCLUDE_DIR AND Judy_LIBRARIES)
SET(Judy_FIND_QUIETLY TRUE)
ENDIF (Judy_INCLUDE_DIR AND Judy_LIBRARIES)
FIND_PATH(Judy_INCLUDE_DIR Judy.h)
FIND_LIBRARY(Judy_LIBRARIES NAMES Judy)
IF (Judy_INCLUDE_DIR AND Judy_LIBRARIES)
SET(Judy_FOUND TRUE)
ELSE (Judy_INCLUDE_DIR AND Judy_LIBRARIES)
SET(Judy_FOUND FALSE)
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)
/* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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
#ifdef DBUG_OFF
#define NDEBUG 1
#endif
#include <boost/config.hpp>
#endif
/* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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-config.h"
#include "graphcore-graph.h"
/* Copyright (C) 2007-2009 Arjen G Lentz & Antony T Curtis for Open Query
/* 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
......@@ -16,33 +16,151 @@
/* ======================================================================
Open Query Graph Computation Engine, based on a concept by Arjen Lentz
Mk.II implementation by Antony Curtis & Arjen Lentz
v3 implementation by Antony Curtis, Arjen Lentz, Andrew McDonnell
For more information, documentation, support, enhancement engineering,
and non-GPL licensing, see http://openquery.com/graph
or contact graph@openquery.com
For packaged binaries, see http://ourdelta.org
see http://openquery.com/graph or contact graph@openquery.com
======================================================================
*/
#ifndef oq_graphcore_graph_h_
#define oq_graphcore_graph_h_
typedef adjacency_list
<
vecS,
vecS,
bidirectionalS,
VertexInfo,
EdgeInfo
> Graph;
#include "oqgraph_shim.h"
#define GRAPH_WEIGHTMAP(G) get(&EdgeInfo::weight, G)
typedef property_map<Graph, EdgeWeight EdgeInfo::*>::type weightmap_type;
#include <boost/graph/two_bit_color_map.hpp>
#define GRAPH_INDEXMAP(G) get(vertex_index, G)
typedef property_map<Graph, vertex_index_t>::type indexmap_type;
namespace boost
{
typedef oqgraph3::graph Graph;
#define GRAPH_IDMAP(G) get(&VertexInfo::id, G)
typedef property_map<Graph, VertexID VertexInfo::*>::type idmap_type;
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
/* Copyright (C) 2007-2009 Arjen G Lentz & Antony T Curtis for Open Query
/* 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
......@@ -16,16 +16,15 @@
/* ======================================================================
Open Query Graph Computation Engine, based on a concept by Arjen Lentz
Mk.II implementation by Antony Curtis & Arjen Lentz
v3 implementation by Antony Curtis, Arjen Lentz, Andrew McDonnell
For more information, documentation, support, enhancement engineering,
and non-GPL licensing, see http://openquery.com/graph
or contact graph@openquery.com
For packaged binaries, see http://ourdelta.org
see http://openquery.com/graph or contact graph@openquery.com
======================================================================
*/
#ifndef oq_graphcore_types_h_
#define oq_graphcore_types_h_
namespace open_query
{
......@@ -33,4 +32,9 @@ namespace open_query
typedef double EdgeWeight;
}
class Field;
typedef struct TABLE TABLE;
#endif
/* Copyright (C) 2007-2009 Arjen G Lentz & Antony T Curtis for Open Query
/* 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
......@@ -16,28 +16,23 @@
/* ======================================================================
Open Query Graph Computation Engine, based on a concept by Arjen Lentz
Mk.II implementation by Antony Curtis & Arjen Lentz
v3 implementation by Antony Curtis, Arjen Lentz, Andrew McDonnell
For more information, documentation, support, enhancement engineering,
and non-GPL licensing, see http://openquery.com/graph
or contact graph@openquery.com
For packaged binaries, see http://ourdelta.org
see http://openquery.com/graph or contact graph@openquery.com
======================================================================
*/
#include <string.h>
#include <cstdlib>
#define BOOST_ALL_NO_LIB 1
#include <boost/config.hpp>
#include "graphcore-config.h"
#include "graphcore-graph.h"
#include <set>
#include <stack>
#include <boost/property_map/property_map.hpp>
#include <boost/graph/graph_concepts.hpp>
#include <boost/graph/graph_archetypes.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/breadth_first_search.hpp>
#include <boost/graph/dijkstra_shortest_paths.hpp>
#include <boost/graph/iteration_macros.hpp>
......@@ -46,54 +41,19 @@
#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 };
namespace open_query
{
enum vertex_id_t { vertex_id };
struct VertexInfo {
inline VertexInfo() { }
inline VertexInfo(VertexID _id)
: id(_id) { }
VertexID id;
};
struct EdgeInfo {
EdgeWeight weight;
};
}
static const row empty_row = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
namespace boost
{
BOOST_INSTALL_PROPERTY(vertex, id);
namespace graph
{
template<>
struct internal_vertex_name<VertexInfo>
{
typedef multi_index::member<VertexInfo, VertexID, &VertexInfo::id> type;
};
template<>
struct internal_vertex_constructor<VertexInfo>
{
typedef vertex_from_name<VertexInfo> type;
};
}
}
extern "C" const char* const oqgraph_boost_version= BOOST_LIB_VERSION;
namespace open_query
{
#include "graphcore-graph.h"
typedef graph_traits<Graph>::vertex_descriptor Vertex;
typedef graph_traits<Graph>::edge_descriptor Edge;
......@@ -187,6 +147,17 @@ namespace open_query
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()),
......@@ -202,7 +173,8 @@ namespace open_query
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_sequence(s), m_vertex(v),
m_edge(), m_weight(0)
{
if (w) m_weight= *w;
if (e) m_edge= *e;
......@@ -261,18 +233,15 @@ namespace open_query {
public:
Graph g;
weightmap_type weightmap;
idmap_type idmap;
indexmap_type indexmap;
optional<Vertex> find_vertex(VertexID id) const;
optional<Edge> find_edge(Vertex, Vertex) const;
inline oqgraph_share() throw()
: g(),
weightmap(GRAPH_WEIGHTMAP(g)),
idmap(GRAPH_IDMAP(g)),
indexmap(GRAPH_INDEXMAP(g))
inline oqgraph_share(
TABLE* table,
Field* origid,
Field* destid,
Field* weight) throw()
: g(table, origid, destid, weight)
{ }
inline ~oqgraph_share()
{ }
......@@ -360,13 +329,13 @@ namespace open_query {
}
};
template <typename P, typename D>
struct GRAPHCORE_INTERNAL oqgraph_visit_dist
: public base_visitor<oqgraph_visit_dist>
: public base_visitor< oqgraph_visit_dist<P,D> >
{
typedef on_finish_vertex event_filter;
oqgraph_visit_dist(std::vector<Vertex>::iterator p,
std::vector<EdgeWeight>::iterator d,
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); }
......@@ -374,22 +343,28 @@ namespace open_query {
template<class T, class Graph>
void operator()(T u, Graph &g)
{
m_cursor.results.push(reference(++seq, u, m_d[GRAPH_INDEXMAP(g)[u]]));
m_cursor.results.push(reference(++seq, u, m_d[ u ]));
}
private:
int seq;
stack_cursor &m_cursor;
std::vector<Vertex>::iterator m_p;
std::vector<EdgeWeight>::iterator m_d;
P m_p;
D m_d;
};
template<bool record_weight, typename goal_filter>
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> >
: public base_visitor<oqgraph_goal<record_weight,goal_filter,P> >
{
typedef goal_filter event_filter;
oqgraph_goal(Vertex goal, std::vector<Vertex>::iterator p,
oqgraph_goal(const Vertex& goal, const P& p,
stack_cursor *cursor)
: m_goal(goal), m_cursor(*cursor), m_p(p)
{ assert(cursor); }
......@@ -400,17 +375,16 @@ namespace open_query {
if (u == m_goal)
{
int seq= 0;
indexmap_type indexmap= GRAPH_INDEXMAP(g);
for (Vertex q, v= u;; v = q, seq++)
if ((q= m_p[ indexmap[v] ]) == v)
if ((q= m_p[ v ]) == v)
break;
for (Vertex v= u;; u= v)
{
optional<Edge> edge;
optional<EdgeWeight> weight;
v= m_p[ indexmap[u] ];
v= m_p[ u ];
if (record_weight && u != v)
{
typename graph_traits<Graph>::out_edge_iterator ei, ei_end;
......@@ -419,7 +393,7 @@ namespace open_query {
if (target(*ei, g) == u)
{
edge= *ei;
weight= GRAPH_WEIGHTMAP(g)[*ei];
weight= get(boost::edge_weight, g, *ei);
break;
}
}
......@@ -437,18 +411,25 @@ namespace open_query {
private:
Vertex m_goal;
stack_cursor &m_cursor;
std::vector<Vertex>::iterator m_p;
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)
: share(arg), cursor(0), lastRetainedLatch(NULL)
{ }
inline oqgraph::~oqgraph() throw()
{
std::free(lastRetainedLatch);
delete cursor;
}
......@@ -468,9 +449,14 @@ namespace open_query
return new (std::nothrow) oqgraph(share);
}
oqgraph_share* oqgraph::create() throw()
oqgraph_share* oqgraph::create(
TABLE* table,
Field* origid,
Field* destid,
Field* weight) throw()
{
return new (std::nothrow) oqgraph_share();
return new (std::nothrow) oqgraph_share(
table, origid, destid, weight);
}
optional<Edge>
......@@ -479,15 +465,15 @@ namespace open_query
if (in_degree(dest, g) >= out_degree(orig, g))
{
graph_traits<Graph>::out_edge_iterator ei, ei_end;
boost::tuples::tie(ei, ei_end)= out_edges(orig, g);
if ((ei= find_if(ei, ei_end, target_equals(dest, g))) != 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;
boost::tuples::tie(ei, ei_end)= in_edges(dest, g);
if ((ei= find_if(ei, ei_end, source_equals(orig, g))) != 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>();
......@@ -496,9 +482,10 @@ namespace open_query
optional<Vertex>
oqgraph_share::find_vertex(VertexID id) const
{
return boost::graph::find_vertex(id, g);
return ::boost::find_vertex(id, g);
}
#if 0
int oqgraph::delete_all() throw()
{
share->g.clear();
......@@ -598,8 +585,9 @@ namespace open_query
optional<Vertex> orig= source(*edge, share->g),
dest= target(*edge, share->g);
bool orig_neq= orig_id ? share->idmap[*orig] != *orig_id : 0;
bool dest_neq= dest_id ? share->idmap[*dest] != *dest_id : 0;
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;
......@@ -675,7 +663,6 @@ namespace open_query
return OK;
}
int oqgraph::delete_edge(VertexID orig_id, VertexID dest_id) throw()
{
optional<Vertex> orig, dest;
......@@ -694,26 +681,47 @@ namespace open_query
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;
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))
......@@ -731,7 +739,8 @@ namespace open_query
{
Vertex v= target(*ei, share->g);
static_cast<stack_cursor*>(cursor)->
results.push(reference(++seq, v, *ei, share->weightmap[*ei]));
results.push(reference(++seq, v, *ei,
get(boost::edge_weight, share->g, *ei)));
}
}
/* fall through */
......@@ -745,7 +754,8 @@ namespace open_query
{
Vertex v= source(*ei, share->g);
static_cast<stack_cursor*>(cursor)->
results.push(reference(++seq, v, *ei, share->weightmap[*ei]));
results.push(reference(++seq, v, *ei,
get(boost::edge_weight, share->g, *ei)));
}
}
break;
......@@ -757,27 +767,29 @@ namespace open_query
case DIJKSTRAS | HAVE_ORIG | HAVE_DEST:
if ((cursor= new (std::nothrow) stack_cursor(share)) && orig && dest)
{
std::vector<Vertex> p(num_vertices(share->g));
std::vector<EdgeWeight> d(num_vertices(share->g));
oqgraph_goal<true, on_finish_vertex>
vis(*dest, p.begin(), static_cast<stack_cursor*>(cursor));
p[share->indexmap[*orig]]= *orig;
boost::unordered_map<Vertex, Vertex> p;
boost::unordered_map<Vertex, EdgeWeight> d;
p[ *orig ]= *orig;
d[ *orig ] = EdgeWeight();
try
{
dijkstra_shortest_paths(share->g, *orig,
weight_map(
share->weightmap
).
distance_map(
make_iterator_property_map(d.begin(), share->indexmap)
).
predecessor_map(
make_iterator_property_map(p.begin(), share->indexmap)
).
visitor(
make_dijkstra_visitor(vis)
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"); */ }
......@@ -787,23 +799,25 @@ namespace open_query
case BREADTH_FIRST | HAVE_ORIG | HAVE_DEST:
if ((cursor= new (std::nothrow) stack_cursor(share)) && orig && dest)
{
std::vector<Vertex> p(num_vertices(share->g));
oqgraph_goal<false, on_discover_vertex>
vis(*dest, p.begin(), static_cast<stack_cursor*>(cursor));
p[share->indexmap[*orig]]= *orig;
boost::unordered_map<Vertex, Vertex> p;
boost::queue<Vertex> Q;
p[ *orig ]= *orig;
try
{
breadth_first_search(share->g, *orig,
visitor(make_bfs_visitor(
breadth_first_visit(share->g, *orig, Q,
make_bfs_visitor(
std::make_pair(
record_predecessors(
make_iterator_property_map(p.begin(), share->indexmap),
boost::make_assoc_property_map(p),
on_tree_edge()
),
vis)
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"); */ }
......@@ -814,109 +828,117 @@ namespace open_query
case BREADTH_FIRST | HAVE_ORIG:
if ((cursor= new (std::nothrow) stack_cursor(share)) && (orig || dest))
{
std::vector<Vertex> p(num_vertices(share->g));
std::vector<EdgeWeight> d(num_vertices(share->g));
oqgraph_visit_dist vis(p.begin(), d.begin(),
static_cast<stack_cursor*>(cursor));
p[share->indexmap[*orig]]= *orig;
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(share->g, *orig,
weight_map(
share->weightmap
).
distance_map(
make_iterator_property_map(d.begin(), share->indexmap)
).
predecessor_map(
make_iterator_property_map(p.begin(), share->indexmap)
).
visitor(
make_dijkstra_visitor(vis)
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_search(share->g, *orig,
visitor(make_bfs_visitor(
breadth_first_visit(share->g, *orig, Q,
make_bfs_visitor(
std::make_pair(
record_predecessors(
make_iterator_property_map(p.begin(),
share->indexmap),
boost::make_assoc_property_map(p),
on_tree_edge()
),
std::make_pair(
record_distances(
make_iterator_property_map(d.begin(),
share->indexmap),
boost::make_assoc_property_map(d),
on_tree_edge()
),
vis
))
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;
default:
abort();
}
}
break;
case BREADTH_FIRST | HAVE_DEST:
case DIJKSTRAS | HAVE_DEST:
if ((cursor= new (std::nothrow) stack_cursor(share)) && (orig || dest))
{
std::vector<Vertex> p(num_vertices(share->g));
std::vector<EdgeWeight> d(num_vertices(share->g));
oqgraph_visit_dist vis(p.begin(), d.begin(),
static_cast<stack_cursor*>(cursor));
boost::unordered_map<Vertex, Vertex> p;
boost::unordered_map<Vertex, EdgeWeight> d;
boost::queue<Vertex> Q;
reverse_graph<Graph> r(share->g);
p[share->indexmap[*dest]]= *dest;
p[ *dest ]= *dest;
d[ *dest ] = EdgeWeight();
switch (ALGORITHM & op)
{
case DIJKSTRAS:
dijkstra_shortest_paths(r.m_g, *dest,
weight_map(
share->weightmap
).
distance_map(
make_iterator_property_map(d.begin(), share->indexmap)
).
predecessor_map(
make_iterator_property_map(p.begin(), share->indexmap)
).
visitor(
make_dijkstra_visitor(vis)
dijkstra_shortest_paths_no_init(share->g, *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, 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_search(r, *dest,
visitor(make_bfs_visitor(
breadth_first_visit(share->g, *dest, Q,
make_bfs_visitor(
std::make_pair(
record_predecessors(
make_iterator_property_map(p.begin(),
share->indexmap),
boost::make_assoc_property_map(p),
on_tree_edge()
),
std::make_pair(
record_distances(
make_iterator_property_map(d.begin(),
share->indexmap),
boost::make_assoc_property_map(d),
on_tree_edge()
),
vis
))
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;
default:
abort();
}
}
break;
default:
break;
}
......@@ -949,7 +971,15 @@ namespace open_query
if (cursor)
cursor->current(ref);
else
ref= reference();
// 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()
......@@ -1006,7 +1036,7 @@ int stack_cursor::fetch_row(const row &row_info, row &result,
if ((result.seq_indicator= seq= last.sequence()))
result.seq= *seq;
if ((result.link_indicator= v= last.vertex()))
result.link= share->idmap[*v];
result.link= get(boost::vertex_index, share->g, *v);
if ((result.weight_indicator= w= last.weight()))
result.weight= *w;
return oqgraph::OK;
......@@ -1040,7 +1070,7 @@ int vertices_cursor::fetch_row(const row &row_info, row &result,
if (v)
{
result.link_indicator= 1;
result.link= share->idmap[*v];
result.link= get(boost::vertex_index, share->g, *v);
#ifdef DISPLAY_VERTEX_INFO
result.seq_indicator= 1;
if ((result.seq= degree(*v, share->g)))
......@@ -1048,10 +1078,10 @@ int vertices_cursor::fetch_row(const row &row_info, row &result,
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+= share->weightmap[*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+= share->weightmap[*oei];
weight+= get(boost::edge_weight, share->g, *oei);
result.weight_indicator= 1;
result.weight= weight / result.seq;
}
......@@ -1066,9 +1096,8 @@ int edges_cursor::fetch_row(const row &row_info, row &result)
{
edge_iterator it, end;
reference ref;
size_t count= position;
for (boost::tuples::tie(it, end)= edges(share->g); count && it != end; ++it, --count)
;
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))
......@@ -1085,9 +1114,19 @@ int edges_cursor::fetch_row(const row &row_info, row &result,
{
result= row_info;
result.orig_indicator= result.dest_indicator= result.weight_indicator= 1;
result.orig= share->idmap[ source( *edge, share->g ) ];
result.dest= share->idmap[ target( *edge, share->g ) ];
result.weight= share->weightmap[ *edge ];
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
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;
......
/* Copyright (C) 2007-2009 Arjen G Lentz & Antony T Curtis for Open Query
/* 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
......@@ -16,11 +16,9 @@
/* ======================================================================
Open Query Graph Computation Engine, based on a concept by Arjen Lentz
Mk.II implementation by Antony Curtis & Arjen Lentz
v3 implementation by Antony Curtis, Arjen Lentz, Andrew McDonnell
For more information, documentation, support, enhancement engineering,
and non-GPL licensing, see http://openquery.com/graph
or contact graph@openquery.com
For packaged binaries, see http://ourdelta.org
see http://openquery.com/graph or contact graph@openquery.com
======================================================================
*/
......@@ -47,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;
......@@ -64,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,
......@@ -96,20 +108,32 @@ 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();
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() throw();
static oqgraph_share *create(TABLE*,Field*,Field*,Field*) throw();
static void free(oqgraph*) throw();
static void free(oqgraph_share*) throw();
void release_cursor() throw();
static const size_t sizeof_ref;
private:
char *lastRetainedLatch;
};
}
......
/*
* Graph Engine - Copyright (C) 2007 by Arjen Lentz (arjen@openquery.com.au)
* graphstore.c internal storage system
*/
#include <stdlib.h>
#include <string.h>
#include <my_global.h>
#include <my_sys.h>
#include "graphstore.h"
/*
create a new vertex, and add it to the list (or start a list)
NOTE! gspp is ptr to base ptr
returns 1 for ok, 0 for error
*/
static int _add_vertex (GRAPHSTORE **gspp, GRAPH_VERTEXID id)
{
GRAPHSTORE *newgsp;
GRAPHSTORE *gscurp;
if (gspp == NULL)
return 0;
/* not allowing 0 */
if (!id)
return 0;
if (*gspp != NULL) {
for (gscurp = *gspp; gscurp != NULL; gscurp = gscurp->next) {
if (gscurp->vertex->id == id)
return 1; /* we can ignore, id already exists */
}
}
/* allocate and initialise */
if ((newgsp = my_malloc(sizeof (GRAPHSTORE),MYF(MY_ZEROFILL))) == NULL)
return 0;
if ((newgsp->vertex = my_malloc(sizeof (GRAPH_VERTEX),MYF(MY_ZEROFILL))) == NULL) {
my_free(newgsp,MYF(0));
return 0;
}
newgsp->vertex->id = id;
/* add new vertex to end of list */
if (*gspp != NULL) {
for (gscurp = *gspp; gscurp->next != NULL; gscurp = gscurp->next);
gscurp->next = newgsp;
}
else /* new list */
*gspp = newgsp;
/* ok */
return 1;
}
/*
find a vertex by id
returns ptr or NULL
*/
static GRAPH_VERTEX *_find_vertex (GRAPHSTORE *gsp, GRAPH_VERTEXID id)
{
/* just loop through the list to find id */
while (gsp != NULL && gsp->vertex->id != id)
gsp = gsp->next;
/* return ptr to vertex, or NULL */
return (gsp != NULL ? gsp->vertex : NULL);
}
/*
add edge
both vertices must already exist; graphstore_insert() does this
return 1 for ok, 0 for error (already exists, alloc error, etc)
*/
static int _add_edge (GRAPHSTORE *gsp, GRAPH_VERTEXID origid, GRAPH_VERTEXID destid, GRAPH_WEIGHT weight)
{
GRAPH_VERTEX *origvp, *destvp;
GRAPH_EDGE *ep, *newep;
/* find both vertices */
if ((origvp = _find_vertex(gsp,origid)) == NULL ||
(destvp = _find_vertex(gsp,destid)) == NULL)
return 0;
/* check if edge already exists */
for (ep = origvp->forward_edge; ep != NULL; ep = ep->next_edge) {
if (ep->vertex->id == destid)
return 0;
}
/* allocate and initialise new edge */
if ((newep = my_malloc(sizeof (GRAPH_EDGE),MYF(MY_ZEROFILL))) == NULL)
return 0;
newep->vertex = destvp;
newep->weight = weight;
/* insert new edge at start of chain, that's easiest */
ep = origvp->forward_edge;
origvp->forward_edge = newep;
newep->next_edge = ep;
/* ok */
return 1;
}
/*
create a new row, and add it to the graph set (or start set)
NOTE! gsetpp is ptr to base ptr
returns 1 for ok, 0 for error
*/
static int _add_graph_set (GRAPH_SET **gsetpp, GRAPH_TUPLE *gtp)
{
GRAPH_SET *newgsetp;
GRAPH_SET *gsetcurp;
if (gsetpp == NULL || gtp == NULL)
return 0;
/* allocate and initialise */
if ((newgsetp = my_malloc(sizeof (GRAPH_SET),MYF(MY_ZEROFILL))) == NULL)
return 0;
/* put in the data */
memcpy(&newgsetp->tuple,gtp,sizeof (GRAPH_TUPLE));
/* add new row to end of set */
if (*gsetpp != NULL) {
for (gsetcurp = *gsetpp; gsetcurp->next != NULL; gsetcurp = gsetcurp->next);
gsetcurp->next = newgsetp;
}
else { /* new set */
*gsetpp = newgsetp;
}
/* ok */
return 1;
}
/*
free a graph set (release memory)
returns 1 for ok, 0 for error
*/
int free_graph_set (GRAPH_SET *gsetp)
{
GRAPH_SET *nextgsetp;
if (gsetp == NULL)
return 0;
while (gsetp != NULL) {
nextgsetp = gsetp->next;
/* free() is a void function, nothing to check */
my_free(gsetp,MYF(0));
gsetp = nextgsetp;
}
/* ok */
return 1;
}
/*
insert new data into graphstore
this can be either a vertex or an edge, depending on the params
NOTE! gspp is ptr to base ptr
returns 1 for ok, 0 for error
*/
int graphstore_insert (GRAPHSTORE **gspp, GRAPH_TUPLE *gtp)
{
if (gspp == NULL)
return 0;
/* if nada or no orig vertex, we can't do anything */
if (gtp == NULL || !gtp->origid)
return 0;
#if 0
printf("inserting: origid=%lu destid=%lu weight=%lu\n",gtp->origid,gtp->destid,gtp->weight);
#endif
if (!gtp->destid) /* no edge param so just adding vertex */
return _add_vertex(gspp,gtp->origid);
/*
add an edge
first add both vertices just in case they didn't yet exist...
not checking result there: if there's a prob, _add_edge() will catch.
*/
_add_vertex(gspp,gtp->origid);
_add_vertex(gspp,gtp->destid);
return _add_edge(*gspp,gtp->origid,gtp->destid,gtp->weight);
}
/*
this is an internal function used by graphstore_query()
find any path from originating vertex to destid
if found, add to the result set on the way back
NOTE: recursive function!
returns 1 for hit, 0 for nothing, -1 for error
*/
int _find_any_path(GRAPH_SET **gsetpp, GRAPH_VERTEXID origid, GRAPH_VERTEXID destid, GRAPH_VERTEX *gvp, GRAPH_SEQ depth)
{
GRAPH_EDGE *gep;
GRAPH_TUPLE tup;
int res;
if (gvp->id == destid) {
/* found target! */
bzero(&tup,sizeof (GRAPH_TUPLE));
tup.origid = origid;
tup.destid = destid;
tup.seq = depth;
tup.linkid = gvp->id;
return (_add_graph_set(gsetpp,&tup) ? 1 : -1);
}
/* walk through all edges for this vertex */
for (gep = gvp->forward_edge; gep; gep = gep->next_edge) {
/* recurse */
res = _find_any_path(gsetpp,origid,destid,gep->vertex,depth+1);
if (res < 0)
return res;
if (res > 0) {
/* found somewhere below this one, insert ourselves and return */
bzero(&tup,sizeof (GRAPH_TUPLE));
tup.origid = origid;
tup.destid = destid;
tup.weight = gep->weight;
tup.seq = depth;
tup.linkid = gvp->id;
return (_add_graph_set(gsetpp,&tup) ? 1 : -1);
}
}
/* nothing found but no error */
return 0;
}
/*
query graphstore
latch specifies what operation to perform
we need to feed the conditions in... (through engine condition pushdown)
for now we just presume one condition per field so we just feed in a tuple
this also means we can just find constants, not ranges
return ptr to GRAPH_SET
caller must free with free_graph_set()
*/
GRAPH_SET *graphstore_query (GRAPHSTORE *gsp, GRAPH_TUPLE *gtp)
{
GRAPH_SET *gsetp = NULL;
GRAPH_SET *gsetcurp;
GRAPH_SET *newgsetp;
if (gsp == NULL || gtp == NULL)
return (NULL);
switch (gtp->latch) {
case 0: /* return all vertices/edges */
{
GRAPHSTORE *gscurp;
GRAPH_EDGE *gep;
GRAPH_TUPLE tup;
/* walk through all vertices */
for (gscurp = gsp; gscurp != NULL; gscurp = gscurp->next) {
/* check for condition */
if (gtp->origid && gscurp->vertex->id != gtp->origid)
continue;
bzero(&tup,sizeof (GRAPH_TUPLE));
tup.origid = gscurp->vertex->id;
/* no edges? */
if (gscurp->vertex->forward_edge == NULL) {
/* just add vertex to set */
if (!_add_graph_set(&gsetp,&tup)) {
if (gsetp != NULL) /* clean up */
my_free(gsetp,MYF(0));
return (NULL);
}
}
else {
/* walk through all edges */
for (gep = gscurp->vertex->forward_edge; gep; gep = gep->next_edge) {
tup.destid = gep->vertex->id;
tup.weight = gep->weight;
/* just add vertex to set */
if (!_add_graph_set(&gsetp,&tup)) {
if (gsetp != NULL) /* clean up */
my_free(gsetp,MYF(0));
return (NULL);
}
}
}
}
}
break;
case 1: /* find a path between origid and destid */
/* yes it'll just go with the first path it finds! */
{
GRAPHSTORE *gscurp;
GRAPH_VERTEX *origvp;
GRAPH_TUPLE tup;
if (!gtp->origid || !gtp->destid)
return NULL;
/* find both vertices */
if ((origvp = _find_vertex(gsp,gtp->origid)) == NULL ||
_find_vertex(gsp,gtp->destid) == NULL)
return NULL;
if (_find_any_path(&gsetp,gtp->origid,gtp->destid,origvp,0) < 0) { /* error? */
if (gsetp != NULL) /* clean up */
my_free(gsetp,MYF(0));
return NULL;
}
}
break;
default:
/* this ends up being an empty set */
break;
}
/* Fix up latch column with the proper value - to be relationally correct */
for (gsetcurp = gsetp; gsetcurp != NULL; gsetcurp = gsetcurp->next)
gsetcurp->tuple.latch = gtp->latch;
return gsetp;
}
/* end of graphstore.c */
\ No newline at end of file
/*
* Graph Engine - Copyright (C) 2007 by Arjen Lentz (arjen@openquery.com.au)
* graphstore.h internal storage system
*/
//typedef unsigned short uint16;
//typedef unsigned long long uint64;
/*
This is essentially what a GRAPH engine table looks like on the MySQL end:
CREATE TABLE foo (
latch SMALLINT UNSIGNED NULL,
origid BIGINT UNSIGNED NULL,
destid BIGINT UNSIGNED NULL,
weight BIGINT UNSIGNED NULL,
seq BIGINT UNSIGNED NULL,
linkid BIGINT UNSIGNED NULL
) ENGINE=OQGRAPH
*/
/*
We represent the above in C in the following way:
*/
typedef uint16 GRAPH_LATCH;
typedef uint64 GRAPH_VERTEXID;
typedef uint64 GRAPH_WEIGHT;
typedef uint64 GRAPH_SEQ;
typedef struct graph_tuple {
GRAPH_LATCH latch; /* function */
GRAPH_VERTEXID origid; /* vertex (should be != 0) */
GRAPH_VERTEXID destid; /* edge */
GRAPH_WEIGHT weight; /* weight */
GRAPH_SEQ seq; /* seq# within (origid) */
GRAPH_VERTEXID linkid; /* current step between origid/destid */
} GRAPH_TUPLE;
typedef struct graph_set {
GRAPH_TUPLE tuple;
struct graph_set *next;
} GRAPH_SET;
/*
Internally, sets look nothing like the above
- We have vertices, connected by edges.
- Each vertex' edges are maintained in a linked list.
- Edges can be weighted.
There are some issues with this structure, it'd be a pest to do a delete
So for now, let's just not support deletes!
*/
/* the below is half-gross and will likely change */
typedef struct graph_edge {
struct graph_vertex {
GRAPH_VERTEXID id;
struct graph_edge *forward_edge;
} *vertex;
GRAPH_WEIGHT weight;
struct graph_edge *next_edge;
} GRAPH_EDGE;
typedef struct graph_vertex GRAPH_VERTEX;
/*
A rough internal storage system for a set
*/
/* this below is fully gross and will definitely change */
typedef struct graphstore {
GRAPH_VERTEX *vertex; /* changed to ptr when integrating into MySQL */
struct graphstore *next;
} GRAPHSTORE;
#ifdef __cplusplus
extern "C" {
#endif
/* public function declarations */
int graphstore_insert (GRAPHSTORE **gspp, GRAPH_TUPLE *gtp);
GRAPH_SET *graphstore_query (GRAPHSTORE *gsp, GRAPH_TUPLE *gtp);
int free_graph_set (GRAPH_SET *gsetp);
#ifdef __cplusplus
}
#endif
/* end of graphstore.h */
\ No newline at end of file
/* Copyright (C) 2007-2009 Arjen G Lentz & Antony T Curtis for Open Query
/* 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
......@@ -16,156 +16,216 @@
/* ======================================================================
Open Query Graph Computation Engine, based on a concept by Arjen Lentz
Mk.II implementation by Antony Curtis & Arjen Lentz
v3 implementation by Antony Curtis, Arjen Lentz, Andrew McDonnell
For more information, documentation, support, enhancement engineering,
and non-GPL licensing, see http://openquery.com/graph
or contact graph@openquery.com
For packaged binaries, see http://ourdelta.org
see http://openquery.com/graph or contact graph@openquery.com
======================================================================
*/
#ifdef USE_PRAGMA_IMPLEMENTATION
#pragma implementation // gcc: Class implementation
#endif
#define MYSQL_SERVER // to have THD
#include <mysql/plugin.h>
#include "sql_class.h"
#include <stdarg.h>
#include <stdio.h>
#include <mysql_version.h>
#include "ha_oqgraph.h"
#include "graphcore.h"
#define MYSQL_SERVER // to have THD
#include <mysql/plugin.h>
#include <sql_error.h>
#if MYSQL_VERSION_ID >= 100004
// Interim workaround for rename in sql_error.h from this point
#define MYSQL_ERROR Sql_condition
#endif
#if MYSQL_VERSION_ID < 100000
// Allow compatibility with build for 5.5.32
#define user_defined_key_parts key_parts
#define open_table_error(a,b,c) open_table_error(a,b,c,0)
#define enum_open_frm_error int
#else
#define enum_open_frm_error enum open_frm_error
#endif
#include "table.h"
#include "field.h"
#include "key.h"
#include "unireg.h"
#include "sql_class.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 ...)
#endif
#define OQGRAPH_STATS_UPDATE_THRESHOLD 10
using namespace open_query;
/* 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
struct oqgraph_info_st
{
THR_LOCK lock;
oqgraph_share *graph;
uint use_count;
uint key_stat_version;
uint records;
bool dropped;
char name[FN_REFLEN+1];
};
#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 const char oqgraph_description[]=
"Open Query Graph Computation Engine, stored in memory "
"(http://openquery.com/graph)";
static my_bool g_allow_create_integer_latch = FALSE;
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", NULL, NULL, FALSE);
#endif
// 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 } ,
{ NULL, -1 }
};
static HASH oqgraph_open_tables;
static mysql_mutex_t LOCK_oqgraph;
static bool oqgraph_init_done= 0;
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;
}
static uchar* get_key(const uchar *ptr, size_t *length, my_bool)
{
const OQGRAPH_INFO *share= (const OQGRAPH_INFO*) ptr;
*length= strlen(share->name);
return (uchar*) share->name;
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";
}
#ifdef HAVE_PSI_INTERFACE
static PSI_mutex_key key_LOCK_oqgraph;
static PSI_mutex_info all_mutexes[]=
struct oqgraph_table_option_struct
{
{ &key_LOCK_oqgraph, "LOCK_oqgraph", PSI_FLAG_GLOBAL},
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 void init_psi_keys()
#define ha_table_option_struct oqgraph_table_option_struct
static const ha_create_table_option oqgraph_table_option_list[]=
{
mysql_mutex_register("oqgraph", all_mutexes, array_elements(all_mutexes));
}
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 const char oqgraph_description[]=
"Open Query Graph Computation Engine "
"(http://openquery.com/graph)";
#if MYSQL_VERSION_ID < 50100
static bool oqgraph_init();
handlerton oqgraph_hton= {
"OQGRAPH",
SHOW_OPTION_YES,
oqgraph_description,
DB_TYPE_OQGRAPH,
oqgraph_init,
0, /* slot */
0, /* savepoint size. */
NULL, /* close_connection */
NULL, /* savepoint */
NULL, /* rollback to savepoint */
NULL, /* release savepoint */
NULL, /* commit */
NULL, /* rollback */
NULL, /* prepare */
NULL, /* recover */
NULL, /* commit_by_xid */
NULL, /* rollback_by_xid */
NULL, /* create_cursor_read_view */
NULL, /* set_cursor_read_view */
NULL, /* close_cursor_read_view */
HTON_NO_FLAGS
};
#define STATISTIC_INCREMENT(X) \
statistic_increment(table->in_use->status_var.X, &LOCK_status)
#define MOVE(X) move_field(X)
#define RECORDS records
#else
#define init_psi_keys() /* no-op */
#endif /* HAVE_PSI_INTERFACE */
#define STATISTIC_INCREMENT(X) /* nothing */
#define MOVE(X) move_field_offset(X)
#define RECORDS stats.records
#endif
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);
}
#if MYSQL_VERSION_ID >= 50100
static int oqgraph_init(handlerton *hton)
{
init_psi_keys();
if (mysql_mutex_init(key_LOCK_oqgraph, &LOCK_oqgraph, MY_MUTEX_INIT_FAST))
goto error;
if (my_hash_init(&oqgraph_open_tables, &my_charset_bin, 32, 0, 0,
get_key, 0, 0))
{
mysql_mutex_destroy(&LOCK_oqgraph);
goto error;
}
#else
static bool oqgraph_init()
{
if (have_oqgraph == SHOW_OPTION_DISABLED)
return 1;
#endif
DBUG_PRINT( "oq-debug", ("oqgraph_init"));
#if MYSQL_VERSION_ID >= 50100
hton->state= SHOW_OPTION_YES;
hton->db_type= DB_TYPE_AUTOASSIGN;
hton->create= oqgraph_create_handler;
hton->flags= HTON_NO_FLAGS;
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;
oqgraph_init_done= TRUE;
return 0;
error:
return 1;
}
static int oqgraph_fini(void *)
{
my_hash_free(&oqgraph_open_tables);
mysql_mutex_destroy(&LOCK_oqgraph);
DBUG_PRINT( "oq-debug", ("oqgraph_fini"));
oqgraph_init_done= FALSE;
return 0;
}
static OQGRAPH_INFO *get_share(const char *name, TABLE *table=0)
{
OQGRAPH_INFO *share;
uint length= strlen(name);
mysql_mutex_assert_owner(&LOCK_oqgraph);
if (!(share= (OQGRAPH_INFO*) my_hash_search(&oqgraph_open_tables,
(byte*) name, length)))
{
if (!table ||
!(share= new OQGRAPH_INFO))
return 0;
share->use_count= share->key_stat_version= share->records= 0;
share->dropped= 0;
strmov(share->name, name);
if (!(share->graph= oqgraph::create()))
{
delete share;
return 0;
}
if (my_hash_insert(&oqgraph_open_tables, (byte*) share))
{
oqgraph::free(share->graph);
delete share;
return 0;
}
thr_lock_init(&share->lock);
}
share->use_count++;
return share;
}
static int free_share(OQGRAPH_INFO *share, bool drop=0)
{
mysql_mutex_assert_owner(&LOCK_oqgraph);
if (!share)
return 0;
if (drop)
{
share->dropped= true;
my_hash_delete(&oqgraph_open_tables, (byte*) share);
}
if (!--share->use_count)
{
if (share->dropped)
{
thr_lock_delete(&share->lock);
oqgraph::free(share->graph);
delete share;
}
}
#endif
return 0;
}
......@@ -197,7 +257,7 @@ static int error_code(int res)
*
* ColName Type Attributes
* ======= ======== =============
* latch SMALLINT UNSIGNED NULL
* latch VARCHAR NULL
* origid BIGINT UNSIGNED NULL
* destid BIGINT UNSIGNED NULL
* weight DOUBLE NULL
......@@ -205,8 +265,12 @@ static int error_code(int res)
* 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 SMALLINT UNSIGNED NULL,
latch VARCHAR(32) NULL,
origid BIGINT UNSIGNED NULL,
destid BIGINT UNSIGNED NULL,
weight DOUBLE NULL,
......@@ -215,13 +279,35 @@ static int error_code(int res)
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.
*/
static int oqgraph_check_table_structure (TABLE *table_arg)
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_SHORT },
{ "latch" , MYSQL_TYPE_VARCHAR },
{ "origid", MYSQL_TYPE_LONGLONG },
{ "destid", MYSQL_TYPE_LONGLONG },
{ "weight", MYSQL_TYPE_DOUBLE },
......@@ -230,28 +316,85 @@ static int oqgraph_check_table_structure (TABLE *table_arg)
{ NULL , 0}
};
DBUG_ENTER("ha_oqgraph::table_structure_ok");
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, 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, MYSQL_ERROR::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, MYSQL_ERROR::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)
DBUG_RETURN(-1);
if (skel[i].coltype != MYSQL_TYPE_DOUBLE) {
if ((*field)->type() != skel[i].coltype) {
badColumn = true;
push_warning_printf( current_thd, MYSQL_ERROR::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, MYSQL_ERROR::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 ))
DBUG_RETURN(-1);
if ( (!((*field)->flags & UNSIGNED_FLAG ))) {
badColumn = true;
push_warning_printf( current_thd, MYSQL_ERROR::WARN_LEVEL_WARN, HA_WRONG_CREATE_OPTION, "Column %d must be UNSIGNED.", i);
}
}
/* Check THAT NOT NULL isn't set */
if ((*field)->flags & NOT_NULL_FLAG)
DBUG_RETURN(-1);
if (!badColumn) if ((*field)->flags & NOT_NULL_FLAG) {
badColumn = true;
push_warning_printf( current_thd, MYSQL_ERROR::WARN_LEVEL_WARN, HA_WRONG_CREATE_OPTION, "Column %d must be NULL.", i);
}
/* Check the column name */
if (strcmp(skel[i].colname,(*field)->field_name))
if (!badColumn) if (strcmp(skel[i].colname,(*field)->field_name)) {
badColumn = true;
push_warning_printf( current_thd, MYSQL_ERROR::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, MYSQL_ERROR::WARN_LEVEL_WARN, HA_WRONG_CREATE_OPTION, "Not enough columns.");
DBUG_RETURN(-1);
}
if (*field) {
push_warning_printf( current_thd, MYSQL_ERROR::WARN_LEVEL_WARN, HA_WRONG_CREATE_OPTION, "Too many columns.");
DBUG_RETURN(-1);
}
if (skel[i].colname || *field || !table_arg->key_info || !table_arg->s->keys)
if (!table_arg->key_info || !table_arg->s->keys) {
push_warning_printf( current_thd, MYSQL_ERROR::WARN_LEVEL_WARN, HA_WRONG_CREATE_OPTION, "No vaild 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)
......@@ -259,8 +402,10 @@ static int oqgraph_check_table_structure (TABLE *table_arg)
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))
HA_KEY_ALG_HASH == key->algorithm)) {
push_warning_printf( current_thd, MYSQL_ERROR::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 */
......@@ -269,11 +414,16 @@ static int oqgraph_check_table_structure (TABLE *table_arg)
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, MYSQL_ERROR::WARN_LEVEL_WARN, HA_WRONG_CREATE_OPTION, "Keys parts mismatch on key %d.", i);
DBUG_RETURN(-1);
}
else
}
else {
push_warning_printf( current_thd, MYSQL_ERROR::WARN_LEVEL_WARN, HA_WRONG_CREATE_OPTION, "Too many key parts on key %d.", i);
DBUG_RETURN(-1);
}
}
DBUG_RETURN(0);
}
......@@ -283,10 +433,28 @@ static int oqgraph_check_table_structure (TABLE *table_arg)
*****************************************************************************/
ha_oqgraph::ha_oqgraph(handlerton *hton, TABLE_SHARE *table_arg)
: handler(hton, table_arg),
share(0), graph(0), records_changed(0), key_stat_version(0)
: 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
{
......@@ -300,269 +468,345 @@ ulong ha_oqgraph::index_flags(uint inx, uint part, bool all_parts) const
return HA_ONLY_WHOLE_INDEX | HA_KEY_SCAN_NOT_ROR;
}
int ha_oqgraph::open(const char *name, int mode, uint test_if_locked)
bool ha_oqgraph::get_error_message(int error, String* buf)
{
mysql_mutex_lock(&LOCK_oqgraph);
if ((share = get_share(name, table)))
if (error < 0)
{
ref_length= oqgraph::sizeof_ref;
}
if (share)
{
/* Initialize variables for the opened table */
thr_lock_data_init(&share->lock, &lock, NULL);
graph= oqgraph::create(share->graph);
/*
We cannot run update_key_stats() here because we do not have a
lock on the table. The 'records' count might just be changed
temporarily at this moment and we might get wrong statistics (Bug
#10178). Instead we request for update. This will be done in
ha_oqgraph::info(), which is always called before key statistics are
used.
*/
key_stat_version= share->key_stat_version-1;
buf->append(error_message);
buf->c_ptr_safe();
error_message.length(0);
}
mysql_mutex_unlock(&LOCK_oqgraph);
return (share ? 0 : 1);
return false;
}
int ha_oqgraph::close(void)
void ha_oqgraph::fprint_error(const char* fmt, ...)
{
mysql_mutex_lock(&LOCK_oqgraph);
oqgraph::free(graph); graph= 0;
int res= free_share(share);
mysql_mutex_unlock(&LOCK_oqgraph);
return error_code(res);
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);
}
void ha_oqgraph::update_key_stats()
/**
* 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'
*
*/
int ha_oqgraph::open(const char *name, int mode, uint test_if_locked)
{
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)
no_records= 2;
key->rec_per_key[key->user_defined_key_parts-1]= no_records;
}
}
}
records_changed= 0;
/* At the end of update_key_stats() we can proudly claim they are OK. */
key_stat_version= share->key_stat_version;
}
DBUG_ENTER("ha_oqgraph::open");
DBUG_PRINT( "oq-debug", ("open(name=%s,mode=%d,test_if_locked=%u)", name, mode, test_if_locked));
int ha_oqgraph::write_row(byte * buf)
{
int res= oqgraph::MISC_FAIL;
Field ** const field= table->field;
DBUG_ASSERT(!have_table_share);
DBUG_ASSERT(graph == NULL);
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
my_ptrdiff_t ptrdiff= buf - table->record[0];
THD* thd = current_thd;
oqgraph_table_option_struct *options=
reinterpret_cast<oqgraph_table_option_struct*>(table->s->option_struct);
if (ptrdiff)
// Catch cases where table was not constructed properly
// Note - need to return -1 so our error text gets reported
if (!options) {
fprint_error("Invalid OQGRAPH backing store (null attributes)");
DBUG_RETURN(-1);
}
if (!options->table_name || !*options->table_name) {
fprint_error("Invalid OQGRAPH backing store (unspecified or empty data_table attribute)");
// if table_name if present but doesnt actually exist, we will fail out below
// when we call open_table_def(). same probably applies for the id fields
DBUG_RETURN(-1);
}
if (!options->origid || !*options->origid) {
fprint_error("Invalid OQGRAPH backing store (unspecified or empty origid attribute)");
DBUG_RETURN(-1);
}
if (!options->destid || !*options->destid) {
fprint_error("Invalid OQGRAPH backing store (unspecified or empty destid attribute)");
DBUG_RETURN(-1);
}
// weight is optional
error_message.length(0);
origid= destid= weight= 0;
init_tmp_table_share( thd, share, table->s->db.str, table->s->db.length, options->table_name, "");
// 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`, dont 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);
strmov(strnmov(share->path.str, name, (int)(p - name) + 1), options->table_name);
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;
#if MYSQL_VERSION_ID >= 100002
open_def_flags = GTS_TABLE;
#endif
// 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))
{
field[1]->move_field_offset(ptrdiff);
field[2]->move_field_offset(ptrdiff);
field[3]->move_field_offset(ptrdiff);
#if MYSQL_VERSION_ID < 100002
if (thd->is_error() && thd->stmt_da->sql_errno() != ER_NO_SUCH_TABLE)
{
free_table_share(share);
DBUG_RETURN(thd->stmt_da->sql_errno());
}
if (!field[1]->is_null() && !field[2]->is_null())
if (ha_create_table_from_engine(thd, table->s->db.str, options->table_name))
{
VertexID orig_id= (VertexID) field[1]->val_int();
VertexID dest_id= (VertexID) field[2]->val_int();
EdgeWeight weight= 1;
free_table_share(share);
DBUG_RETURN(thd->stmt_da->sql_errno());
}
/*mysql_reset_errors(thd, 1);*/
thd->clear_error();
continue;
#else
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);
#endif
}
if (!field[3]->is_null())
weight= (EdgeWeight) field[3]->val_real();
if (!(res= graph->insert_edge(orig_id, dest_id, weight, replace_dups)))
if (int err= share->error)
{
++records_changed;
share->records++;
}
if (res == oqgraph::DUPLICATE_EDGE && ignore_dups && !insert_dups)
res= oqgraph::OK;
open_table_error(share, share->error, share->open_errno);
free_table_share(share);
DBUG_RETURN(err);
}
if (ptrdiff)
if (share->is_view)
{
field[1]->move_field_offset(-ptrdiff);
field[2]->move_field_offset(-ptrdiff);
field[3]->move_field_offset(-ptrdiff);
free_table_share(share);
fprint_error("VIEWs are not supported for an OQGRAPH backing store.");
DBUG_RETURN(-1);
}
dbug_tmp_restore_column_map(table->read_set, old_map);
if (!res && records_changed*OQGRAPH_STATS_UPDATE_THRESHOLD > share->records)
if (enum_open_frm_error err= open_table_from_share(thd, share, "",
(uint) (HA_OPEN_KEYFILE | HA_OPEN_RNDFILE |
HA_GET_INDEX | HA_TRY_READ_ONLY),
READ_KEYINFO | COMPUTE_TYPES | EXTRA_RECORD,
thd->open_options, edges, FALSE))
{
/*
We can perform this safely since only one writer at the time is
allowed on the table.
*/
share->key_stat_version++;
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);
}
return error_code(res);
}
int ha_oqgraph::update_row(const byte * old, byte * buf)
{
int res= oqgraph::MISC_FAIL;
VertexID orig_id, dest_id;
EdgeWeight weight= 1;
Field **field= table->field;
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
my_ptrdiff_t ptrdiff= buf - table->record[0];
if (ptrdiff)
if (!edges->file)
{
field[0]->move_field_offset(ptrdiff);
field[1]->move_field_offset(ptrdiff);
field[2]->move_field_offset(ptrdiff);
field[3]->move_field_offset(ptrdiff);
fprint_error("Some error occurred opening table '%s'", options->table_name);
free_table_share(share);
DBUG_RETURN(-1);
}
if (inited == INDEX || inited == RND)
{
VertexID *origp= 0, *destp= 0;
EdgeWeight *weightp= 0;
if (!field[1]->is_null())
*(origp= &orig_id)= (VertexID) field[1]->val_int();
if (!field[2]->is_null())
*(destp= &dest_id)= (VertexID) field[2]->val_int();
if (!field[3]->is_null())
*(weightp= &weight)= (EdgeWeight) field[3]->val_real();
edges->reginfo.lock_type= TL_READ;
my_ptrdiff_t ptrdiff2= old - buf;
edges->tablenr= thd->current_tablenr++;
edges->status= STATUS_NO_RECORD;
edges->file->ha_start_of_new_statement();
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);
field[0]->move_field_offset(ptrdiff2);
field[1]->move_field_offset(ptrdiff2);
field[2]->move_field_offset(ptrdiff2);
field[3]->move_field_offset(ptrdiff2);
// We expect fields origid, destid and optionally weight
origid= destid= weight= 0;
if (field[0]->is_null())
for (Field **field= edges->field; *field; ++field)
{
if (!origp == field[1]->is_null() &&
*origp == (VertexID) field[1]->val_int())
origp= 0;
if (!destp == field[2]->is_null() &&
*destp == (VertexID) field[2]->val_int())
origp= 0;
if (!weightp == field[3]->is_null() &&
*weightp == (VertexID) field[3]->val_real())
weightp= 0;
if (!(res= graph->modify_edge(oqgraph::current_row(),
origp, destp, weightp, replace_dups)))
++records_changed;
else if (ignore_dups && res == oqgraph::DUPLICATE_EDGE)
res= oqgraph::OK;
if (strcmp(options->origid, (*field)->field_name))
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, 0);
free_table_share(share);
DBUG_RETURN(-1);
}
origid = *field;
break;
}
field[0]->move_field_offset(-ptrdiff2);
field[1]->move_field_offset(-ptrdiff2);
field[2]->move_field_offset(-ptrdiff2);
field[3]->move_field_offset(-ptrdiff2);
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, 0);
free_table_share(share);
DBUG_RETURN(-1);
}
if (ptrdiff)
for (Field **field= edges->field; *field; ++field)
{
field[0]->move_field_offset(-ptrdiff);
field[1]->move_field_offset(-ptrdiff);
field[2]->move_field_offset(-ptrdiff);
field[3]->move_field_offset(-ptrdiff);
if (strcmp(options->destid, (*field)->field_name))
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, 0);
free_table_share(share);
DBUG_RETURN(-1);
}
destid = *field;
break;
}
dbug_tmp_restore_column_map(table->read_set, old_map);
if (!res && records_changed*OQGRAPH_STATS_UPDATE_THRESHOLD > share->records)
{
/*
We can perform this safely since only one writer at the time is
allowed on the table.
*/
share->key_stat_version++;
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, 0);
free_table_share(share);
DBUG_RETURN(-1);
}
return error_code(res);
}
int ha_oqgraph::delete_row(const byte * buf)
{
int res= oqgraph::EDGE_NOT_FOUND;
Field **field= table->field;
// Make sure origid column != destid column
if (strcmp( origid->field_name, destid->field_name)==0) {
fprint_error("Invalid OQGRAPH backing store ('%s.destid' attribute set to same column as origid attribute)", p+1, options->table_name);
closefrm(edges, 0);
free_table_share(share);
DBUG_RETURN(-1);
}
if (inited == INDEX || inited == RND)
for (Field **field= edges->field; options->weight && *field; ++field)
{
if ((res= graph->delete_edge(oqgraph::current_row())) == oqgraph::OK)
if (strcmp(options->weight, (*field)->field_name))
continue;
if ((*field)->result_type() != REAL_RESULT ||
!((*field)->flags & NOT_NULL_FLAG))
{
++records_changed;
share->records--;
fprint_error("Column '%s.%s' (weight) is not a not-null real type",
options->table_name, options->weight);
closefrm(edges, 0);
free_table_share(share);
DBUG_RETURN(-1);
}
weight = *field;
break;
}
if (res != oqgraph::OK)
{
my_bitmap_map *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);
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, 0);
free_table_share(share);
DBUG_RETURN(-1);
}
if (field[0]->is_null() && !field[1]->is_null() && !field[2]->is_null())
if (!(graph_share = oqgraph::create(edges, origid, destid, weight)))
{
VertexID orig_id= (VertexID) field[1]->val_int();
VertexID dest_id= (VertexID) field[2]->val_int();
fprint_error("Unable to create graph instance.");
closefrm(edges, 0);
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)
{
oqgraph::free(graph); graph= 0;
oqgraph::free(graph_share); graph_share= 0;
if ((res= graph->delete_edge(orig_id, dest_id)) == oqgraph::OK)
if (have_table_share)
{
++records_changed;
share->records--;
}
if (edges->file)
closefrm(edges, 0);
free_table_share(share);
have_table_share = false;
}
return 0;
}
if (ptrdiff)
void ha_oqgraph::update_key_stats()
{
for (uint i= 0; i < table->s->keys; i++)
{
field[0]->move_field_offset(-ptrdiff);
field[1]->move_field_offset(-ptrdiff);
field[2]->move_field_offset(-ptrdiff);
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;
}
dbug_tmp_restore_column_map(table->read_set, old_map);
}
if (!res && table->s->tmp_table == NO_TMP_TABLE &&
records_changed*OQGRAPH_STATS_UPDATE_THRESHOLD > share->records)
{
/*
We can perform this safely since only one writer at the time is
allowed on the table.
*/
share->key_stat_version++;
}
return error_code(res);
/* 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(byte * buf)
{
return HA_ERR_TABLE_READONLY;
}
int ha_oqgraph::update_row(const byte * old, byte * 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);
}
......@@ -577,6 +821,56 @@ int ha_oqgraph::index_next_same(byte *buf, const byte *key, uint key_len)
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 >= 0 && 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)
{
......@@ -586,7 +880,7 @@ int ha_oqgraph::index_read_idx(byte * buf, uint index, const byte * key,
VertexID orig_id, dest_id;
int latch;
VertexID *orig_idp=0, *dest_idp=0;
int *latchp=0;
int* latchp=0;
open_query::row row;
bmove_align(buf, table->s->default_values, table->s->reclength);
......@@ -602,9 +896,30 @@ int ha_oqgraph::index_read_idx(byte * buf, uint index, const byte * key,
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, MYSQL_ERROR::WARN_LEVEL_WARN, ER_WRONG_ARGUMENTS, ER(ER_WRONG_ARGUMENTS), "OQGRAPH latch");
table->status = STATUS_NOT_FOUND;
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;
}
......@@ -628,10 +943,28 @@ int ha_oqgraph::index_read_idx(byte * buf, uint index, const byte * key,
}
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);
if (!res && !(res= graph->fetch_row(row)))
DBUG_PRINT( "oq-debug", ("search() = %d", res));
if (!res && !(res= graph->fetch_row(row))) {
res= fill_record(buf, row);
}
table->status = res ? STATUS_NOT_FOUND : 0;
return error_code(res);
}
......@@ -655,12 +988,29 @@ int ha_oqgraph::fill_record(byte *record, const open_query::row &row)
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)
{
......@@ -708,13 +1058,16 @@ int ha_oqgraph::fill_record(byte *record, const open_query::row &row)
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)
{
int res;
open_query::row row;
open_query::row row = {};
if (!(res= graph->fetch_row(row)))
res= fill_record(buf, row);
table->status= res ? STATUS_NOT_FOUND: 0;
......@@ -743,65 +1096,40 @@ int ha_oqgraph::cmp_ref(const byte *ref1, const byte *ref2)
int ha_oqgraph::info(uint flag)
{
stats.records= graph->vertices_count() + graph->edges_count();
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();
// if (key_stat_version != share->key_stat_version)
// update_key_stats();
return 0;
}
int ha_oqgraph::extra(enum ha_extra_function operation)
{
switch (operation)
{
case HA_EXTRA_IGNORE_DUP_KEY:
ignore_dups= true;
break;
case HA_EXTRA_NO_IGNORE_DUP_KEY:
ignore_dups= false;
insert_dups= false;
break;
case HA_EXTRA_WRITE_CAN_REPLACE:
replace_dups= true;
break;
case HA_EXTRA_WRITE_CANNOT_REPLACE:
replace_dups= false;
break;
case HA_EXTRA_INSERT_WITH_UPDATE:
insert_dups= true;
break;
default:
break;
}
return 0;
return edges->file->extra(operation);
}
int ha_oqgraph::delete_all_rows()
{
int res;
if (!(res= graph->delete_all()))
{
share->records= 0;
}
if (!res && table->s->tmp_table == NO_TMP_TABLE)
{
/*
We can perform this safely since only one writer at the time is
allowed on the table.
*/
share->key_stat_version++;
}
return error_code(res);
return HA_ERR_TABLE_READONLY;
}
int ha_oqgraph::external_lock(THD *thd, int lock_type)
{
return 0; // No external locking
// 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);
}
......@@ -809,10 +1137,7 @@ THR_LOCK_DATA **ha_oqgraph::store_lock(THD *thd,
THR_LOCK_DATA **to,
enum thr_lock_type lock_type)
{
if (lock_type != TL_IGNORE && lock.type == TL_UNLOCK)
lock.type=lock_type;
*to++= &lock;
return to;
return edges->file->store_lock(thd, to, lock_type);
}
/*
......@@ -820,29 +1145,13 @@ THR_LOCK_DATA **ha_oqgraph::store_lock(THD *thd,
not when doing a CREATE on the table.
*/
int ha_oqgraph::delete_table(const char *name)
int ha_oqgraph::delete_table(const char *)
{
int res= 0;
OQGRAPH_INFO *share;
mysql_mutex_lock(&LOCK_oqgraph);
if ((share= get_share(name)))
{
res= free_share(share, true);
}
mysql_mutex_unlock(&LOCK_oqgraph);
return error_code(res);
return 0;
}
int ha_oqgraph::rename_table(const char * from, const char * to)
int ha_oqgraph::rename_table(const char *, const char *)
{
mysql_mutex_lock(&LOCK_oqgraph);
if (OQGRAPH_INFO *share= get_share(from))
{
strmov(share->name, to);
my_hash_update(&oqgraph_open_tables, (byte*) share,
(byte*) from, strlen(from));
}
mysql_mutex_unlock(&LOCK_oqgraph);
return 0;
}
......@@ -851,6 +1160,15 @@ ha_rows ha_oqgraph::records_in_range(uint inx, key_range *min_key,
key_range *max_key)
{
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", ("records_in_range ::>> inx=%u", 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 ||
......@@ -858,23 +1176,88 @@ ha_rows ha_oqgraph::records_in_range(uint inx, key_range *min_key,
min_key->flag != HA_READ_KEY_EXACT ||
max_key->flag != HA_READ_AFTER_KEY)
{
if (min_key->length == key->key_part[0].store_length)
if (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
DBUG_ASSERT(key->key_part[0].store_length == 3);
// 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])
return graph->vertices_count();
!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)
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];
//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;
}
......@@ -883,24 +1266,18 @@ ha_rows ha_oqgraph::records_in_range(uint inx, key_range *min_key,
int ha_oqgraph::create(const char *name, TABLE *table_arg,
HA_CREATE_INFO *create_info)
{
int res = -1;
OQGRAPH_INFO *share;
oqgraph_table_option_struct *options=
reinterpret_cast<oqgraph_table_option_struct*>(table_arg->s->option_struct);
mysql_mutex_lock(&LOCK_oqgraph);
if ((share= get_share(name)))
{
free_share(share);
}
else
{
if (!oqgraph_check_table_structure(table_arg))
res= 0;;
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);
}
mysql_mutex_unlock(&LOCK_oqgraph);
if (this->share)
info(HA_STATUS_NO_LOCK | HA_STATUS_CONST | HA_STATUS_VARIABLE);
return error_code(res);
(void)(options);
DBUG_RETURN(0);
}
......@@ -912,20 +1289,41 @@ void ha_oqgraph::update_create_info(HA_CREATE_INFO *create_info)
struct st_mysql_storage_engine oqgraph_storage_engine=
{ MYSQL_HANDLERTON_INTERFACE_VERSION };
extern "C" const char* const oqgraph_boost_version;
extern "C" const char* const oqgraph_judy_version;
static struct st_mysql_show_var oqgraph_status[]=
{
{ "OQGraph_Boost_Version", (char*) &oqgraph_boost_version, SHOW_CHAR_PTR },
/*{ "OQGraph_Judy_Version", (char*) &oqgraph_judy_version, SHOW_CHAR_PTR },*/
{ 0, 0, SHOW_UNDEF }
};
#ifdef RETAIN_INT_LATCH_COMPATIBILITY
static struct st_mysql_sys_var* oqgraph_sysvars[]= {
MYSQL_SYSVAR(allow_create_integer_latch),
0
};
#endif
maria_declare_plugin(oqgraph)
{
MYSQL_STORAGE_ENGINE_PLUGIN,
&oqgraph_storage_engine,
"OQGRAPH",
"Arjen Lentz & Antony T Curtis, Open Query",
"Arjen Lentz & Antony T Curtis, Open Query, and Andrew McDonnell",
oqgraph_description,
PLUGIN_LICENSE_GPL,
(int (*)(void*)) oqgraph_init, /* Plugin Init */
oqgraph_fini, /* Plugin Deinit */
0x0200, /* Version: 2.0 */
NULL, /* status variables */
NULL, /* system variables */
"2.0",
0x0300, /* Version: 3s.0 */
oqgraph_status, /* status variables */
#ifdef RETAIN_INT_LATCH_COMPATIBILITY
oqgraph_sysvars, /* system variables */
#else
NULL,
#endif
"3.0",
MariaDB_PLUGIN_MATURITY_BETA
}
maria_declare_plugin_end;
/* Copyright (C) 2007-2009 Arjen G Lentz & Antony T Curtis for Open Query
/* 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
......@@ -16,11 +16,9 @@
/* ======================================================================
Open Query Graph Computation Engine, based on a concept by Arjen Lentz
Mk.II implementation by Antony Curtis & Arjen Lentz
v3 implementation by Antony Curtis, Arjen Lentz, Andrew McDonnell
For more information, documentation, support, enhancement engineering,
and non-GPL licensing, see http://openquery.com/graph
or contact graph@openquery.com
For packaged binaries, see http://ourdelta.org
see http://openquery.com/graph or contact graph@openquery.com
======================================================================
*/
......@@ -29,6 +27,7 @@
#endif
#include "handler.h"
#include "table.h"
typedef struct oqgraph_info_st OQGRAPH_INFO;
typedef uchar byte;
......@@ -37,19 +36,22 @@ namespace open_query
{
struct row;
class oqgraph;
class oqgraph_share;
}
/* class for the the Open Query Graph handler */
class ha_oqgraph: public handler
{
OQGRAPH_INFO *share;
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;
THR_LOCK_DATA lock;
/* number of records changed since last statistics update */
uint records_changed;
uint key_stat_version;
bool replace_dups, ignore_dups, insert_dups;
int fill_record(byte*, const open_query::row&);
......@@ -61,7 +63,7 @@ public:
ha_oqgraph(TABLE *table);
Table_flags table_flags() const;
#endif
~ha_oqgraph() {}
virtual ~ha_oqgraph();
const char *index_type(uint inx)
{
return "HASH";
......@@ -69,6 +71,7 @@ public:
/* 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; }
......@@ -102,6 +105,19 @@ public:
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
private:
int oqgraph_check_table_structure (TABLE *table_arg);
void update_key_stats();
String error_message;
};
/* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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"
#include <Judy.h>
#ifndef JUDY_LIB_VERSION
#define JUDY_LIB_VERSION "(unknown)"
#endif
extern "C" const char* const oqgraph_judy_version= JUDY_LIB_VERSION;
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;
}
/* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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);
};
}
/* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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;
}
/* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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_thunk.h"
#include "oqgraph_judy.h"
#define BOOST_NO_HASH 1
#define BOOST_NO_SLIST 1
#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*() { 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) { return _cursor == x._cursor; }
bool operator!=(const self& x) { 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) { }
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 >= 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
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;
}
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;
};
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_weight_t>::const_type::reference
get(const property_map<oqgraph3::graph,
edge_weight_t>::const_type& p,
const property_map<
oqgraph3::graph,
edge_weight_t>::const_type::key_type& key)
{ return key.weight(); }
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;
}
}
/* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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_thunk.h"
#include <boost/tuple/tuple.hpp>
#define MYSQL_SERVER
#include "mysql_version.h"
#include "sql_base.h"
#include "table.h"
#include "field.h"
#include "key.h"
#include "unireg.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.s->key_info + _index, table.s->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.s->key_info[_index].user_defined_key_parts == _parts ?
HA_READ_KEY_EXACT : HA_READ_KEY_OR_NEXT))
{
table.file->ha_index_end();
return rc;
}
if (table.vfield)
update_virtual_fields(table.in_use, &table);
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 (table.vfield)
update_virtual_fields(table.in_use, &table);
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;
}
if (table.vfield)
update_virtual_fields(table.in_use, &table);
}
_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);
}
if (table.vfield)
update_virtual_fields(table.in_use, &table);
_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);
}
if (table.vfield)
update_virtual_fields(table.in_use, &table);
_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.s->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.s->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.s->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.s->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 (table.vfield)
update_virtual_fields(table.in_use, &table);
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;
}
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;
}
/* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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;
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--; }
};
}
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