morris/microdb

Deleting a record corrupts the index

Opened this issue · 5 comments

<?php

include "MicroDB/Database.php";
include "MicroDB/Event.php";
include "MicroDB/Cache.php";
include "MicroDB/Index.php";

$db = new \MicroDB\Database('data/bug_index');
$id_idx = new \MicroDB\Index($db, 'id_idx', 'id');

$id1 = $db->create(array('id' => 42, 'data' => 'Item #1'));
$id2 = $db->create(array('id' => 42, 'data' => 'Item #2'));

$db->delete($id1);
$db->delete($id2);

$id = $id_idx->first(42);

var_dump($id);
?>

Expected output: NULL
Actual output: int(2)

@rickerd would you mind looking into this?

Im currently working on a AngularJS application with jcrop that i need to fix.
If i have time ill do it, maybe you'll have it solved faster than me.

UPDATE:
I looked into it but don't have an answer for the bug.

Well, I'd say the immediate problem is with
https://github.com/morris/microdb/blob/master/src/MicroDB/Index.php#L227
https://github.com/morris/microdb/blob/master/src/MicroDB/Index.php#L254
because the docs for array_splice() explicitly state

Note that numeric keys in input are not preserved.

However, given that in 2 years nobody has ever bothered to use the index-related functionality of this DBMS, I doubt it is worth any time or efforts to investigate this issue any further.

Thanks for the information! 👍

Why do you think its not worth any time?
I think there can be a fix. If you can contribute to the project i'll appreciate it.

how much speed this microdb?