Re: WIP: index support for regexp search

Поиск
Список
Период
Сортировка
Искать

Re: WIP: index support for regexp search

От:
"Erik Rijkers" <er@xs4all.nl>
Дата:
On Tue, December 18, 2012 08:04, Alexander Korotkov wrote:

> trgm-regexp-0.9.patch.gz   22 k

Hi.

I ran the same test again: HEAD versus trgm_regex v6, 7 and 9.  In v9 there is some gain but also
some regression.

It remains a difficult problem...

If I get some time in the holidays I'll try to diversify the test program; it is now too simple.


Thanks,

Erik Rijkers

Re: WIP: index support for regexp search

От:
"Erik Rijkers" <er@xs4all.nl>
Дата:

Re: WIP: index support for regexp search

От:
"Erik Rijkers" <er@xs4all.nl>
Дата:
On Fri, November 30, 2012 12:22, Alexander Korotkov wrote:
> Hi!
>
> On Thu, Nov 29, 2012 at 12:58 PM, er  wrote:
>
>> On Mon, November 26, 2012 20:49, Alexander Korotkov wrote:
>>
>>
>> I ran the simple-minded tests against generated data (similar to the ones
>> I did in January 2012).
>> The problems of that older version seem pretty much all removed. (although
>> I didn't do much work
>> on it -- just reran these tests).
>>
>
> Thanks a lot for testing! Could you repeat for 0.7 version of patch which
> has new overflow handling?
>

I've attached a similar test re-run that compares HEAD with patch versions 0.6, and 0.7.


Erik Rijkers

Re: WIP: index support for regexp search

От:
"Erik Rijkers" <er@xs4all.nl>
Дата:
On Sun, December 2, 2012 19:07, Alexander Korotkov wrote:
>>
>> I've attached a similar test re-run that compares HEAD with patch versions
>> 0.6, and 0.7.
>>
>
> Thanks! Did you write scripts for automated testing? I would be nice if you
> share them.
>

Sure, here they are.

The perl program does depend a bit on my particular setup (it reads the port from the
postgresql.conf of each instance, and the script knows the data_dir locations), but I suppose it's
easy enough to remove that.

(Just hardcode the %instances hash, instead of calling instances().)

If you need help to get them to run I can 'generalise' them, but for now I'll send them as they are.

Erik Rijkers


Re: WIP: index support for regexp search

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Alexander Korotkov  writes:
> [ trgm-regexp-0.15.patch.gz ]

I spent the weekend hacking on this, making a number of bug fixes and a
whole lot of cosmetic changes.  I think there are large parts of this
that are in committable shape now, but I still find the actual graph
transformation logic to be mostly unintelligible.  I think what's most
obscure is the distinction between the arcs list and the keys list of
each state in the expanded graph.  I get the impression that the
general idea is for the arcs to represent exactly-known transitions
while the keys represent imprecisely-known transitions ... but there
seems to be at least some leakage between those categories.  Could
you write down a specification for what's supposed to be happening
there?

			regards, tom lane

Re: WIP: index support for regexp search

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:

Re: WIP: index support for regexp search

От:
"Erik Rijkers" <er@xs4all.nl>
Дата:

Re: WIP: index support for regexp search

От:
Stephen Frost <sfrost@snowman.net>
Дата:

Re: WIP: index support for regexp search

От:
David Fetter <david@fetter.org>
Дата:

Re: WIP: index support for regexp search

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:

Re: WIP: index support for regexp search

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:

Re: WIP: index support for regexp search

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:

Re: WIP: index support for regexp search

От:
Heikki Linnakangas <heikki.linnakangas@enterprisedb.com>
Дата:

Re: WIP: index support for regexp search

От:
Tomas Vondra <tv@fuzzy.cz>
Дата:

Re: WIP: index support for regexp search

От:
Heikki Linnakangas <hlinnakangas@vmware.com>
Дата:

Re: WIP: index support for regexp search

От:
Heikki Linnakangas <hlinnakangas@vmware.com>
Дата:
On 25.11.2012 22:55, Alexander Korotkov wrote:
> On Tue, Nov 20, 2012 at 1:43 PM, Heikki Linnakangas> wrote:
>
>> Glad to see this patch hasn't been totally forgotten. Being able to use
>> indexes for regular expressions would be really cool!
>>
>> Back in January, I asked for some high-level description of how the
>> algorithm works (http://archives.postgresql.**
>> org/message-id/4F187D5C.30701@**enterprisedb.com).
>> That's still sorely needed. Googling around, I found the slides for your
>> presentation on this from PGConf.EU - it would be great to have the
>> information from that presentation included in the patch.
>
>
> New version of patch is attached. The changes are following:
> 1) A big comment with high-level description of what is going on.
> 2) Regression tests.
> 3) Documetation update.
> 4) Some more refactoring.

Great, that top-level comment helped tremendously! I feel enlightened.

I fixed some spelling, formatting etc. trivial stuff while reading 
through the patch, see attached. Below is some feedback on the details:

* I don't like the PG_TRY/CATCH trick. It's not generally safe to catch 
an error, without propagating it further or rolling back the whole 
(sub)transation. It might work in this case, as you're only suppressing 
errors with the special sqlcode that are used in the same file, but it 
nevertheless feels naughty. I believe none of the limits that are being 
checked are strict; it's OK to exceed the limits somewhat, as long as 
you terminate the processing in a reasonable time, in case of 
pathological input. I'd suggest putting an explicit check for the limits 
somewhere, and not rely on ereport(). Something like this, in the code 
that recurses:

if (trgmCNFA->arcsCount > MAX_RESULT_ARCS ||
     hash_get_num_entries(trgmCNFA->states) > MAX_RESULT_STATES)
{
	trgmCNFA->overflowed = true;
	return;
}

And then check for the overflowed flag at the top level.

* This part of the high-level comment was not clear to me:

>  * States of the graph produced in the first stage are marked with "keys". Key is a pair
>  * of a "prefix" and a state of the original automaton. "Prefix" is a last
>  * characters. So, knowing the prefix is enough to know what is a trigram when we read some new
>  * character. However, we can know single character of prefix or don't know any
>  * characters of it. Each state of resulting graph have an "enter key" (with that
>  * key we've entered this state) and a set of keys which are reachable without
>  * reading any predictable trigram. The algorithm of processing each state
>  * of resulting graph are so:
>  * 1) Add all keys which achievable without reading of any predictable trigram.
>  * 2) Add outgoing arcs labeled with trigrams.
>  * Step 2 leads to creation of new states and recursively processing them. So,
>  * we use depth-first algorithm.

I didn't understand that. Can you elaborate? It might help to work 
through an example, with some ascii art depicting the graph.

* It would be nice to add some comments to TrgmCNFA struct, explaining 
which fields are valid at which stages. For example, it seems that 
'trgms' array is calculated only after building the CNFA, by 
getTrgmVector() function, while arcsCount is updated on the fly, while 
recursing in the getState() function.

* What is the representation used for the path matrix? Needs a comment.

* What do the getColorinfo() and scanColorMap() functions do? What 
exactly does a color represent? What's the tradeoff in choosing 
MAX_COLOR_CHARS?

- Heikki

Re: WIP: index support for regexp search

От:
Heikki Linnakangas <hlinnakangas@vmware.com>
Дата:

Re: WIP: index support for regexp search

От:
Heikki Linnakangas <hlinnakangas@vmware.com>
Дата:

Re: WIP: index support for regexp search

От:
Heikki Linnakangas <hlinnakangas@vmware.com>
Дата:

Re: WIP: index support for regexp search

От:
Heikki Linnakangas <hlinnakangas@vmware.com>
Дата:
On 18.12.2012 09:04, Alexander Korotkov wrote:
> Bug is found and fixed in attached patch.

I finally got around to look at this. I like this new version, without 
the path matrix, much better.

I spend quite some time honing the code and comments, trying to organize 
it so that it's easier to understand. In particular, I divided the 
processing more clearly into four separate stages, and added comments 
indicating which functions and which fields in the structs are needed in 
which state.

I understand the other stages fairly well now, but the transformation 
from the source CNFA form into the transformed graph is still a black 
box to me. The addKeys/addArcs functions still need more explanation. 
Can you come up with some extra comments or refactoring to clarify those?

I'd like to see a few more regression test cases, to cover the various 
overflow cases. In particular, I built with --enable-coverage and ran 
"make installcheck", and it looks like the state merging code isn't 
exercised at all. Report attached.

To visualize the graphs, I rewrote the debugging print* functions to 
write the graphs in graphviz .dot format. That helped a lot. See 
attached graphs, generated from the regexp '^(abc|def)(ghi|jk[lmn])$'.

There's still a lot of cleanup to do, I'm going to continue working on 
this tomorrow, but wanted to shared what I have this far.

- Heikki

Re: WIP: index support for regexp search

От:
Heikki Linnakangas <hlinnakangas@vmware.com>
Дата:

Re: WIP: index support for regexp search

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:

Re: WIP: index support for regexp search

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:

Re: WIP: index support for regexp search

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:

Re: WIP: index support for regexp search

От:
"Erik Rijkers" <er@xs4all.nl>
Дата:

Re: WIP: index support for regexp search

От:
"Erikjan Rijkers" <er@xs4all.nl>
Дата:
On Tue, April 2, 2013 23:54, Alexander Korotkov wrote:

> [trgm-regexp-0.15.patch.gz]

Yes, it does look good now; Attached a list of measurements. Most of the searches that I put in
that test-program are now speeded up very much.

There still are a few regressions, for example:

HEAD          azjunk6  x[aeiou]{4,5}q          83  Seq Scan          1393.465 ms
trgm_regex15  azjunk6  x[aeiou]{4,5}q          83  Bitmap Heap Scan  1728.319 ms

HEAD          azjunk7  x[aeiou]{1,3}q      190031  Seq Scan         16819.555 ms
trgm_regex15  azjunk7  x[aeiou]{1,3}q      190031  Bitmap Heap Scan 21286.804 ms

Not exactly negligible, and ideally those regressions would be removed but with the huge
advantages for other cases I'd say it's worth it.

hth,

Erik Rijkers



Re: WIP: index support for regexp search

От:
"Erikjan Rijkers" <er@xs4all.nl>
Дата:
On Mon, April 1, 2013 23:15, Alexander Korotkov wrote:

[trgm-regexp-0.14.patch.gz]

Hi Alexander,

Something went wrong in this version of the patch: many (most) queries that were earlier
spectacularly fast have become slow, often slower than a seqscan or only marginally faster. See
the attached numbers; it compares head(seqscan) with trgm-regex patch versions 13 and 14.

I did not even complete the test-run because version 14 is so clearly inferior to 13 (and earlier,
as far as I can remember).

(let me know if you want the whole result, I can run it overnight)


Thanks,


Erik Rijkers

Re: WIP: index support for regexp search

От:
"Erik Rijkers" <er@xs4all.nl>
Дата:

Re: WIP: index support for regexp search

От:
Robert Haas <robertmhaas@gmail.com>
Дата:

Re: WIP: index support for regexp search

От:
Marti Raudsepp <marti@juffo.org>
Дата:

Re: WIP: index support for regexp search

От:
Pavel Stehule <pavel.stehule@gmail.com>
Дата:

Re: WIP: index support for regexp search

От:
Pavel Stehule <pavel.stehule@gmail.com>
Дата:

Re: WIP: index support for regexp search

От:
Alexander Korotkov <aekorotkov@gmail.com>
Дата:
On Fri, Nov 30, 2012 at 3:20 PM, Alexander Korotkov <aekorotkov@gmail.com> wrote:
For depth-first it's not. 

Oh, I didn't explained it. 
In order to stop graph processing we need to be sure that we put all outgoing arcs from state or assume that state to be final. In DFS we can be in the final part of graph producing but still didn't add some arc (with new trigram) from initial state directly to the final state. It obviously leads to false negatives.

------
With best regards,
Alexander Korotkov.

Re: WIP: index support for regexp search

От:
Alexander Korotkov <aekorotkov@gmail.com>
Дата:
On Mon, Dec 3, 2012 at 2:05 PM, Heikki Linnakangas <hlinnakangas@vmware.com> wrote:
On 02.12.2012 20:19, Tom Lane wrote:
Alexander Korotkov<aekorotkov@gmail.com>  writes:
Nice idea to delay expanding colors to characters! Obviously, we should
delay expanding inly alphanumerical characters. Because non-alphanumberical
characters influence graph structure. Trying to implement...

Uh, why would that be?  Colors are colors.  The regexp machinery doesn't
care whether they represent alphanumerics or not.  (Or to be more
precise, if there is a situation where it makes a difference, separate
colors will have been created for each set of characters that need to be
distinguished.)

The regexp machinery doesn't care, but the trigrams that pg_trgm extracts only contain alphanumeric characters. So if by looking at the CNFA graph produced by the regexp machinery you conclude that any matching strings must contain three-letter sequences "%oo" and "#oo", you can just club them together into " oo" trigram.

I think you can run a pre-processing step to the colors, and merge colors that are equivalent as far as trigrams are considered. For example, if you have a color that contains only character '%', and another that contains character '#', you can treat them as the same hcolor. You might then be able to simplify the CNFA. Actually, it would be even better if you could apply the pre-processing to the regexp before the regexp machinery turns it into a CNFA. Not sure how easy it would be to do such pre-processing.
 
Treating colors as same should be possible only for colors which has no alphanumeric characters, because colors are non-overlapping. However, this optimization could be significant in some cases.

BTW, why create the path matrix? You could check the "check" array of trigrams in the consistent function directly against the graph. Consistent should return true, iff there is a path through the graph following only arcs that contain trigrams present in the check array. Finding a path through a complex graph could be expensive, O(|E|), but if the path is complex, the path matrix would be large as well, and checking against a large matrix isn't exactly free either. It would allow you to avoid "overflows" caused by having too many paths through the graph.

Actually, I generally dislike path matrix for same reasons. But:
1) Output graphs could contain trigrams which are completely useless for search. For example, for regex /(abcdefgh)*ijk/ we need only "ijk" trigram while graph would contain much more.Path matrix is a method to get rid of all of them.
2) If we use color trigrams then we need some criteria for which color trigrams to expand into trigrams. Simultaneously, we shouldn't allow path from initial state to the final by unexpanded trigrams. It seems much harder to do with graph than with matrix.

------
With best regards,
Alexander Korotkov.

Re: WIP: index support for regexp search

От:
Alexander Korotkov <aekorotkov@gmail.com>
Дата:
On Fri, Dec 14, 2012 at 1:34 AM, Alexander Korotkov <aekorotkov@gmail.com> wrote:
On Mon, Dec 3, 2012 at 4:31 PM, Alexander Korotkov <aekorotkov@gmail.com> wrote:
Actually, I generally dislike path matrix for same reasons. But:
1) Output graphs could contain trigrams which are completely useless for search. For example, for regex /(abcdefgh)*ijk/ we need only "ijk" trigram while graph would contain much more.Path matrix is a method to get rid of all of them.
2) If we use color trigrams then we need some criteria for which color trigrams to expand into trigrams. Simultaneously, we shouldn't allow path from initial state to the final by unexpanded trigrams. It seems much harder to do with graph than with matrix.

Now, I have an idea about doing some not comprehensive but simple and fast simplification of graph. I'm doing experiments now. In case of success we could get rid of path matrix.

Attached patch have following changes:
1) Postphone expansion of colors. Graph are building on color trigrams.
2) Selective expansion of color trigrams into simple trigrams. All non-expanded color trigrams are removed. Such removal leads to union of all states pairs connected with corresponding arcs. Surely, this must no lead to union of initial and final states: that could do all previous work senseless.

------
With best regards,
Alexander Korotkov.

Re: WIP: index support for regexp search

От:
Alexander Korotkov <aekorotkov@gmail.com>
Дата:
On Wed, Apr 3, 2013 at 11:10 AM, Erikjan Rijkers <er@xs4all.nl> wrote:
On Tue, April 2, 2013 23:54, Alexander Korotkov wrote:

> [trgm-regexp-0.15.patch.gz]

Yes, it does look good now; Attached a list of measurements. Most of the searches that I put in
that test-program are now speeded up very much.

There still are a few regressions, for example:

HEAD          azjunk6  x[aeiou]{4,5}q          83  Seq Scan          1393.465 ms
trgm_regex15  azjunk6  x[aeiou]{4,5}q          83  Bitmap Heap Scan  1728.319 ms

HEAD          azjunk7  x[aeiou]{1,3}q      190031  Seq Scan         16819.555 ms
trgm_regex15  azjunk7  x[aeiou]{1,3}q      190031  Bitmap Heap Scan 21286.804 ms

Not exactly negligible, and ideally those regressions would be removed but with the huge
advantages for other cases I'd say it's worth it.

Thank you for testing!
Exploring results more detail I found version 13 to be buggy. This version is a dead end, we have quite different API now. Could you use v12 instead of v13 in comparison, please?
Sometimes we have regression in comparison with head in two reasons:
1) We select index scan in both cases but with patch we spent more time for analysis. It's inevitable disadvantage of any index. We can only take care of analysis doesn't take too long. Current testing results don't show this reason to be significant.
2) Sometimes we select index scan while sequential scan would be faster. It's also inevitable disadvantage until we have a relevant statistics. We now have similar situation, for example, with in-core geometrical search and LIKE/ILIKE search in pg_trgm. However,  probably, situation could be improved somehow even without such statistics. But I think we can do such conclusion based on synthetical testing, because improvements for synthetical cases could appear to be an worsening for real-life cases.

------
With best regards,
Alexander Korotkov.

Re: WIP: index support for regexp search

От:
Alexander Korotkov <aekorotkov@gmail.com>
Дата:
On Tue, Dec 18, 2012 at 11:45 AM, Erik Rijkers <er@xs4all.nl> wrote:
On Tue, December 18, 2012 08:04, Alexander Korotkov wrote:
I ran the same test again: HEAD versus trgm_regex v6, 7 and 9.  In v9 there is some gain but also
some regression.

It remains a difficult problem...

If I get some time in the holidays I'll try to diversify the test program; it is now too simple.

Note, that regexes which contains {,n} are likely not what do you expect.

test=# select 'xq' ~ 'x[aeiou]{,2}q';
 ?column? 
----------
 f
(1 row)

test=# select 'xa{,2}q' ~ 'x[aeiou]{,2}q';
 ?column? 
----------
 t
(1 row)

You should use {0,n} to express from 0 to n occurences.

------
With best regards,
Alexander Korotkov.

Re: WIP: index support for regexp search

От:
Alexander Korotkov <aekorotkov@gmail.com>
Дата:
Hi!

On Mon, Dec 17, 2012 at 12:54 PM, Erik Rijkers <er@xs4all.nl> wrote:
On Sun, December 16, 2012 22:25, Alexander Korotkov wrote:

> trgm-regexp-0.8.patch.gz   22 k

Hi Alexander,

I gave this a quick try; the patch works when compiled for DEBUG, but crashes as a
'speed'-compiled binary:

Compile for speed:

$ pg_config --configure
'--prefix=/home/aardvark/pg_stuff/pg_installations/pgsql.trgm_regex8' '--with-pgport=6556'
'--enable-depend' '--with-openssl' '--with-perl' '--with-libxml'

$ psql
psql (9.3devel-trgm_regex8-20121216_2336-c299477229559d4ee7db68720d86d3fb391db761)
Type "help" for help.

testdb=# explain analyze select txt from azjunk5 where txt ~ 'x[aeiouy]{2,5}q';
The connection to the server was lost. Attempting reset: Failed.
!> \q

Didn't reproduce it yet. Can you retry it with this line uncommented:
#define TRGM_REGEXP_DEBUG
Then we can see which stage it fails.

------
With best regards,
Alexander Korotkov.

Re: WIP: index support for regexp search

От:
Alexander Korotkov <aekorotkov@gmail.com>
Дата:
On Mon, Mar 25, 2013 at 1:50 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Alexander Korotkov <aekorotkov@gmail.com> writes:
> Now I have working implemetation of this API. Comments still need rework.
> Could you give me any feedback?

I looked at this a little bit, but it's not very far along at all
towards resolving my API worries.  The basic point that I'm concerned
about is that we would like to split off the regex library (ie,
backend/regex/) as a standalone project someday.  There are already
some problems to be resolved to make that possible, and I don't want
this patch to introduce new ones.  From that standpoint, the proposed
regextract.c file is a disaster, because it depends on a boatload of
Postgres-specific stuff (at least StringInfo, List, HTAB, and pg_wchar;
to say nothing of palloc).  We can't consider that to be on the regex
side of the fence.
 
Now I can see your position about API much more clearly. Previously I thought only about algorithmic side of things.

Similarly, pushing PG-specific declarations like RE_compile_and_cache()
into regex/regex.h is completely not the right thing for preserving a
clear library boundary (even positing that we want to expose that
function outside adt/regexp.c, which I'd rather we didn't).

Given that you've already got a notion of callbacks provided by
contrib/pg_trgm, perhaps this can be fixed by pushing more of the work
into those callbacks, so that the heavy-duty data structures like the
hash table live over there and the API exposed by backend/regex/ is at
a much simpler level than what you have here.  But right now I don't
see any usable library API here.

Perhaps we could avoid these issues by defining a library API that
provides accessors like these for the opaque regex_t struct:

* get the number of states in the CNFA

* get the numbers of the initial and final states

* get the number of out-arcs for the N'th state

* get the out-arcs for the N'th state into a caller-provided array
(sized using the previous function), where each out-arc is represented
by a color and an end-state

* get the number of character codes represented by color C

* get the wchar codes for color C into a caller-provided array

(The reason for letting the caller allocate the result arrays is so we
can use palloc for that; if we allocate it in backend/regex/ we must
use malloc, which will greatly increase the risk of leakages.  Also,
as far as the color API goes, the above lets the caller decide how
many characters is "too many" to bother with.)

I like the this idea. Seems like clear and not over-engineered API. I can implement it. Could you propose something particular to do with RE_compile_and_cache in this patch? With this API we still need a way to get regex_t or equivalent from string.

------
With best regards,
Alexander Korotkov.

Re: WIP: index support for regexp search

От:
Alexander Korotkov <aekorotkov@gmail.com>
Дата:

On Tue, Nov 20, 2012 at 1:43 PM, Heikki Linnakangas <hlinnakangas@vmware.com> wrote:
Glad to see this patch hasn't been totally forgotten. Being able to use indexes for regular expressions would be really cool!

Back in January, I asked for some high-level description of how the algorithm works (http://archives.postgresql.org/message-id/4F187D5C.30701@enterprisedb.com). That's still sorely needed. Googling around, I found the slides for your presentation on this from PGConf.EU - it would be great to have the information from that presentation included in the patch.

New version of patch is attached. The changes are following:
1) A big comment with high-level description of what is going on.
2) Regression tests.
3) Documetation update.
4) Some more refactoring.

------
With best regards,
Alexander Korotkov.

Re: WIP: index support for regexp search

От:
Alexander Korotkov <aekorotkov@gmail.com>
Дата:
On Fri, Nov 30, 2012 at 6:23 PM, Heikki Linnakangas <hlinnakangas@vmware.com> wrote:
On 30.11.2012 13:20, Alexander Korotkov wrote:
On Thu, Nov 29, 2012 at 5:25 PM, Heikki Linnakangas<hlinnakangas@vmware.com
wrote:

Would it be safe to simply stop short the depth-first search on overflow,
and proceed with the graph that was constructed up to that point?

For depth-first it's not. But your proposal naturally makes sense. I've
changed it to breadth-first search. And then it's safe to mark all
unprocessed states as final when overflow. It means that we assume every
unprocessed branch to immediately finish with matching (this can give us
more false positives but no false negatives).
For overflow of matrix collection, it's safe to do just OR between all the
trigrams.
New version of patch is attached.

Thanks, sounds good.

I've spent quite a long time trying to understand the transformation the getState/addKeys/addAcrs functions do to the original CNFA graph. I think that still needs more comments to explain the steps involved in it.

One thing that occurs to me is that it might be better to delay expanding colors to characters. You could build and transform the graph, and even create the paths, all while operating on colors. You would end up with lists of "color trigrams", consisting of sequences of three colors that must appear in the source string. Only at the last step you would expand the color trigrams to real character trigrams. I think that would save a lot of processing while building the graph, if you have colors that contain many characters. It would allow us to do better than the fixed small MAX_COLOR_CHARS limit. For example with MAX_COLOR_CHARS = 4 in the current patch, it's a shame that we can't do anything with a fairly simple regexp like "^a[b-g]h$"

Nice idea to delay expanding colors to characters! Obviously, we should delay expanding inly alphanumerical characters. Because non-alphanumberical characters influence graph structure. Trying to implement...

------
With best regards,
Alexander Korotkov.

Re: WIP: index support for regexp search

От:
Alexander Korotkov <aekorotkov@gmail.com>
Дата:
On Thu, Dec 1, 2011 at 12:29 AM, Robert Haas <robertmhaas@gmail.com> wrote:
Please add this patch here so it does not get lost in the shuffle:

https://commitfest.postgresql.org/action/commitfest_view/open

Done.

------
With best regards,
Alexander Korotkov.

Re: WIP: index support for regexp search

От:
Alexander Korotkov <aekorotkov@gmail.com>
Дата:
On Wed, Jan 23, 2013 at 7:29 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Heikki Linnakangas <hlinnakangas@vmware.com> writes:
> On 23.01.2013 09:36, Alexander Korotkov wrote:
>> On Wed, Jan 23, 2013 at 6:08 AM, Tom Lane<tgl@sss.pgh.pa.us>  wrote:
>>> The biggest problem is that I really don't care for the idea of
>>> contrib/pg_trgm being this cozy with the innards of regex_t.

>> The only option I see now is to provide a method like "export_cnfa" which
>> would export corresponding CNFA in fixed format.

> Yeah, I think that makes sense. The transformation code in trgm_regexp.c
> would probably be more readable too, if it didn't have to deal with the
> regex guts representation of the CNFA. Also, once you have intermediate
> representation of the original CNFA, you could do some of the
> transformation work on that representation, before building the
> "tranformed graph" containing trigrams. You could eliminate any
> non-alphanumeric characters, joining states connected by arcs with
> non-alphanumeric characters, for example.

It's not just the CNFA though; the other big API problem is with mapping
colors back to characters.  Right now, that not only knows way too much
about a part of the regex internals we have ambitions to change soon,
but it also requires pg_wchar2mb_with_len() and lowerstr(), neither of
which should be known to the regex library IMO.  So I'm not sure how we
divvy that up sanely.  To be clear: I'm not going to insist that we have
to have a clean API factorization before we commit this at all.  But it
worries me if we don't even know how we could get to that, because we
are going to need it eventually.

Now I have following idea about API.
Put code of stage 2 (transform the original CNFA into an automaton-like graph) into regex engine. It would use API which describes what exactly are we going to extract from CNFA. This API could look like this.

typedef char *Prefix;
typedef char *ArcLabel;

typedef struct
{
Prefix newPrefix;
ArcLabel label;
} ArcInfo;

typedef struct
{
Prefix (*getInitialPrefix) ();
bool (*prefixContains) (Prefix prefix1, Prefix prefix2);
Prefix * (*getPrefixes) (Prefix prefix, color c, int *n);
ArcInfo * (*getArcs) (Prefix prefix, color c, int *n);
void (*freePrefix) (Prefix prefix);
void (*freeArcLabel) (ArcLabel arcLabel);
} CFNATransformAPI;

getInitialPrefix returns initial prefix value like now this code does:
> initkey.prefix.colors[0] = UNKNOWN_COLOR;
> initkey.prefix.colors[1] = UNKNOWN_COLOR;
prefixContains are exactly same as function with this name.
getPrefixes and getArcs cycle step work of addKeys an addArcs.
freePrefix and freeArcLabel frees used memory of Prefix and ArcLabel strutures.

Additionally regex engine should provide correct way to examine colormap.
int getColorCharsCount(colormap *cm, color c);
pg_wchar *getColorChars(colormap *cm, color c);
getColorCharsCount would return -1 if this color should be considered as unexpandable.

Any thoughts?

------
With best regards,
Alexander Korotkov.

Re: WIP: index support for regexp search

От:
Alexander Korotkov <aekorotkov@gmail.com>
Дата:
On Fri, Jan 20, 2012 at 8:45 PM, Marti Raudsepp <marti@juffo.org> wrote:
On Fri, Jan 20, 2012 at 01:33, Erik Rijkers <er@xs4all.nl> wrote:
> Btw, it seems impossible to Ctrl-C out of a search once it is submitted; I suppose this is
> normally necessary for perfomance reasons, but it would be useful te be able to compile a test
> version that allows it.

I believe being interruptible is a requirement for the patch to be accepted.

CHECK_FOR_INTERRUPTS(); should be added to the indeterminate loops.
Sure. It's easy to fix. But it seems that in this case gin extract_query method becomes slow (because index scan itself is breakable). So, it just shouldn't work so long. 

------
With best regards,
Alexander Korotkov.

Re: WIP: index support for regexp search

От:
Alexander Korotkov <aekorotkov@gmail.com>
Дата:
On Tue, Dec 18, 2012 at 12:51 PM, Erik Rijkers <er@xs4all.nl> wrote:
On Tue, December 18, 2012 09:45, Alexander Korotkov wrote:
>
> You should use {0,n} to express from 0 to n occurences.
>


Thanks, but I know that of course.  It's a testing program; and in the end robustness with
unexpected or even wrong input is as important as performance.  (to put it bluntly, I am also
trying to get your patch to fall over ;-))

I found most of regressions in 0.9 version to be in {,n} cases. New version of patch use more of trigrams than previous versions.
For example for regex 'x[aeiou]{,2}q'.
In 0.7 version we use trigrams '__2', '_2_' and '__q'.
In 0.9 version we use trigrams 'xa_', 'xe_', 'xi_', 'xo_', 'xu_', '__2', '_2_' and '__q'.

But, actually trigram '__2' or '_2_' never occurs. It enough to have one of them, all others are just causing a slowdown. Simultaneously, we can't decide reasonably which trigrams to use without knowing their frequencies. For example, if trigrams 'xa_', 'xe_', 'xi_', 'xo_', 'xu_' were altogether more rare than '__2', newer version of patch would be faster.


------
With best regards,
Alexander Korotkov.

Re: WIP: index support for regexp search

От:
Alexander Korotkov <aekorotkov@gmail.com>
Дата:
On Fri, Jan 20, 2012 at 1:07 AM, Alexander Korotkov <aekorotkov@gmail.com> wrote:
What does last 7 zeros in the first column means? No conversion to pg_wchar is possible from these encodings?
Uh, I see. These encodings is not supported as server encodings. 

------
With best regards,
Alexander Korotkov.

Re: WIP: index support for regexp search

От:
Alexander Korotkov <aekorotkov@gmail.com>
Дата:
Hi!

Some quick answers to the part of notes/issues. I will provide rest of answers soon.

On Wed, Jan 23, 2013 at 6:08 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
The biggest problem is that I really don't care for the idea of
contrib/pg_trgm being this cozy with the innards of regex_t.  Sooner
or later we are going to want to split the regex code off again as a
standalone library, and we *must* have a cleaner division of labor if
that is ever to happen.  Not sure what a suitable API would look like
though.

The only option I see now is to provide a method like "export_cnfa" which would export corresponding CNFA in fixed format.
 
I think the assumption that all MB characters fit in 4 bytes is
unacceptable; someday we'll want to support wider Unicode characters
than we do now, and this code seems utterly unable to handle it.  It's
especially bad that the code isn't even bothering to defend itself
against the possibility of wider characters.

In attached patch I introduce MAX_MULTIBYTE_CHARACTER_LENGTH macro and use it in type definition. Is this way ok? 
 
Can't just modify pg_trgm--1.0.sql in place, must create a "1.1" version
and an upgrade script.

Fixed.
 
Comments and documentation still need a lot of copy-editing, also I
think a lot of the comment blocks will not survive pg_indent.  It'd be
a good idea to run trgm_regexp.c through pg_indent as soon as you have
that fixed.

Fixed.
 
New file trgm_regexp.c lacks a copyright notice

Fixed. 

Calling RE_compile_and_cache with DEFAULT_COLLATION_OID is not good
enough; need to pass through the actual collation for the regex
operator.

We have collation passed to gin_extract_query in ginscan.c. I noticed that gincost_pattern don't pass collation to gin_extract_query. Is it a bug? Anyway this is not collation we need. We need collation used in operator clause. In attached patch I introduce additional argument to gin_extract_query which represent collation of operator clause. Do you think it is reasonable change in GIN interface? If so, I will provide it as separate patch.
 
Not too happy with convertPgWchar: aside from hard-wired, unchecked
assumption about maximum length of pg_wchar2mb_with_len result, why is
it that this is doing a lowercase conversion?  Surely the regex stuff
dealt with that already?

Trigrams are already lowercased. We can simplify our calculations by excluding uppercased characters from consideration. 

------
With best regards,
Alexander Korotkov.

Re: WIP: index support for regexp search

От:
Alexander Korotkov <aekorotkov@gmail.com>
Дата:
On Tue, Nov 20, 2012 at 3:02 AM, Tomas Vondra <tv@fuzzy.cz> wrote:
2) It's common to use upper-case names for macros, but trgm.h defines
   macro "iswordchr" - I see it's moved from trgm_op.c but maybe we
   could make it a bit more correct?

3) I see there are two '#ifdef KEEPONLYALNUM" blocks right next to each
   other in trgm.h - maybe it'd be a good idea to join them?

4) The two new method prototypes at the end of trgm.h use different
   indendation than the rest (spaces only instead of tabs).
These issues are fixed in attached patch.
Additionally 3 new macros are introduced: MAX_RESULT_STATES, MAX_RESULT_ARCS, MAX_RESULT_PATHS. They are limiting resources usage during regex processing.

------
With best regards,
Alexander Korotkov.

Re: WIP: index support for regexp search

От:
Alexander Korotkov <aekorotkov@gmail.com>
Дата:
On Wed, Jan 23, 2013 at 7:29 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Heikki Linnakangas <hlinnakangas@vmware.com> writes:
> On 23.01.2013 09:36, Alexander Korotkov wrote:
>> On Wed, Jan 23, 2013 at 6:08 AM, Tom Lane<tgl@sss.pgh.pa.us>  wrote:
>>> The biggest problem is that I really don't care for the idea of
>>> contrib/pg_trgm being this cozy with the innards of regex_t.

>> The only option I see now is to provide a method like "export_cnfa" which
>> would export corresponding CNFA in fixed format.

> Yeah, I think that makes sense. The transformation code in trgm_regexp.c
> would probably be more readable too, if it didn't have to deal with the
> regex guts representation of the CNFA. Also, once you have intermediate
> representation of the original CNFA, you could do some of the
> transformation work on that representation, before building the
> "tranformed graph" containing trigrams. You could eliminate any
> non-alphanumeric characters, joining states connected by arcs with
> non-alphanumeric characters, for example.

It's not just the CNFA though; the other big API problem is with mapping
colors back to characters.  Right now, that not only knows way too much
about a part of the regex internals we have ambitions to change soon,
but it also requires pg_wchar2mb_with_len() and lowerstr(), neither of
which should be known to the regex library IMO.  So I'm not sure how we
divvy that up sanely.  To be clear: I'm not going to insist that we have
to have a clean API factorization before we commit this at all.  But it
worries me if we don't even know how we could get to that, because we
are going to need it eventually.

Now, we probably don't have enough of time before 9.3 to solve an API problem :(. It's likely we have to choose either commit to 9.3 without clean API factorization or postpone it to 9.4.

------
With best regards,
Alexander Korotkov. 

Re: WIP: index support for regexp search

От:
Alexander Korotkov <aekorotkov@gmail.com>
Дата:
On Thu, Nov 29, 2012 at 5:25 PM, Heikki Linnakangas <hlinnakangas@vmware.com> wrote:
One thing that bothers me with this algoritm is that the overflow mechanism is all-or-nothing. In many cases, even when there is a huge number of states in the diagram, you could still extract at least a few trigrams that must be present in any matching string, with little effort. At least, it seems like that to a human :-).

For example, consider this:

explain analyze select count(*) from azjunk4 where txt ~ ('^aabaacaadaaeaafaagaahaaiaajaakaalaamaanaaoaapaaqaaraasaataauaavaawaaxaayaazabaabbabcabdabeabfabgabhabiabjabkablabmabnaboabpabqabrabsabtabuabvabwabxabyabzacaacbaccacdaceacfacgachaciacjackaclacmacnacoacpacqacracsactacuacvacwacxacyaczadaadbadcaddadeadfadgadhadiadjadkadladmadnadoadpadqadradsadtaduadvadwadxadyadzaeaaebaecaedaeeaefaegaehaeiaejaekaelaemaenaeoaepaeqaeraesaetaeuaevaewaexaeyaezafaafbafcafdafeaffafgafhafiafjafkaflafmafnafoafpafqafrafsaftafuafvafwafxafyafzagaagbagcagdageagfaggaghagiagjagkaglagmagnagoagpagqagragsagtaguagvagwagxagyagzahaahbahcahdaheahfahgahhahiahjahkahlahmahnahoahpahqahrahs$');

you get a query plan like this (the long regexp string edited out):

 Aggregate  (cost=228148.02..228148.03 rows=1 width=0) (actual time=131.100..131
.101 rows=1 loops=1)
   ->  Bitmap Heap Scan on azjunk4  (cost=228144.01..228148.02 rows=1 width=0) (
actual time=131.096..131.096 rows=0 loops=1)
         Recheck Cond: (txt ~ <ridiculously long regexp>)
         Rows Removed by Index Recheck: 10000
         ->  Bitmap Index Scan on azjunk4_trgmrgx_txt_01_idx (cost=0.00..228144
.01 rows=1 width=0) (actual time=82.914..82.914 rows=10000 loops=1)
               Index Cond: (txt ~ <ridiculously long regexp>)
 Total runtime: 131.230 ms
(7 rows)

That ridiculously long string exceeds the number of states (I think, could be number of paths or arcs too), and the algorithm gives up, resorting to scanning the whole index as can be seen by the "Rows Removed by Index Recheck" line. However, it's easy to see that any matching string must contain *any* of the possible trigrams the algorithm extracts. If it could safely return just a few of them, say "aab" and "abz", and discard the rest, that would already be much better than a full index scan.

Would it be safe to simply stop short the depth-first search on overflow, and proceed with the graph that was constructed up to that point?

For depth-first it's not. But your proposal naturally makes sense. I've changed it to breadth-first search. And then it's safe to mark all unprocessed states as final when overflow. It means that we assume every unprocessed branch to immediately finish with matching (this can give us more false positives but no false negatives).
For overflow of matrix collection, it's safe to do just OR between all the trigrams.
New version of patch is attached.

------
With best regards,
Alexander Korotkov.

Re: WIP: index support for regexp search

От:
Alexander Korotkov <aekorotkov@gmail.com>
Дата:
I found you committed GiST index implementation. That's cool.
I found an easy way to optimize it. We can also use trigramsMatchGraph for signatures. Attached patch contains implementation.
Simple example in order to demonstrate it:

Before the patch:

test=# explain (analyze, buffers) select * from words where s ~ '[abc]def';
                                                        QUERY PLAN                                  
                      
--------------------------------------------------------------------------------------------------------------------------
 Bitmap Heap Scan on words  (cost=4.36..40.24 rows=10 width=9) (actual time=17.189..17.193 rows=3 loops=1)
   Recheck Cond: (s ~ '[abc]def'::text)
   Buffers: shared hit=858
   ->  Bitmap Index Scan on words_trgm_idx  (cost=0.00..4.36 rows=10 width=0) (actual time=17.172..17.172 rows=3 loops=1)
         Index Cond: (s ~ '[abc]def'::text)
         Buffers: shared hit=857
 Total runtime: 17.224 ms
(7 rows)

After the patch:

test=# explain (analyze, buffers) select * from words where s ~ '[abc]def';
                                                        QUERY PLAN                                  
                      
--------------------------------------------------------------------------------------------------------------------------
 Bitmap Heap Scan on words  (cost=4.36..40.24 rows=10 width=9) (actual time=13.718..13.721 rows=3 loops=1)
   Recheck Cond: (s ~ '[abc]def'::text)
   Buffers: shared hit=498
   ->  Bitmap Index Scan on words_trgm_idx  (cost=0.00..4.36 rows=10 width=0) (actual time=13.701..13.701 rows=3 loops=1)
         Index Cond: (s ~ '[abc]def'::text)
         Buffers: shared hit=497
 Total runtime: 13.786 ms
(7 rows)


------
With best regards,
Alexander Korotkov.

Re: WIP: index support for regexp search

От:
Alexander Korotkov <aekorotkov@gmail.com>
Дата:
On Thu, Mar 14, 2013 at 9:40 PM, Alexander Korotkov <aekorotkov@gmail.com> wrote:
On Wed, Jan 23, 2013 at 7:29 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Heikki Linnakangas <hlinnakangas@vmware.com> writes:
> On 23.01.2013 09:36, Alexander Korotkov wrote:
>> On Wed, Jan 23, 2013 at 6:08 AM, Tom Lane<tgl@sss.pgh.pa.us>  wrote:
>>> The biggest problem is that I really don't care for the idea of
>>> contrib/pg_trgm being this cozy with the innards of regex_t.

>> The only option I see now is to provide a method like "export_cnfa" which
>> would export corresponding CNFA in fixed format.

> Yeah, I think that makes sense. The transformation code in trgm_regexp.c
> would probably be more readable too, if it didn't have to deal with the
> regex guts representation of the CNFA. Also, once you have intermediate
> representation of the original CNFA, you could do some of the
> transformation work on that representation, before building the
> "tranformed graph" containing trigrams. You could eliminate any
> non-alphanumeric characters, joining states connected by arcs with
> non-alphanumeric characters, for example.

It's not just the CNFA though; the other big API problem is with mapping
colors back to characters.  Right now, that not only knows way too much
about a part of the regex internals we have ambitions to change soon,
but it also requires pg_wchar2mb_with_len() and lowerstr(), neither of
which should be known to the regex library IMO.  So I'm not sure how we
divvy that up sanely.  To be clear: I'm not going to insist that we have
to have a clean API factorization before we commit this at all.  But it
worries me if we don't even know how we could get to that, because we
are going to need it eventually.

Now I have following idea about API.
Put code of stage 2 (transform the original CNFA into an automaton-like graph) into regex engine. It would use API which describes what exactly are we going to extract from CNFA. This API could look like this.

typedef char *Prefix;
typedef char *ArcLabel;

typedef struct
{
Prefix newPrefix;
ArcLabel label;
} ArcInfo;

typedef struct
{
Prefix (*getInitialPrefix) ();
bool (*prefixContains) (Prefix prefix1, Prefix prefix2);
Prefix * (*getPrefixes) (Prefix prefix, color c, int *n);
ArcInfo * (*getArcs) (Prefix prefix, color c, int *n);
void (*freePrefix) (Prefix prefix);
void (*freeArcLabel) (ArcLabel arcLabel);
} CFNATransformAPI;

getInitialPrefix returns initial prefix value like now this code does:
> initkey.prefix.colors[0] = UNKNOWN_COLOR;
> initkey.prefix.colors[1] = UNKNOWN_COLOR;
prefixContains are exactly same as function with this name.
getPrefixes and getArcs cycle step work of addKeys an addArcs.
freePrefix and freeArcLabel frees used memory of Prefix and ArcLabel strutures.

Additionally regex engine should provide correct way to examine colormap.
int getColorCharsCount(colormap *cm, color c);
pg_wchar *getColorChars(colormap *cm, color c);
getColorCharsCount would return -1 if this color should be considered as unexpandable.

Now I have working implemetation of this API. Comments still need rework. Could you give me any feedback?

------
With best regards,
Alexander Korotkov.

Re: WIP: index support for regexp search

От:
Alexander Korotkov <aekorotkov@gmail.com>
Дата:
On Tue, Apr 9, 2013 at 9:15 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Alexander Korotkov <aekorotkov@gmail.com> writes:
> On Mon, Apr 8, 2013 at 9:28 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> I spent the weekend hacking on this, making a number of bug fixes and a
>> whole lot of cosmetic changes.  I think there are large parts of this
>> that are in committable shape now, but I still find the actual graph
>> transformation logic to be mostly unintelligible.  I think what's most
>> obscure is the distinction between the arcs list and the keys list of
>> each state in the expanded graph.  I get the impression that the
>> general idea is for the arcs to represent exactly-known transitions
>> while the keys represent imprecisely-known transitions ... but there
>> seems to be at least some leakage between those categories.  Could
>> you write down a specification for what's supposed to be happening
>> there?

> Here is my try to specify it.

Thanks.  I hacked on this some more and committed it.  I found a number
of bugs along the way with respect to handling of word boundaries
(partially-blank transition trigrams) and EOL-color ($) handling.
I think it's all fixed now but it could definitely use some more
study and testing.
 
Great, thanks! I also will do some more testing.

One issue that bothered me is that the regression tests really don't
provide much visibility into what the code is doing.  Some of the bugs
had to do with failing to generate expected trigrams, for instance
col ~ 'foo bar' only generating trigram "foo" and not "bar".  This still
led to getting the right answer, so the error was invisible as far as the
tests were concerned.  Is it worth thinking of a way to expose what the
extract function did at SQL level, so we could test more carefully?

Yes, I also had similar idea. But, I think we need some relatively stable representation of resulting graph in order to expose it. There could be a lot of equivalent graphs. Some changes in implementation could lead to change from one equivalent graph to another. It would be better to not rewrite tests in this case. Ideally, we should expose some representation which is the same for all equivalent graphs. However, it doesn't seem to be realistic. But, I think we could at least make it stable to order sequence of states and color trigrams. Another option I see is to expose just set of trigrams. It doesn't have completeness of information, but it is quite stable.

------
With best regards,
Alexander Korotkov.

Re: WIP: index support for regexp search

От:
Alexander Korotkov <aekorotkov@gmail.com>
Дата:
On Sun, Jan 27, 2013 at 10:40 PM, Alexander Korotkov <aekorotkov@gmail.com> wrote:
Now I'm working on additional comments.

Some comments were added for addKey and addArc(s). I hope they clarify something.

------
With best regards,
Alexander Korotkov.

Re: WIP: index support for regexp search

От:
Alexander Korotkov <aekorotkov@gmail.com>
Дата:
On Sat, Dec 1, 2012 at 3:22 PM, Erik Rijkers <er@xs4all.nl> wrote:
On Fri, November 30, 2012 12:22, Alexander Korotkov wrote:
> Hi!
>
> On Thu, Nov 29, 2012 at 12:58 PM, er <er@xs4all.nl> wrote:
>
>> On Mon, November 26, 2012 20:49, Alexander Korotkov wrote:
>>
>>
>> I ran the simple-minded tests against generated data (similar to the ones
>> I did in January 2012).
>> The problems of that older version seem pretty much all removed. (although
>> I didn't do much work
>> on it -- just reran these tests).
>>
>
> Thanks a lot for testing! Could you repeat for 0.7 version of patch which
> has new overflow handling?
>

I've attached a similar test re-run that compares HEAD with patch versions 0.6, and 0.7.

Thanks! Did you write scripts for automated testing? I would be nice if you share them.

------
With best regards,
Alexander Korotkov.

WIP: index support for regexp search

От:
Alexander Korotkov <aekorotkov@gmail.com>
Дата:
Hackers,

WIP patch with index support for regexp search for pg_trgm contrib is attached.
In spite of techniques which extracts continuous text parts from regexp, this patch presents technique of automatum transformation. That allows more comprehensive trigrams extraction.

A little example of possible perfomance benefit.

test=# explain analyze select * from words where s ~ 'a[bc]+[de]';
                                              QUERY PLAN                                            
   
----------------------------------------------------------------------------------------------------
---
 Seq Scan on words  (cost=0.00..1703.11 rows=10 width=9) (actual time=3.092..242.303 rows=662 loops=1)
   Filter: (s ~ 'a[bc]+[de]'::text)
   Rows Removed by Filter: 97907
 Total runtime: 243.213 ms
(4 rows)

test=# explain analyze select * from words where s ~ 'a[bc]+[de]';
                                                         QUERY PLAN                                 
                        
----------------------------------------------------------------------------------------------------------------------------
 Bitmap Heap Scan on words  (cost=260.08..295.83 rows=10 width=9) (actual time=4.166..7.506 rows=662 loops=1)
   Recheck Cond: (s ~ 'a[bc]+[de]'::text)
   Rows Removed by Index Recheck: 18
   ->  Bitmap Index Scan on words_trgm_idx  (cost=0.00..260.07 rows=10 width=0) (actual time=4.076..4.076 rows=680 loops=1)
         Index Cond: (s ~ 'a[bc]+[de]'::text)
 Total runtime: 8.424 ms
(6 rows)

Current version of patch have some limitations:
1) Algorithm of logical expression extraction on trigrams have high computational complexity. So, it can become really slow on regexp with many branches. Probably, improvements of this algorithm is possible.
2) Surely, no perfomance benefit if no trigrams can be extracted from regexp. It's inevitably.
3) Currently, only GIN index is supported. There are no serious problems, GiST code for it just not written yet.
4) It appear to be some kind of problem to extract multibyte encoded character from pg_wchar. I've posted question about it here:
While I've hardcoded some dirty solution. So PG_EUC_JP, PG_EUC_CN, PG_EUC_KR, PG_EUC_TW, PG_EUC_JIS_2004 are not supported yet.

------
With best regards,
Alexander Korotkov.

Re: WIP: index support for regexp search

От:
Alexander Korotkov <aekorotkov@gmail.com>
Дата:
Hi!

New version of patch is attached. Changes are following:
1) Right way to convert from pg_wchar to multibyte.
2) Optimization of producing CFNA-like graph on trigrams (produce smaller, but equivalent, graphs in less time).
3) Comments and refactoring.

------
With best regards,
Alexander Korotkov.

Re: WIP: index support for regexp search

От:
Alexander Korotkov <aekorotkov@gmail.com>
Дата:
On Wed, Apr 3, 2013 at 12:36 AM, Erikjan Rijkers <er@xs4all.nl> wrote:
On Mon, April 1, 2013 23:15, Alexander Korotkov wrote:

[trgm-regexp-0.14.patch.gz]

Hi Alexander,

Hi Erik!
 
Something went wrong in this version of the patch: many (most) queries that were earlier
spectacularly fast have become slow, often slower than a seqscan or only marginally faster. See
the attached numbers; it compares head(seqscan) with trgm-regex patch versions 13 and 14.

I did not even complete the test-run because version 14 is so clearly inferior to 13 (and earlier,
as far as I can remember).

(let me know if you want the whole result, I can run it overnight)

Yes, there was bug in new color map scan implementation. It was fixed in attached version. Could you re-run tests please?
Attached version of patch also addresses problem that we now using API it's not correct to use special values of color number. It introduces additional structure ExtendedColor which contain ExtendedColorClass field for handling additional "virtual" colors introduced by analysis.

------
With best regards,
Alexander Korotkov.

Re: WIP: index support for regexp search

От:
Alexander Korotkov <aekorotkov@gmail.com>
Дата:
On Mon, Dec 3, 2012 at 4:31 PM, Alexander Korotkov <aekorotkov@gmail.com> wrote:
Actually, I generally dislike path matrix for same reasons. But:
1) Output graphs could contain trigrams which are completely useless for search. For example, for regex /(abcdefgh)*ijk/ we need only "ijk" trigram while graph would contain much more.Path matrix is a method to get rid of all of them.
2) If we use color trigrams then we need some criteria for which color trigrams to expand into trigrams. Simultaneously, we shouldn't allow path from initial state to the final by unexpanded trigrams. It seems much harder to do with graph than with matrix.

Now, I have an idea about doing some not comprehensive but simple and fast simplification of graph. I'm doing experiments now. In case of success we could get rid of path matrix.

------
With best regards,
Alexander Korotkov.

Re: WIP: index support for regexp search

От:
Alexander Korotkov <aekorotkov@gmail.com>
Дата:
On Mon, Mar 25, 2013 at 2:38 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Alexander Korotkov <aekorotkov@gmail.com> writes:
> On Mon, Mar 25, 2013 at 1:50 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> Similarly, pushing PG-specific declarations like RE_compile_and_cache()
>> into regex/regex.h is completely not the right thing for preserving a
>> clear library boundary (even positing that we want to expose that
>> function outside adt/regexp.c, which I'd rather we didn't).
>>
>> Perhaps we could avoid these issues by defining a library API that
>> provides accessors like these for the opaque regex_t struct:
>>
>> * get the number of states in the CNFA
>>
>> * get the numbers of the initial and final states
>>
>> * get the number of out-arcs for the N'th state
>>
>> * get the out-arcs for the N'th state into a caller-provided array
>> (sized using the previous function), where each out-arc is represented
>> by a color and an end-state
>>
>> * get the number of character codes represented by color C
>>
>> * get the wchar codes for color C into a caller-provided array
>>
>> (The reason for letting the caller allocate the result arrays is so we
>> can use palloc for that; if we allocate it in backend/regex/ we must
>> use malloc, which will greatly increase the risk of leakages.  Also,
>> as far as the color API goes, the above lets the caller decide how
>> many characters is "too many" to bother with.)

> I like the this idea. Seems like clear and not over-engineered API. I can
> implement it. Could you propose something particular to do with
> RE_compile_and_cache in this patch? With this API we still need a way to
> get regex_t or equivalent from string.

Well, the brute force answer is for pg_trgm to not go through
RE_compile_and_cache at all, but just call the regex library for itself.
That would lose the ability to cache regex compilations, but I'm not
sure we care.  The motivation for RE_compile_and_cache is mainly to
prevent having to compile the regex again for *every row*, which is what
would otherwise happen in a simple SELECT using a regex function.
Unless I'm misunderstanding something, pg_trgm would only need to
compile the regex once per indexscan, which is probably tolerable.

For me it makes sense.
Patch with proposed API implementation is attached.

------
With best regards,
Alexander Korotkov.

Re: WIP: index support for regexp search

От:
Alexander Korotkov <aekorotkov@gmail.com>
Дата:
I also have a question about pg_wchar.

/*
 *-------------------------------------------------------------------
 * encoding info table
 * XXX must be sorted by the same order as enum pg_enc (in mb/pg_wchar.h)
 *-------------------------------------------------------------------
 */
