Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Gpdb
提交
0a5fdb0d
G
Gpdb
项目概览
Greenplum
/
Gpdb
通知
7
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
Gpdb
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
0a5fdb0d
编写于
5月 25, 2006
作者:
T
Tom Lane
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Reduce per-character overhead in COPY OUT by combining calls to
CopySendData.
上级
c76cb771
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
90 addition
and
42 deletion
+90
-42
src/backend/commands/copy.c
src/backend/commands/copy.c
+90
-42
未找到文件。
src/backend/commands/copy.c
浏览文件 @
0a5fdb0d
...
...
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.26
4 2006/05/21 20:05:19
tgl Exp $
* $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.26
5 2006/05/25 18:42:17
tgl Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -243,8 +243,8 @@ static Datum CopyReadBinaryAttribute(CopyState cstate,
int
column_no
,
FmgrInfo
*
flinfo
,
Oid
typioparam
,
int32
typmod
,
bool
*
isnull
);
static
void
CopyAttributeOutText
(
CopyState
cstate
,
char
*
s
erver_s
tring
);
static
void
CopyAttributeOutCSV
(
CopyState
cstate
,
char
*
s
erver_s
tring
,
static
void
CopyAttributeOutText
(
CopyState
cstate
,
char
*
string
);
static
void
CopyAttributeOutCSV
(
CopyState
cstate
,
char
*
string
,
bool
use_quote
,
bool
single_attr
);
static
List
*
CopyGetAttnums
(
Relation
rel
,
List
*
attnamelist
);
static
char
*
limit_printout_length
(
const
char
*
str
);
...
...
@@ -2884,91 +2884,123 @@ CopyReadBinaryAttribute(CopyState cstate,
/*
* Send text representation of one attribute, with conversion and escaping
*/
#define DUMPSOFAR() \
do { \
if (ptr > start) \
CopySendData(cstate, start, ptr - start); \
} while (0)
static
void
CopyAttributeOutText
(
CopyState
cstate
,
char
*
s
erver_s
tring
)
CopyAttributeOutText
(
CopyState
cstate
,
char
*
string
)
{
char
*
string
;
char
*
ptr
;
char
*
start
;
char
c
;
char
delimc
=
cstate
->
delim
[
0
];
int
mblen
;
if
(
cstate
->
need_transcoding
)
string
=
pg_server_to_client
(
server_string
,
strlen
(
server_
string
));
ptr
=
pg_server_to_client
(
string
,
strlen
(
string
));
else
string
=
server_
string
;
ptr
=
string
;
for
(;
(
c
=
*
string
)
!=
'\0'
;
string
+=
mblen
)
/*
* We have to grovel through the string searching for control characters
* and instances of the delimiter character. In most cases, though, these
* are infrequent. To avoid overhead from calling CopySendData once per
* character, we dump out all characters between replaceable characters
* in a single call. The loop invariant is that the data from "start"
* to "ptr" can be sent literally, but hasn't yet been.
*/
start
=
ptr
;
while
((
c
=
*
ptr
)
!=
'\0'
)
{
mblen
=
1
;
switch
(
c
)
{
case
'\b'
:
DUMPSOFAR
();
CopySendString
(
cstate
,
"
\\
b"
);
start
=
++
ptr
;
break
;
case
'\f'
:
DUMPSOFAR
();
CopySendString
(
cstate
,
"
\\
f"
);
start
=
++
ptr
;
break
;
case
'\n'
:
DUMPSOFAR
();
CopySendString
(
cstate
,
"
\\
n"
);
start
=
++
ptr
;
break
;
case
'\r'
:
DUMPSOFAR
();
CopySendString
(
cstate
,
"
\\
r"
);
start
=
++
ptr
;
break
;
case
'\t'
:
DUMPSOFAR
();
CopySendString
(
cstate
,
"
\\
t"
);
start
=
++
ptr
;
break
;
case
'\v'
:
DUMPSOFAR
();
CopySendString
(
cstate
,
"
\\
v"
);
start
=
++
ptr
;
break
;
case
'\\'
:
DUMPSOFAR
();
CopySendString
(
cstate
,
"
\\\\
"
);
start
=
++
ptr
;
break
;
default:
if
(
c
==
delimc
)
{
DUMPSOFAR
();
CopySendChar
(
cstate
,
'\\'
);
start
=
ptr
;
/* we include char in next run */
}
/*
* We can skip pg_encoding_mblen() overhead when encoding is
* safe, because in valid backend encodings, extra bytes of a
* multibyte character never look like ASCII.
*/
if
(
cstate
->
encoding_embeds_ascii
&&
IS_HIGHBIT_SET
(
c
))
mblen
=
pg_encoding_mblen
(
cstate
->
client_encoding
,
string
);
CopySendData
(
cstate
,
string
,
mblen
);
if
(
IS_HIGHBIT_SET
(
c
)
&&
cstate
->
encoding_embeds_ascii
)
ptr
+=
pg_encoding_mblen
(
cstate
->
client_encoding
,
ptr
);
else
ptr
++
;
break
;
}
}
DUMPSOFAR
();
}
/*
* Send
CSV
representation of one attribute, with conversion and
* CSV
typ
e escaping
* Send
text
representation of one attribute, with conversion and
* CSV
-styl
e escaping
*/
static
void
CopyAttributeOutCSV
(
CopyState
cstate
,
char
*
s
erver_s
tring
,
CopyAttributeOutCSV
(
CopyState
cstate
,
char
*
string
,
bool
use_quote
,
bool
single_attr
)
{
char
*
string
;
char
*
ptr
;
char
*
start
;
char
c
;
char
delimc
=
cstate
->
delim
[
0
];
char
quotec
=
cstate
->
quote
[
0
];
char
escapec
=
cstate
->
escape
[
0
];
char
*
tstring
;
int
mblen
;
/* force quoting if it matches null_print */
if
(
!
use_quote
&&
strcmp
(
s
erver_s
tring
,
cstate
->
null_print
)
==
0
)
/* force quoting if it matches null_print
(before conversion!)
*/
if
(
!
use_quote
&&
strcmp
(
string
,
cstate
->
null_print
)
==
0
)
use_quote
=
true
;
if
(
cstate
->
need_transcoding
)
string
=
pg_server_to_client
(
server_string
,
strlen
(
server_
string
));
ptr
=
pg_server_to_client
(
string
,
strlen
(
string
));
else
string
=
server_
string
;
ptr
=
string
;
/*
* have to run through the string twice, first time to see if it needs
* quoting, second to actually send it
* Make a preliminary pass to discover if it needs quoting
*/
if
(
!
use_quote
)
{
...
...
@@ -2977,41 +3009,57 @@ CopyAttributeOutCSV(CopyState cstate, char *server_string,
* alone on a line so it is not interpreted as the end-of-data
* marker.
*/
if
(
single_attr
&&
strcmp
(
string
,
"
\\
."
)
==
0
)
if
(
single_attr
&&
strcmp
(
ptr
,
"
\\
."
)
==
0
)
use_quote
=
true
;
else
{
for
(
tstring
=
string
;
(
c
=
*
tstring
)
!=
'\0'
;
tstring
+=
mblen
)
char
*
tptr
=
ptr
;
while
((
c
=
*
tptr
)
!=
'\0'
)
{
if
(
c
==
delimc
||
c
==
quotec
||
c
==
'\n'
||
c
==
'\r'
)
{
use_quote
=
true
;
break
;
}
if
(
cstate
->
encoding_embeds_ascii
&&
IS_HIGHBIT_SET
(
c
)
)
mblen
=
pg_encoding_mblen
(
cstate
->
client_encoding
,
tstring
);
if
(
IS_HIGHBIT_SET
(
c
)
&&
cstate
->
encoding_embeds_ascii
)
tptr
+=
pg_encoding_mblen
(
cstate
->
client_encoding
,
tptr
);
else
mblen
=
1
;
tptr
++
;
}
}
}
if
(
use_quote
)
{
CopySendChar
(
cstate
,
quotec
);
for
(;
(
c
=
*
string
)
!=
'\0'
;
string
+=
mblen
)
{
if
(
use_quote
&&
(
c
==
quotec
||
c
==
escapec
))
CopySendChar
(
cstate
,
escapec
);
if
(
cstate
->
encoding_embeds_ascii
&&
IS_HIGHBIT_SET
(
c
))
mblen
=
pg_encoding_mblen
(
cstate
->
client_encoding
,
string
);
else
mblen
=
1
;
CopySendData
(
cstate
,
string
,
mblen
);
}
/*
* We adopt the same optimization strategy as in CopyAttributeOutText
*/
start
=
ptr
;
while
((
c
=
*
ptr
)
!=
'\0'
)
{
if
(
c
==
quotec
||
c
==
escapec
)
{
DUMPSOFAR
();
CopySendChar
(
cstate
,
escapec
);
start
=
ptr
;
/* we include char in next run */
}
if
(
IS_HIGHBIT_SET
(
c
)
&&
cstate
->
encoding_embeds_ascii
)
ptr
+=
pg_encoding_mblen
(
cstate
->
client_encoding
,
ptr
);
else
ptr
++
;
}
DUMPSOFAR
();
if
(
use_quote
)
CopySendChar
(
cstate
,
quotec
);
}
else
{
/* If it doesn't need quoting, we can just dump it as-is */
CopySendString
(
cstate
,
ptr
);
}
}
/*
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录