Improve contrib/pg_trgm's heuristics for regexp index searches.
Improve contrib/pg_trgm's heuristics for regexp index searches.

When extracting trigrams from a regular expression for search of a GIN or
GIST trigram index, it's useful to penalize (preferentially discard)
trigrams that contain whitespace, since those are typically far more common
in the index than trigrams not containing whitespace.  Of course, this
should only be a preference not a hard rule, since we might otherwise end
up with no trigrams to search for.  The previous coding tended to produce
fairly inefficient trigram search sets for anchored regexp patterns, as
reported by Erik Rijkers.  This patch penalizes whitespace-containing
trigrams, and also reduces the target number of extracted trigrams, since
experience suggests that the original coding tended to select too many
trigrams to search for.

Alexander Korotkov, reviewed by Tom Lane

50wu/gpdb,jmcatamney/gpdb,techdragon/Postgres-XL,ovr/postgres-xl,xinzweb/gpdb,zeroae/postgres-xl,jmcatamney/gpdb,jmcatamney/gpdb,lisakowen/gpdb,ashwinstar/gpdb,zeroae/postgres-xl,lisakowen/gpdb,oberstet/postgres-xl,adam8157/gpdb,Postgres-XL/Postgres-XL,yazun/postgres-xl,zeroae/postgres-xl,pavanvd/postgres-xl,lisakowen/gpdb,lisakowen/gpdb,jmcatamney/gpdb,lisakowen/gpdb,jmcatamney/gpdb,ashwinstar/gpdb,50wu/gpdb,adam8157/gpdb,50wu/gpdb,techdragon/Postgres-XL,greenplum-db/gpdb,greenplum-db/gpdb,adam8157/gpdb,pavanvd/postgres-xl,50wu/gpdb,xinzweb/gpdb,ovr/postgres-xl,jmcatamney/gpdb,xinzweb/gpdb,oberstet/postgres-xl,xinzweb/gpdb,ashwinstar/gpdb,Postgres-XL/Postgres-XL,Postgres-XL/Postgres-XL,greenplum-db/gpdb,adam8157/gpdb,yazun/postgres-xl,xinzweb/gpdb,techdragon/Postgres-XL,50wu/gpdb,pavanvd/postgres-xl,adam8157/gpdb,ovr/postgres-xl,oberstet/postgres-xl,yazun/postgres-xl,yazun/postgres-xl,ashwinstar/gpdb,xinzweb/gpdb,techdragon/Postgres-XL,lisakowen/gpdb,greenplum-db/gpdb,oberstet/postgres-xl,greenplum-db/gpdb,ovr/postgres-xl,ashwinstar/gpdb,greenplum-db/gpdb,jmcatamney/gpdb,lisakowen/gpdb,ashwinstar/gpdb,50wu/gpdb,greenplum-db/gpdb,xinzweb/gpdb,ovr/postgres-xl,techdragon/Postgres-XL,zeroae/postgres-xl,Postgres-XL/Postgres-XL,pavanvd/postgres-xl,ashwinstar/gpdb,jmcatamney/gpdb,50wu/gpdb,oberstet/postgres-xl,xinzweb/gpdb,ashwinstar/gpdb,adam8157/gpdb,pavanvd/postgres-xl,yazun/postgres-xl,zeroae/postgres-xl,greenplum-db/gpdb,lisakowen/gpdb,50wu/gpdb,Postgres-XL/Postgres-XL,adam8157/gpdb,adam8157/gpdb