pg_wchar_tbl pg_wchar_table[] = {
{pg_ascii2wchar_with_len, pg_ascii_mblen, pg_ascii_dsplen, pg_ascii_verifier, 1}, /* PG_SQL_ASCII */
{pg_eucjp2wchar_with_len, pg_eucjp_mblen, pg_eucjp_dsplen, pg_eucjp_verifier, 3}, /* PG_EUC_JP */
{pg_euccn2wchar_with_len, pg_euccn_mblen, pg_euccn_dsplen, pg_euccn_verifier, 2}, /* PG_EUC_CN */
{pg_euckr2wchar_with_len, pg_euckr_mblen, pg_euckr_dsplen, pg_euckr_verifier, 3}, /* PG_EUC_KR */
{pg_euctw2wchar_with_len, pg_euctw_mblen, pg_euctw_dsplen, pg_euctw_verifier, 4}, /* PG_EUC_TW */
{pg_eucjp2wchar_with_len, pg_eucjp_mblen, pg_eucjp_dsplen, pg_eucjp_verifier, 3}, /* PG_EUC_JIS_2004 */
{pg_utf2wchar_with_len, pg_utf_mblen, pg_utf_dsplen, pg_utf8_verifier, 4}, /* PG_UTF8 */
{pg_mule2wchar_with_len, pg_mule_mblen, pg_mule_dsplen, pg_mule_verifier, 4}, /* PG_MULE_INTERNAL */
{pg_latin12wchar_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifier, 1}, /* PG_LATIN1 */
{pg_latin12wchar_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifier, 1}, /* PG_LATIN2 */
{pg_latin12wchar_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifier, 1}, /* PG_LATIN3 */
{pg_latin12wchar_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifier, 1}, /* PG_LATIN4 */
{pg_latin12wchar_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifier, 1}, /* PG_LATIN5 */
{pg_latin12wchar_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifier, 1}, /* PG_LATIN6 */
{pg_latin12wchar_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifier, 1}, /* PG_LATIN7 */
{pg_latin12wchar_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifier, 1}, /* PG_LATIN8 */
{pg_latin12wchar_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifier, 1}, /* PG_LATIN9 */
{pg_latin12wchar_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifier, 1}, /* PG_LATIN10 */
{pg_latin12wchar_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifier, 1}, /* PG_WIN1256 */
{pg_latin12wchar_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifier, 1}, /* PG_WIN1258 */
{pg_latin12wchar_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifier, 1}, /* PG_WIN866 */
{pg_latin12wchar_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifier, 1}, /* PG_WIN874 */
{pg_latin12wchar_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifier, 1}, /* PG_KOI8R */
{pg_latin12wchar_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifier, 1}, /* PG_WIN1251 */
{pg_latin12wchar_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifier, 1}, /* PG_WIN1252 */
{pg_latin12wchar_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifier, 1}, /* ISO-8859-5 */
{pg_latin12wchar_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifier, 1}, /* ISO-8859-6 */
{pg_latin12wchar_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifier, 1}, /* ISO-8859-7 */
{pg_latin12wchar_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifier, 1}, /* ISO-8859-8 */
{pg_latin12wchar_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifier, 1}, /* PG_WIN1250 */
{pg_latin12wchar_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifier, 1}, /* PG_WIN1253 */
{pg_latin12wchar_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifier, 1}, /* PG_WIN1254 */
{pg_latin12wchar_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifier, 1}, /* PG_WIN1255 */
{pg_latin12wchar_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifier, 1}, /* PG_WIN1257 */
{pg_latin12wchar_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifier, 1}, /* PG_KOI8U */
{0, pg_sjis_mblen, pg_sjis_dsplen, pg_sjis_verifier, 2}, /* PG_SJIS */
{0, pg_big5_mblen, pg_big5_dsplen, pg_big5_verifier, 2}, /* PG_BIG5 */
{0, pg_gbk_mblen, pg_gbk_dsplen, pg_gbk_verifier, 2}, /* PG_GBK */
{0, pg_uhc_mblen, pg_uhc_dsplen, pg_uhc_verifier, 2}, /* PG_UHC */
{0, pg_gb18030_mblen, pg_gb18030_dsplen, pg_gb18030_verifier, 4}, /* PG_GB18030 */
{0, pg_johab_mblen, pg_johab_dsplen, pg_johab_verifier, 3}, /* PG_JOHAB */
{0, pg_sjis_mblen, pg_sjis_dsplen, pg_sjis_verifier, 2} /* PG_SHIFT_JIS_2004 */
};

What does last 7 zeros in the first column means? No conversion to pg_wchar is possible from these encodings?

------
With best regards,
Alexander Korotkov.

Re: WIP: index support for regexp search

От:
Alexander Korotkov <aekorotkov@gmail.com>
Дата:

On Fri, Jan 25, 2013 at 11:47 AM, Erik Rijkers <er@xs4all.nl> wrote:
On Wed, January 23, 2013 08:36, Alexander Korotkov wrote:
> Hi!
>
> Some quick answers to the part of notes/issues. I will provide rest of
> answers soon.
>
[...]
> trgm-regexp-0.10.patch.gz    27 k

Trying to build this I get, after 'make install' in contrib/ :

/usr/bin/install: cannot stat `./pg_trgm--1.1.sql': No such file or directory
/usr/bin/install: cannot stat `./pg_trgm--1.0--1.1.sql': No such file or directory
make[1]: *** [install] Error 1
make: *** [install-pg_trgm-recurse] Error 2

Forgot to include these files into patch.

Another changes in new version of patch:
1) Get rid of recursion in trigramsMatchGraph and addKeys.
2) Both bos[0] and eos[0] are also included into checks.
3) Get rid of strnlen.
4) I found the way to fix work with collation in previous version of patch to be wrong. Collation of operator must match collation of indexed column for index scan. Only thing to fix is passing collation in gincost_pattern.
5) Some tests were added which improves the coverage.

Now I'm working on additional comments.

------
With best regards,
Alexander Korotkov.

Re: WIP: index support for regexp search

От:
Alexander Korotkov <aekorotkov@gmail.com>
Дата:
On Fri, Jan 20, 2012 at 12:54 AM, Alexander Korotkov <aekorotkov@gmail.com> wrote:
On Fri, Jan 20, 2012 at 12:30 AM, Heikki Linnakangas <heikki.linnakangas@enterprisedb.com> wrote:
Apart from that, the multibyte issue seems like the big one. Any way around that?
Conversion of pg_wchar to multibyte character is the only way I found to avoid serious hacking of existing regexp code. Do you think additional function in pg_wchar_tbl which converts pg_wchar back to multibyte character is possible solution?
Do you have any notes on it? I could make the patch which adds such function into core.

------
With best regards,
Alexander Korotkov.

Re: WIP: index support for regexp search

От:
Alexander Korotkov <aekorotkov@gmail.com>
Дата:
Hi!

Thank you for your feedback!

On Fri, Jan 20, 2012 at 3:33 AM, Erik Rijkers <er@xs4all.nl> wrote:
The patch yields spectacular speedups with small, simple-enough regexen.  But it does not do a
good enough job when guessing where to use the index and where fall back to Seq Scan.  This can
lead to (also spectacular) slow-downs, compared to Seq Scan.
Could you give some examples of regexes where index scan becomes slower than seq scan?
 
I guessed that MAX_COLOR_CHARS limits the character class size (to 4, in your patch), is that
true?   I can understand you want that value to be low to limit the above risk, but now it reduces
the usability of the feature a bit: one has to split up larger char-classes into several smaller
ones to make a statement use the index: i.e.:
Yes, MAX_COLOR_CHARS is number of maximum character in automata color when that color is divided to a separated characters. And it's likely there could be better solution than just have this hard limit.
 
Btw, it seems impossible to Ctrl-C out of a search once it is submitted; I suppose this is
normally necessary for perfomance reasons, but it would be useful te be able to compile a test
version that allows it.  I don't know how hard that would be.
I seems that Ctrl-C was impossible because procedure of trigrams exctraction becomes so long while it is not breakable. It's not difficult to make this procedure breakable, but actually it just shouldn't take so long.
 
There is also a minor bug, I think, when running with  'set enable_seqscan=off'  in combination
with a too-large regex:
Thanks for pointing. Will be fixed.

------
With best regards,
Alexander Korotkov.

Re: WIP: index support for regexp search

От:
Alexander Korotkov <aekorotkov@gmail.com>
Дата:
On Mon, Apr 8, 2013 at 9:28 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Alexander Korotkov <aekorotkov@gmail.com> writes:
> [ trgm-regexp-0.15.patch.gz ]

I spent the weekend hacking on this, making a number of bug fixes and a
whole lot of cosmetic changes.  I think there are large parts of this
that are in committable shape now, but I still find the actual graph
transformation logic to be mostly unintelligible.  I think what's most
obscure is the distinction between the arcs list and the keys list of
each state in the expanded graph.  I get the impression that the
general idea is for the arcs to represent exactly-known transitions
while the keys represent imprecisely-known transitions ... but there
seems to be at least some leakage between those categories.  Could
you write down a specification for what's supposed to be happening
there?

Here is my try to specify it.
At first some notions. I know, they are already in the comments, but just in order to put it together.

