Commit 8074860a authored by Andrew McDonnell's avatar Andrew McDonnell

Properly handle `is null`

parents 92d4ccbc 56d3c792
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;
...@@ -31,6 +31,8 @@ INSERT INTO graph_base(from_id, to_id) VALUES (3,4), (4,3); ...@@ -31,6 +31,8 @@ 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,6), (6,5);
select * from graph where latch is null; 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_base;
DROP TABLE graph; DROP TABLE graph;
......
...@@ -44,7 +44,7 @@ ...@@ -44,7 +44,7 @@
#include "my_dbug.h" #include "my_dbug.h"
// Uncomment this for extra debug, but expect a performance hit in large queries // Uncomment this for extra debug, but expect a performance hit in large queries
#define VERBOSE_DEBUG //#define VERBOSE_DEBUG
#ifdef VERBOSE_DEBUG #ifdef VERBOSE_DEBUG
#else #else
#undef DBUG_PRINT #undef DBUG_PRINT
...@@ -882,7 +882,10 @@ int ha_oqgraph::index_read_idx(byte * buf, uint index, const byte * key, ...@@ -882,7 +882,10 @@ int ha_oqgraph::index_read_idx(byte * buf, uint index, const byte * key,
// so we pass the string now. // so we pass the string now.
// In the future we should refactor parse_latch_string_to_legacy_int() // In the future we should refactor parse_latch_string_to_legacy_int()
// into oqgraph instead. // into oqgraph instead.
if (latchp)
graph->retainLatchFieldValue(latchFieldValue.c_ptr_safe()); graph->retainLatchFieldValue(latchFieldValue.c_ptr_safe());
else
graph->retainLatchFieldValue(NULL);
DBUG_PRINT( "oq-debug", ("index_read_idx ::>> search(latch:%s,%ld,%ld)", DBUG_PRINT( "oq-debug", ("index_read_idx ::>> search(latch:%s,%ld,%ld)",
...@@ -1095,7 +1098,7 @@ ha_rows ha_oqgraph::records_in_range(uint inx, key_range *min_key, ...@@ -1095,7 +1098,7 @@ ha_rows ha_oqgraph::records_in_range(uint inx, key_range *min_key,
min_key->flag != HA_READ_KEY_EXACT || min_key->flag != HA_READ_KEY_EXACT ||
max_key->flag != HA_READ_AFTER_KEY) 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 // If latch is not null and equals 0, return # nodes
......
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