Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> Re: INDEX possible for reverse wildcards?
Christopher Browne <cbbrowne_at_acm.org> wrote:
> After takin a swig o' Arrakan spice grog, ctcgag_at_hotmail.com belched out:
> > "Mikito Harakiri" <mikharakiri_at_iahu.com> wrote:
> >> <ctcgag_at_hotmail.com> wrote in message
> >> news:20040604183510.277$gk_at_newsreader.com...
> >> > Well, you would only need to look at index entries that start with
> >> > 'w', '%', or '_'. And if the first character is a 'w' or a '_', you
> >> > only need to look at ones where the second is 'w', '%', or '_'.
> >>
> >> And if the first character happens to be '%', then?
> >
> > Then you check the rest of it to see if it matches. (What did you
> > expect?)
>
>
Actually, the original question was rather Oracle *does* do it, not whether it could do it. When someone suggested that Oracle could not do it with their current index structure, I suggested they could at least get *some* benefit from it without changing the physical index structure, only changing some of the code that accesses it.
>
But that is what the original poster specifically excluded. He wanted it the other way around:
select * from some_table where 'Brown' like name;
Where the wildcards reside in the column, not in the bind value.
>
>
>
Yes, and in the case under discussion, my example could be transformed to something like:
select * from some_table where 'Brown' like name and substr(name,1,1) in ('B','_','%').
Where the "substr... in ..." part could (at least theoretically) be supported by the index. Of course for maximum benefit you would have to have to code the access method itself, not just some query re-write, because you could apply it recursively to each successive letter, up until a % is found, at which point you would have to return to the brute force method (or some even more clever method)
>
>
>
Meanwhile, in the situation we were actually talking about, with the pattern in the column, not in the bind variable---Sure, you still have to scan the patterns that do start with %, but there may be an aweful lot of patterns that don't start with % (or with _, or with the first letter of the query), and hence can be ruled out using the index, without ever scanning them.
Xho
-- -------------------- http://NewsReader.Com/ -------------------- Usenet Newsgroup Service $9.95/Month 30GBReceived on Sat Jun 05 2004 - 12:24:37 CDT
![]() |
![]() |