Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected error after deleting an index #7754

Open
Noremos opened this issue Sep 20, 2023 · 4 comments
Open

Unexpected error after deleting an index #7754

Noremos opened this issue Sep 20, 2023 · 4 comments

Comments

@Noremos
Copy link
Contributor

Noremos commented Sep 20, 2023

Here is a simple example. Create the follow metadata:

create table DOC(PAR_ID integer, EXC_ID integer, exe_name varchar(1000));
insert into DOC values(0, 1,'123r332');
commit;
CREATE INDEX DOC_INDEX ON DOC COMPUTED BY (upper(exe_name));
exit;

Then in a new connection:

Database: test.fdb, User: SYSDBA
SQL> set autoddl off;
SQL> drop index DOC_INDEX;
SQL> select * from DOC where EXC_ID = 1;
Statement failed, SQLSTATE = 42S12
there is no index in table DOC with id 0

The problem is that is kinda inconsistent. For example, if i call some select * from doc earlier, the error disappears

Database: test.fdb, User: SYSDBA
SQL> select * from DOC where PAR_ID = 1;
SQL> set autoddl off;
SQL> drop index DOC_INDEX;
SQL> select * from DOC where EXC_ID = 1;

PAR_ID                          0
EXC_ID                          1
EXE_NAME                        123r332

But this case is nothing compared to the next one. Same 3 calls, but now with two connections:

->start connect 1
->start connect 2
connect 1:
Database: localhost:test.fdb, User: SYSDBA
set autoddl off;
drop index DOC_INDEX;
select * from DOC where EXC_ID = 1;
The error...

connect 2: 
Database: localhost:test.fdb, User: SYSDBA
SQL> insert into DOC values(5, 7,'1,h7j332');
Statement failed, SQLSTATE = 42S12
Error during savepoint backout - transaction invalidated
-there is no index in table DOC with id 0
SQL> 

This is highly unexpected for regular users
Tested on the master branch (ffd31e3)

@dyemanov
Copy link
Member

Regular users are commonly suggested to avoid (1) intermixing DDL and DML in a single transaction and (2) running DDL in concurrent environment. That said, I would still be good to have this issue resolved if possible.

@hvlad
Copy link
Member

hvlad commented Sep 20, 2023

Why expression index is used in example ? Is it important ?

@dyemanov
Copy link
Member

Yes, it's important (either expression or partial index is required).

@Noremos
Copy link
Contributor Author

Noremos commented Sep 20, 2023

Why expression index is used in example ? Is it important ?

The error message comes from here

firebird/src/jrd/btr.cpp

Lines 968 to 994 in 78f2097

if (idx->idx_flags & idx_expression)
{
MET_lookup_index_expression(tdbb, relation, idx);
if (!idx->idx_expression)
{
if (tdbb->tdbb_flags & TDBB_sweeper)
return false;
// Definition of index expression is not found for index @1
error = isc_idx_expr_not_found;
}
}
if (!error && idx->idx_flags & idx_condition)
{
MET_lookup_index_condition(tdbb, relation, idx);
if (!idx->idx_condition)
{
if (tdbb->tdbb_flags & TDBB_sweeper)
return false;
// Definition of index condition is not found for index @1
error = isc_idx_cond_not_found;
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants