codenotary / immudb

immudb - immutable database based on zero trust, SQL/Key-Value/Document model, tamperproof, data change history
https://immudb.io
Other
8.54k stars 341 forks source link

Select statement gets stuck due to indexing issue #1943

Closed ostafen closed 1 month ago

ostafen commented 4 months ago

What happened

A select statement over a table with a primary key of type VARCHAR(512) completely gets stuck and returns no result rows.

What you expected to happen

The query either returns an error or some result rows.

How to reproduce it (as minimally and precisely as possible)

Initialize a table as follows:

BEGIN TRANSACTION;

CREATE TABLE IF NOT EXISTS tb (
   pk VARCHAR(512) NOT NULL,

   PRIMARY KEY (pk)
);

INSERT INTO tb(pk) VALUES ('test');
COMMIT;

and run a select statement:

SELECT * FROM tb;

Environment

immudb v1.9.0-RC2

Additional info (any other context about the problem)

The problem is due to the following indexing issue:

immudb  2024/04/02 09:27:49 ERROR: indexing failed at 'data' due to error: tbtree: max key size exceeded

Indexing a primary key of VARCHAR(512) type produces index keys exceeding the maximum key size allowed by immudb (the issue doesn't show with types of shorter size, such as VARCHAR(256) or numeric types). Such error is never forwarded correctly and causes the code to get stuck on the following lines:

err = indexer.WaitForIndexingUpto(ctx, txID)
if err != nil {
    return nil, err
}