Our code had:
Our code had:

                if (c == '\\' && cstate->line_buf.len == 0)

The problem with that is the because of the input and _output_
buffering, cstate->line_buf.len could be zero even if we are not on the
first character of a line.  In fact, for a typical line, it is zero for
all characters on the line.  The proper solution is to introduce a
boolean, first_char_in_line, that we set as we enter the loop and clear
once we process a character.

I have restructured the line-reading code in copy.c by:

        o  merging the CSV/non-CSV functions into a single function
        o  used macros to centralize and clarify the buffering code
        o  updated comments
        o  renamed client_encoding_only to encoding_embeds_ascii
        o  added a high-bit test to the encoding_embeds_ascii test for
           performance
        o  in CSV mode, allow a backslash followed by a non-period to
           continue being processed as a data value

There should be no performance impact from this patch because it is
functionally equivalent.  If you apply the patch you will see copy.c is
much clearer in this area now and might suggest additional
optimizations.

I have also attached a 8.1-only patch to fix the CSV \. handling bug
with no code restructuring.

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