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

Resolve todo "Blob pattern search is slow" #3917

Closed
wants to merge 1 commit into from
Closed

Resolve todo "Blob pattern search is slow" #3917

wants to merge 1 commit into from

Conversation

nell-shark
Copy link
Contributor

See Todo

If you would like to save a previous code:

BufferedInputStream in = new BufferedInputStream(value.getInputStream());
IOUtils.skipFully(in, start - 1);
int pos = 0;
int patternPos = 0;
while (true) {
    int x = in.read();
    if (x < 0) {
        break;
    }
    if (x == (pattern[patternPos] & 0xff)) {
        if (patternPos == 0) {
            in.mark(pattern.length);
        }
        if (patternPos == pattern.length) {
            return pos - patternPos;
        }
        patternPos++;
    } else {
        if (patternPos > 0) {
            in.reset();
            pos -= patternPos;
        }
    }
    pos++;
}
return -1;

I think you need to update code as follows:

if (patternPos == (pattern.length -1)) {
  return pos - patternPos;
}

and:

if (patternPos > 0) {
  in.reset();
  pos -= patternPos;
  patternPos = 0;
}

@katzyn
Copy link
Contributor

katzyn commented Oct 24, 2023

Thank you for your contribution!

This method is unconditionally disabled in H2, there is no way to use it without recompliation of H2 with modified sources and it seems that nobody cares, this method doesn't look like being really useful.

If you really want to improve it, you also need to remove Constants.BLOB_SEARCH and related conditions and add some real tests for both Blob.position() methods to TestLobApi, including tests with invalid arguments.

ArrayList<Byte> also isn't suitable for efficient implementations.

@nell-shark
Copy link
Contributor Author

@katzyn, Thank you for your quick feedback

@nell-shark nell-shark closed this Oct 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants