Subject Re: [Firebird-Java] Re: Streamed Blob
Author Nickolay Samofatov
Hello, Roman, All,

>> Are streamed blobs a possibility when using JayBird? I cannot reliably
>> use LIKE queries that contain wild cards with a segmented blob. The
>> wild card breaks if it goes across a segment boundary. For example, if
>> I select LIKE "%line2%line200%" and the blob segments on say line 50,
>> the query will fail.

> Yes, current version of JayBird in CVS uses stream blobs by default
> (and probably using segemented blobs needs recompilation :)). But as
> long as your blob was created segmented, you cannot switch it to
> streamed and vice versa. So, if your test works in IBExpert with the
> same blob it fails in JayBird, then something wrong is somewhere else.

Engine evaluates "LIKE" statement in 1024-byte chunks for streamed
blobs. Here is the relevant code:

blob =
BLB_open(tdbb, tdbb->tdbb_request->req_transaction,
reinterpret_cast < bid * >(desc1->dsc_address));

/* Performs the string_function on each segment of the blob until
a positive result is obtained */

ret_val = FALSE;
while (!(blob->blb_flags & BLB_eof)) {
l1 = BLB_get_segment(tdbb, blob, buffer, sizeof(buffer));
if (string_function(tdbb, node, l1, buffer, l2, p2, type1)) {
ret_val = TRUE;
break;
}
if (node->nod_type == nod_starts)
break;
}

BLB_close(tdbb, blob);

buffer has the size of 1024 bytes.

It seems obvious to apply a little bit of hacking and fetch entire
blob before doing pattern-matching, but it opens another problem.
Implementation of pattern-matching algorithm is very far from being
perfect, it has max cost of O(N^3*M^2) where N and M are lengths of LIKE
arguments. So if this algorithm is applied to large BLOB with string
like this it will run forever. This has to be fixed first.
Any volunteers to implement good pattern-matching algorithm ?

> Roman

--
Nickolay Samofatov mailto:skidder@...