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

Firebird performance issue - unnecessary index reads #7494

Closed
EPluribusUnum opened this issue Mar 3, 2023 · 11 comments
Closed

Firebird performance issue - unnecessary index reads #7494

EPluribusUnum opened this issue Mar 3, 2023 · 11 comments

Comments

@EPluribusUnum
Copy link

EPluribusUnum commented Mar 3, 2023

Hi *!

SELECT FIRST 1 1 FROM fk_tetel WHERE szla = '361'
--PLAN (FK_TETEL INDEX (FK_TETEL_FKISZ_ID_SZLA_FK))

returns no row
No "Enchanced Info" (IBExpert) because no read at all.
This is the expected behaviour

SELECT FIRST 1 1 FROM fk_tetel WHERE szla = '3611'
--PLAN (FK_TETEL INDEX (FK_TETEL_FKISZ_ID_SZLA_FK))--same plan

also returns no row, BUT "Enchanced Info" reports 6227 index red on FK_TETEL
Where does the index reads come from and why? It should be 0 Index reads also in this case.
(Firebird 3.0.10, x64, Windows)

I uploaded the database to FTP and will the login details in DM on request.

Thank you!

@EPluribusUnum
Copy link
Author

This extra reads happens for many different values, not just the reported example value.
Also this condition in our case could be inside nested loops so the extra reads quickly blows up and hits us very hard adding many millons unnecessary record reads.

@hvlad
Copy link
Member

hvlad commented Mar 6, 2023

Send it to me, please

@EPluribusUnum
Copy link
Author

@hvlad , details sent.

@hvlad
Copy link
Member

hvlad commented Mar 7, 2023

Reproduced, thanks.

The problem happens when:

  • search key length is multiply of 4
  • there is records with key field values length greater than search key length
  • the index is multi-segment
  • the index match is partial, i.e. some last segments is not used.

The issue is not a regression, it should be present in previous Firebird versions.
The simplest workaround (until proper solution not found) is to use single-segment index.

@EPluribusUnum
Copy link
Author

Thanks. Hoping for a fast fix 🙏 . I don't think we will put extra (duplicate) indicies to tables beacause of this. (The multi segment index in this case is came from a foreign key, can't drop it)

@hvlad
Copy link
Member

hvlad commented Mar 13, 2023

FYI: I have a fix for this case but it doesn't handle descending indices so far. Working on it.

hvlad added a commit that referenced this issue Mar 28, 2023
…eads.

Also, fixed unregistered bug when scan of multi-segmented descending index with partial match and greater-than condition could miss some records.
@EPluribusUnum
Copy link
Author

@hvlad , the latest snapshot (03.31) does not contain this fix? I'll run my tests and also yours, and still makes extra reads, and sometimes neve return recors when it should be.

@hvlad
Copy link
Member

hvlad commented Mar 31, 2023

I've created pull request #7521 and awaiting for comments from other devs.

hvlad added a commit that referenced this issue Apr 7, 2023
Impovement #7494 : Firebird performance issue - non necessary index r…
@hvlad
Copy link
Member

hvlad commented Apr 7, 2023

The pull request is merged, please check next snapshot build.

@EPluribusUnum
Copy link
Author

@hvlad , checked, it OK. Thank you!

@hvlad
Copy link
Member

hvlad commented Apr 11, 2023

Re-opened for forward porting

@hvlad hvlad reopened this Apr 11, 2023
hvlad added a commit that referenced this issue Apr 13, 2023
…ssary index reads.

Also, fixed unregistered bug when scan of multi-segmented descending index with partial match and greater-than condition could miss some records.
hvlad added a commit that referenced this issue Apr 13, 2023
…ssary index reads.

Also, fixed unregistered bug when scan of multi-segmented descending index with partial match and greater-than condition could miss some records.
@hvlad hvlad closed this as completed Apr 13, 2023
@mrotteveel mrotteveel changed the title Firebird performance issue - non necessary index reads Firebird performance issue - unnecessary index reads Aug 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment