Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support batch INSERT #290

Closed
terrymanu opened this issue Jul 13, 2017 · 23 comments
Closed

Support batch INSERT #290

terrymanu opened this issue Jul 13, 2017 · 23 comments
Assignees

Comments

@terrymanu
Copy link
Member

支持批量insert语句,例:

INSERT INTO t_table (xx, xx) VALUES
(xx,xx),
(xx,xx),
(xx,xx);

terrymanu added a commit that referenced this issue Jul 17, 2017
…ListLastPosition => generatedKeys and valuesListLastPositionList
@yinjw
Copy link

yinjw commented Jul 31, 2017

急需该功能,循环新增数据太慢了

@tian6318
Copy link

亮哥这么棒现在支持批量执行的语句了?

@igool
Copy link

igool commented Nov 18, 2017

请问现在要支持批量的话,只能单独更新这几个类吗?有没有分支可以直接使用?

@Comven
Copy link

Comven commented Dec 11, 2017

@terrymanu 建议亮哥优先考虑下支持透传方式执行sql,这样sharding-jdbc短时间不支持批量insert方式也能够通过透传方式,完成单一物理表的批量insert,毕竟在数据量较大的时候批量insert执行效率比一条一条的插入好太多。

@terrymanu terrymanu self-assigned this Feb 15, 2018
@githublaohu
Copy link

批量instet 能解析出来吗?

@wgou
Copy link

wgou commented Mar 5, 2018

建议亮哥优先考虑下支持透传方式执行sql,这样sharding-jdbc短时间不支持批量insert方式也能够通过透传方式,完成单一物理表的批量insert,毕竟在数据量较大的时候批量insert执行效率比一条一条的插入好太多。

@lazio579
Copy link

insert多条语句,按道理是需要分布式事务配合的,如果不嫌弃网易中间件的话,可以尝试我们的:https://github.com/Lede-Inc/cetus

@githublaohu
Copy link

哥们,牛头不对马嘴啊。

@lazio579
Copy link

批量插入,如果涉及到多个分库,当然需要分布式事务了

@githublaohu
Copy link

这个issues的问题是,insert解析与路由的问题。
sharding-jdbc支持两段提交啊

@lazio579
Copy link

在哪儿支持,我没有发现有任何xa的机制

@lazio579
Copy link

官方也只是说:

BASE Transaction

并不是真正的分布式事务

@githublaohu
Copy link

如果不支持两段提交,sharding-jdbc能上正式环境
两段提交,非常简单,需要纠结吗?

@githublaohu
Copy link

AbstractConnectionAdapter
看下这个类吧

@PrimaryKey3610
Copy link

insert into test
( A , B , C , D)VALUES('这是第0A','这是第0B','这是第0C','这是第0D'), ('这是第1A','这是第1B','这是第1C','这是第1D'), ('这是第2A','这是第2B','这是第2C','这是第2D');
Disconnected from the target VM, address: '127.0.0.1:63898', transport: 'socket'
2018-03-21 17:15:08.299 ERROR 15844 --- [ main] c.alibaba.druid.filter.stat.StatFilter : merge sql error, dbType mysql, sql : insert into test_0
( A , B , C , D, id)VALUES, 183266118457098240);

com.alibaba.druid.sql.parser.ParserException: syntax error, expect ')', pos 46, line 2, column 28, token COMMA

这是为啥啊? 是按照批量格式来的啊

@PrimaryKey3610
Copy link

            InsertStatement insertStatement = (InsertStatement)new SQLParsingEngine(DatabaseType.MySQL, insertSQL, shardingRule).parse();

这样写并没有更新. 这句代码是InsertStatementParserTest.java中找到的.

@dingmengyang
Copy link

我参照example那的springboot项目配置,批量插入还是不行。

io.shardingjdbc
sharding-jdbc-core-spring-boot-starter
2.0.3

需要2.1.0吗?(maven上现在只能获取2.0.3版本的)

@wgou
Copy link

wgou commented Apr 19, 2018

connection = DataSourceUtils.getConnection(dataSource);
		statement = connection.prepareStatement(sql);
		int rows = 0,count = 0;
		for(RebBusiLedgerDO busi : busiLedger){
			int idx =1;
			statement.setString(idx++, busi.getContractNo());
			statement.setString(idx++, busi.getSupplierCode());
			statement.setString(idx++, busi.getBusiNo());
			statement.setString(idx++, busi.getLedgerNo());
			statement.setInt(idx++, busi.getStatus());
			statement.setString(idx++, busi.getLedgerNo());
			statement.addBatch();
            count++;rows++;
            if (count % 5000 == 0) {
                statement.executeBatch();
                count = 0;
               }
           }
        if (count != 0) {
            statement.executeBatch();
        }

2.1以下版本 按照分表规则拆分N个集合,然后做这种批量不是很完美么?

@terrymanu terrymanu assigned maxiaoguang64 and unassigned terrymanu Apr 30, 2018
@terrymanu
Copy link
Member Author

terrymanu commented Apr 30, 2018

fixed at 3.0.0.M1

@codehorde
Copy link

codehorde commented Aug 8, 2018

只支持很简单的sql语法,虽然有dialect但很多语法都不支持

@terrymanu terrymanu changed the title 批量insert支持 Support batch INSERT Aug 8, 2018
@ratyzhang
Copy link

ratyzhang commented Mar 14, 2019

@terrymanu 亮哥
INSERT INTO t_table_yymmdd (xx, xx,....M) VALUES
(xx,xx,....M),
(xx,xx,....M),
(xx,xx,....M)
....N
当M(字段数)N(记录数)比较大,进行分表操作时,如50020时,sql执行非常慢,基本上卡死了。根据debug 应该问题出在 sqlRoute 和 sqlParse 这块。请确认。备注:版本为3.1.0

@Mirrormiss
Copy link

亮哥,在集成mybatis的时候 ,使用了批量新增,发现报了一个莫名的错误
(Parameter 'XXX' not found. Available parameters are [A, B]),
大致看了下,是不是因为单表mybatis的Invocation中是一条SQL,而批量的是一个集合,导致ShardingValue中的分片键和分片键的值对应不上的原因?
备注:版本为3.1.0

@yangyun-zero
Copy link

亮哥,插入多条数据,分表后,很慢,这个有什么方式可以解决吗

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests