Skip to content

[Bug]: BCP import memory leak with decimals #2455

@staticlibs

Description

@staticlibs

What happened?

There seems to be a leak in decimal (numeric) conversion. Memory is allocated in MessageContext, so it is released after BCP import finishes. Still can be a problem when importing large files.

Using the following table with a decimal column:

create table tab1 (col1 decimal(18,5))
insert into tab1 values ('41.42')
insert into tab1 select col1 from tab1
insert into tab1 select col1 from tab1
insert into tab1 select col1 from tab1
insert into tab1 select col1 from tab1
insert into tab1 select col1 from tab1
insert into tab1 select col1 from tab1
insert into tab1 select col1 from tab1
insert into tab1 select col1 from tab1
insert into tab1 select col1 from tab1
insert into tab1 select col1 from tab1
insert into tab1 select col1 from tab1
insert into tab1 select col1 from tab1
insert into tab1 select col1 from tab1
insert into tab1 select col1 from tab1
insert into tab1 select col1 from tab1
insert into tab1 select col1 from tab1
insert into tab1 select col1 from tab1
insert into tab1 select col1 from tab1
insert into tab1 select col1 from tab1
insert into tab1 select col1 from tab1
select count(*) from tab1
> 1048576

Export it with BCP:

bcp tab1 out tab1.bcp -n -S 192.168.122.1,1433 -U jdbc_user -P 12345678
...
1048576 rows copied.
Network packet size (bytes): 4096
Clock Time (ms.) Total     : 1453   Average : (721662.75 rows per sec.)

Clear the table:

truncate table tab1

Run server under mprof:

mprof run -M ./bin/postgres -D /home/alex/projects/postgres/dist/data

Import exported data back with BCP:

bcp tab1 in tab1.bcp -n -S 192.168.122.1,1433 -U jdbc_user -P 12345678
...
1048576 rows copied.
Network packet size (bytes): 4096
Clock Time (ms.) Total     : 1578   Average : (664496.81 rows per sec.)

BCP import backend process shows excessive memory usage:

mprof plot

Figure_1

Will submit a patch to TdsTypeNumericToDatum shortly.

Version

BABEL_3_X_DEV (Default)

Extension

babelfishpg_tds

Which flavor of Linux are you using when you see the bug?

Fedora

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions