Fix string_to_array() to correctly handle the case where there are overlapping possible matches for the separator string, such as string_to_array('123xx456xxx789', 'xx'). Also, revise the logic of replace(), split_part(), and string_to_array() to avoid O(N^2) work from redundant searches and conversions to pg_wchar format when there are N matches to the separator string. Backpatched the full patch as far as 8.0.  7.4 also has the bug, but the code has diverged a lot, so I just went for a quick-and-dirty fix of the bug itself in that branch.
Fix string_to_array() to correctly handle the case where there are
overlapping possible matches for the separator string, such as
string_to_array('123xx456xxx789', 'xx').
Also, revise the logic of replace(), split_part(), and string_to_array()
to avoid O(N^2) work from redundant searches and conversions to pg_wchar
format when there are N matches to the separator string.
Backpatched the full patch as far as 8.0.  7.4 also has the bug, but the
code has diverged a lot, so I just went for a quick-and-dirty fix of the
bug itself in that branch.

lisakowen/gpdb,oberstet/postgres-xl,foyzur/gpdb,greenplum-db/gpdb,xinzweb/gpdb,xuegang/gpdb,rvs/gpdb,pavanvd/postgres-xl,lintzc/gpdb,edespino/gpdb,royc1/gpdb,janebeckman/gpdb,Chibin/gpdb,foyzur/gpdb,greenplum-db/gpdb,lisakowen/gpdb,ashwinstar/gpdb,cjcjameson/gpdb,lisakowen/gpdb,xuegang/gpdb,edespino/gpdb,Postgres-XL/Postgres-XL,rvs/gpdb,xinzweb/gpdb,tangp3/gpdb,0x0FFF/gpdb,chrishajas/gpdb,0x0FFF/gpdb,CraigHarris/gpdb,Quikling/gpdb,zeroae/postgres-xl,greenplum-db/gpdb,arcivanov/postgres-xl,edespino/gpdb,xinzweb/gpdb,kmjungersen/PostgresXL,yuanzhao/gpdb,lpetrov-pivotal/gpdb,xinzweb/gpdb,Chibin/gpdb,tangp3/gpdb,zaksoup/gpdb,0x0FFF/gpdb,atris/gpdb,CraigHarris/gpdb,greenplum-db/gpdb,jmcatamney/gpdb,greenplum-db/gpdb,Quikling/gpdb,cjcjameson/gpdb,0x0FFF/gpdb,Chibin/gpdb,janebeckman/gpdb,Postgres-XL/Postgres-XL,techdragon/Postgres-XL,Quikling/gpdb,rvs/gpdb,randomtask1155/gpdb,kmjungersen/PostgresXL,0x0FFF/gpdb,Postgres-XL/Postgres-XL,janebeckman/gpdb,CraigHarris/gpdb,greenplum-db/gpdb,rvs/gpdb,CraigHarris/gpdb,janebeckman/gpdb,zaksoup/gpdb,xinzweb/gpdb,edespino/gpdb,50wu/gpdb,janebeckman/gpdb,0x0FFF/gpdb,Quikling/gpdb,yuanzhao/gpdb,lisakowen/gpdb,Quikling/gpdb,ahachete/gpdb,kaknikhil/gpdb,tangp3/gpdb,tpostgres-projects/tPostgres,Quikling/gpdb,zeroae/postgres-xl,xuegang/gpdb,rubikloud/gpdb,yuanzhao/gpdb,yazun/postgres-xl,Chibin/gpdb,Quikling/gpdb,adam8157/gpdb,kmjungersen/PostgresXL,cjcjameson/gpdb,Quikling/gpdb,oberstet/postgres-xl,lpetrov-pivotal/gpdb,chrishajas/gpdb,50wu/gpdb,ahachete/gpdb,xuegang/gpdb,foyzur/gpdb,tpostgres-projects/tPostgres,atris/gpdb,pavanvd/postgres-xl,edespino/gpdb,foyzur/gpdb,rubikloud/gpdb,postmind-net/postgres-xl,zeroae/postgres-xl,atris/gpdb,chrishajas/gpdb,royc1/gpdb,Postgres-XL/Postgres-XL,0x0FFF/gpdb,jmcatamney/gpdb,cjcjameson/gpdb,yazun/postgres-xl,Quikling/gpdb,rubikloud/gpdb,ashwinstar/gpdb,yazun/postgres-xl,tangp3/gpdb,tangp3/gpdb,yazun/postgres-xl,50wu/gpdb,greenplum-db/gpdb,kaknikhil/gpdb,cjcjameson/gpdb,ashwinstar/gpdb,lpetrov-pivotal/gpdb,lintzc/gpdb,xuegang/gpdb,yuanzhao/gpdb,ashwinstar/gpdb,50wu/gpdb,ashwinstar/gpdb,janebeckman/gpdb,CraigHarris/gpdb,50wu/gpdb,postmind-net/postgres-xl,edespino/gpdb,jmcatamney/gpdb,rubikloud/gpdb,jmcatamney/gpdb,adam8157/gpdb,ashwinstar/gpdb,Chibin/gpdb,rvs/gpdb,arcivanov/postgres-xl,arcivanov/postgres-xl,randomtask1155/gpdb,rubikloud/gpdb,randomtask1155/gpdb,edespino/gpdb,lisakowen/gpdb,kaknikhil/gpdb,zaksoup/gpdb,rubikloud/gpdb,arcivanov/postgres-xl,royc1/gpdb,cjcjameson/gpdb,royc1/gpdb,Chibin/gpdb,edespino/gpdb,pavanvd/postgres-xl,atris/gpdb,yuanzhao/gpdb,snaga/postgres-xl,kaknikhil/gpdb,tpostgres-projects/tPostgres,ashwinstar/gpdb,snaga/postgres-xl,janebeckman/gpdb,yuanzhao/gpdb,rvs/gpdb,pavanvd/postgres-xl,ovr/postgres-xl,lintzc/gpdb,0x0FFF/gpdb,xinzweb/gpdb,CraigHarris/gpdb,postmind-net/postgres-xl,chrishajas/gpdb,lpetrov-pivotal/gpdb,yuanzhao/gpdb,foyzur/gpdb,Postgres-XL/Postgres-XL,lisakowen/gpdb,pavanvd/postgres-xl,cjcjameson/gpdb,lpetrov-pivotal/gpdb,tangp3/gpdb,lintzc/gpdb,jmcatamney/gpdb,ovr/postgres-xl,oberstet/postgres-xl,randomtask1155/gpdb,chrishajas/gpdb,kaknikhil/gpdb,Chibin/gpdb,lintzc/gpdb,jmcatamney/gpdb,lintzc/gpdb,jmcatamney/gpdb,zeroae/postgres-xl,foyzur/gpdb,cjcjameson/gpdb,ashwinstar/gpdb,techdragon/Postgres-XL,lintzc/gpdb,xuegang/gpdb,lisakowen/gpdb,atris/gpdb,yazun/postgres-xl,tpostgres-projects/tPostgres,adam8157/gpdb,kaknikhil/gpdb,lisakowen/gpdb,CraigHarris/gpdb,xuegang/gpdb,atris/gpdb,xinzweb/gpdb,ahachete/gpdb,snaga/postgres-xl,lpetrov-pivotal/gpdb,lintzc/gpdb,edespino/gpdb,adam8157/gpdb,ahachete/gpdb,ahachete/gpdb,rvs/gpdb,randomtask1155/gpdb,kmjungersen/PostgresXL,oberstet/postgres-xl,tpostgres-projects/tPostgres,adam8157/gpdb,janebeckman/gpdb,snaga/postgres-xl,jmcatamney/gpdb,kmjungersen/PostgresXL,xuegang/gpdb,zaksoup/gpdb,kaknikhil/gpdb,kaknikhil/gpdb,yuanzhao/gpdb,oberstet/postgres-xl,Chibin/gpdb,Quikling/gpdb,adam8157/gpdb,CraigHarris/gpdb,adam8157/gpdb,kaknikhil/gpdb,lpetrov-pivotal/gpdb,chrishajas/gpdb,tangp3/gpdb,adam8157/gpdb,royc1/gpdb,rubikloud/gpdb,chrishajas/gpdb,edespino/gpdb,arcivanov/postgres-xl,postmind-net/postgres-xl,zaksoup/gpdb,Chibin/gpdb,zaksoup/gpdb,ovr/postgres-xl,techdragon/Postgres-XL,rubikloud/gpdb,techdragon/Postgres-XL,kaknikhil/gpdb,royc1/gpdb,rvs/gpdb,rvs/gpdb,royc1/gpdb,ahachete/gpdb,chrishajas/gpdb,cjcjameson/gpdb,CraigHarris/gpdb,ahachete/gpdb,50wu/gpdb,techdragon/Postgres-XL,janebeckman/gpdb,postmind-net/postgres-xl,Chibin/gpdb,ovr/postgres-xl,randomtask1155/gpdb,randomtask1155/gpdb,ahachete/gpdb,atris/gpdb,snaga/postgres-xl,greenplum-db/gpdb,royc1/gpdb,yuanzhao/gpdb,foyzur/gpdb,tangp3/gpdb,yuanzhao/gpdb,rvs/gpdb,ovr/postgres-xl,janebeckman/gpdb,xuegang/gpdb,arcivanov/postgres-xl,zaksoup/gpdb,randomtask1155/gpdb,foyzur/gpdb,50wu/gpdb,zeroae/postgres-xl,atris/gpdb,50wu/gpdb,lpetrov-pivotal/gpdb,lintzc/gpdb,cjcjameson/gpdb,zaksoup/gpdb,xinzweb/gpdb