Extended color - any color of source CNFA or one of two special values:
1) Unknown color - may represent any character either alphanumeric or non-alphanumeric.
2) Blank color - may represent any non-alphanumeric character
Prefix is extended colors of last two characters read by CNFA.
Key is pair of CNFA state and prefix. So, key is a extended state which is containing additional information which can influence further trigrams.

So, if you are in some key and traverse some CNFA arc then you moves info another key. But there are two possible cases (or, sometimes, both of them):
1) Your move from one key into another necessary means read of some trigram. Then you create new arc labeled with that trigram.
2) You move into another key, but you doesn't necessary read an useful trigram. For example, arc of source CNFA is labeled by "unextractable" color. Then you add new key into "keys" array. And outgoing arcs from this key will also be processed similarly to source key. Therefore "keys" array is a set of keys which are achievable from "stateKey" without reading of useful trigram.
We could get rid of "keys" array and produce some "empty arcs" in the second case. You can imagine that "keys" array is set of keys which are achivable by "empty arcs" from "stateKey". States connected with "empty arcs" could be merged on the next stage.
However, the reason of having separated addKeys stage is optimization. In addKey function more generals keys absorb less general ones. In many cases resulting graph becomes much simplier because of this. For example, if your regex is not prefix, then engine puts self-referencing arcs of all possible colors to initial state. Straight-forward processing of this could produce enormous output graph. I had similar situation in early version of patch where keys didn't absorb earch other. 

------
With best regards,
Alexander Korotkov.

Re: WIP: index support for regexp search

От:
Alexander Korotkov <aekorotkov@gmail.com>
Дата:
Hi!

On Thu, Nov 29, 2012 at 12:58 PM, er <er@xs4all.nl> wrote:
On Mon, November 26, 2012 20:49, Alexander Korotkov wrote:

> trgm-regexp-0.6.patch.gz

I ran the simple-minded tests against generated data (similar to the ones I did in January 2012).
The problems of that older version seem pretty much all removed. (although I didn't do much work
on it -- just reran these tests).

Thanks a lot for testing! Could you repeat for 0.7 version of patch which has new overflow handling?

------
With best regards,
Alexander Korotkov.

Re: WIP: index support for regexp search

От:
Alexander Korotkov <aekorotkov@gmail.com>
Дата:
On Mon, Dec 17, 2012 at 1:16 PM, Alexander Korotkov <aekorotkov@gmail.com> wrote:
Didn't reproduce it yet. Can you retry it with this line uncommented:
#define TRGM_REGEXP_DEBUG
Then we can see which stage it fails.

Bug is found and fixed in attached patch.

------
With best regards,
Alexander Korotkov.

Re: WIP: index support for regexp search

От:
Alexander Korotkov <aekorotkov@gmail.com>
Дата:
Some quick comments.

On Tue, Nov 20, 2012 at 3:02 AM, Tomas Vondra <tv@fuzzy.cz> wrote:
6) It does not compile - I do get a bunch of errors like this
Fixed. 

7) Once fixed, it seems to work

CREATE EXTENSION pg_trgm ;
CREATE TABLE TEST (val TEXT);
INSERT INTO test
       SELECT md5(i::text) FROM generate_series(1,1000000) s(i);
CREATE INDEX trgm_idx ON test USING gin (val gin_trgm_ops);
ANALYZE test;

EXPLAIN SELECT * FROM test WHERE val ~ '.*qqq.*';


                           QUERY PLAN
---------------------------------------------------------------------
 Bitmap Heap Scan on test  (cost=16.77..385.16 rows=100 width=33)
   Recheck Cond: (val ~ '.*qqq.*'::text)
   ->  Bitmap Index Scan on trgm_idx  (cost=0.00..16.75 rows=100
                                       width=0)
         Index Cond: (val ~ '.*qqq.*'::text)
(4 rows)

but I do get a bunch of NOTICE messages with debugging info (no matter
if the GIN index is used or not, so it's somewhere in the common regexp
code). But I guess that's due to WIP status.
It's due to TRGM_REGEXP_DEBUG macro. I disabled it by default. But I think pieces of code hidden by that macro could be useful for debug even after WIP status.

------
With best regards,
Alexander Korotkov.

Re: WIP: index support for regexp search

От:
Alexander Korotkov <aekorotkov@gmail.com>
Дата:
On Fri, Jan 20, 2012 at 12:30 AM, Heikki Linnakangas <heikki.linnakangas@enterprisedb.com> wrote:
The code badly needs comments. There is no explanation of how the trigram extraction code in trgm_regexp.c works.
Sure. I hoped to find a time for comments before commitfest starts. Unfortunately I didn't, sorry.
 
Guessing from the variable names, it seems to be some sort of a coloring algorithm that works on a graph, but that all needs to be explained. Can this algorithm be found somewhere in literature, perhaps? A link to a paper would be nice.
I hope it's truly novel. At least application to regular expressions. I'm going to write a paper about it.
 
Apart from that, the multibyte issue seems like the big one. Any way around that?
Conversion of pg_wchar to multibyte character is the only way I found to avoid serious hacking of existing regexp code. Do you think additional function in pg_wchar_tbl which converts pg_wchar back to multibyte character is possible solution?

------
With best regards,
Alexander Korotkov.

Re: WIP: index support for regexp search

От:
Alexander Korotkov <aekorotkov@gmail.com>
Дата:
On Mon, Nov 26, 2012 at 4:55 PM, Heikki Linnakangas <hlinnakangas@vmware.com> wrote:
Great, that top-level comment helped tremendously! I feel enlightened.

I fixed some spelling, formatting etc. trivial stuff while reading through the patch, see attached. Below is some feedback on the details:

* I don't like the PG_TRY/CATCH trick. It's not generally safe to catch an error, without propagating it further or rolling back the whole (sub)transation. It might work in this case, as you're only suppressing errors with the special sqlcode that are used in the same file, but it nevertheless feels naughty. I believe none of the limits that are being checked are strict; it's OK to exceed the limits somewhat, as long as you terminate the processing in a reasonable time, in case of pathological input. I'd suggest putting an explicit check for the limits somewhere, and not rely on ereport(). Something like this, in the code that recurses:

if (trgmCNFA->arcsCount > MAX_RESULT_ARCS ||
    hash_get_num_entries(trgmCNFA->states) > MAX_RESULT_STATES)
{
        trgmCNFA->overflowed = true;
        return;
}

PG_TRY/CATCH trick is replaced with some number of if/return. Code becomes a bit more complicated, but your notes does matter.

And then check for the overflowed flag at the top level.

* This part of the high-level comment was not clear to me:

 * States of the graph produced in the first stage are marked with "keys". Key is a pair
 * of a "prefix" and a state of the original automaton. "Prefix" is a last
 * characters. So, knowing the prefix is enough to know what is a trigram when we read some new
 * character. However, we can know single character of prefix or don't know any
 * characters of it. Each state of resulting graph have an "enter key" (with that
 * key we've entered this state) and a set of keys which are reachable without
 * reading any predictable trigram. The algorithm of processing each state
 * of resulting graph are so:
 * 1) Add all keys which achievable without reading of any predictable trigram.
 * 2) Add outgoing arcs labeled with trigrams.
 * Step 2 leads to creation of new states and recursively processing them. So,
 * we use depth-first algorithm.

I didn't understand that. Can you elaborate? It might help to work through an example, with some ascii art depicting the graph.

This comment is extended with example.
 
* It would be nice to add some comments to TrgmCNFA struct, explaining which fields are valid at which stages. For example, it seems that 'trgms' array is calculated only after building the CNFA, by getTrgmVector() function, while arcsCount is updated on the fly, while recursing in the getState() function.

TrgmCNFA comment is extended with this. 
 
* What is the representation used for the path matrix? Needs a comment.

Comments are added to PackedTrgmPaths and TrgmStatePath.
 
* What do the getColorinfo()
 
getColorInfo comment now references to ColorInfo struct which have comment. 

and scanColorMap() functions do?

 scanColorMap comment now have description of colormap structure.
 
What exactly does a color represent?

This is added to the top comment.
 
What's the tradeoff in choosing MAX_COLOR_CHARS?
 
Comment is added to the macro.

------
With best regards,
Alexander Korotkov.

Re: WIP: index support for regexp search

От:
Alexander Korotkov <aekorotkov@gmail.com>
Дата:
Hi!

On Wed, Nov 21, 2012 at 12:51 AM, Pavel Stehule <pavel.stehule@gmail.com> wrote:
do you plan to support GiST?

At first, I would note that pg_trgm GiST opclass is quite ridiculous for support regex search (and, actually for LIKE/ILIKE search which is already implemented too). Because in GiST opclass we store set of trigrams in leaf pages. In was designed for trigram similarity search and have sense for it because of elimination of trigram set computation. But for regex or LIKE/ILIKE search this representation is both lossy and bigger than just original string. Probably we could think about another opclass for GiST focusing on regex and LIKE/ILIKE search?

However, amyway I can create additional patch for current GiST opclass.

------
With best regards,
Alexander Korotkov.

Re: WIP: index support for regexp search

От:
"Erik Rijkers" <er@xs4all.nl>
Дата:

Re: WIP: index support for regexp search

От:
"Erik Rijkers" <er@xs4all.nl>
Дата:

Re: WIP: index support for regexp search

От:
"er" <er@xs4all.nl>
Дата:
FAQ