环境:
操作系统: CentOS 7.2
数据库服务器: 10.1.23-MariaDB Columnstore 1.0.9-1
2个测试数据库,一个InnoDB和一个Columnstore:
CREATE TABLE `test_innodb` (
`ctlid` bigint(20) NOT NULL AUTO_INCREMENT,
`rfid` varchar(100) DEFAULT NULL,
PRIMARY KEY (`ctlid`)
) ENGINE=InnoDB
CREATE TABLE `test_cs` (
`ctlid` bigint(20) DEFAULT NULL COMMENT 'autoincrement=1',
`rfid` varchar(100) DEFAULT NULL
) ENGINE=Columnstore问题:
我在InnoDB表中运行了几个插入:
insert into test_innodb (rfid) values ('a1');
...
insert into test_innodb (rfid) values ('aX');当我想获得最后一个插入的id时,我运行以下命令:
select last_insert_id();结果正确地显示了在当前会话期间插入的最后一个ctlid值,而不管是否有其他并发会话运行插入到InnoDB表中并触发额外ctlid值的创建。到目前为止还不错..。
现在,我在Columnstore表中执行几个插入操作:
insert into test_cs (rfid) values ('a1');
...
insert into test_cs (rfid) values ('aX');我希望实现与上面相同的行为,但不幸的是,Columnstore忽略了这一点:
select last_insert_id();我使用了以下备选方案:
-- this will return the next value
select nextvalue from calpontsys.syscolumn cs where cs.schema='my_test_database' and cs.tablename='test_cs' and cs.columnname='ctlid';
- this will return the last inserted id
select callastinsertid('test_cs');但是两者都显示了一个主要的限制:如果其他并发会话运行插入,那么上述两个查询的结果将受到这些插入生成的自动增量值的影响。基本上,我可能没有得到预期的最后插入id,但如果其他会话并行地创建了自动增量值,则会得到一个更大的id。
我还试图:
select callastinsertid('test_cs')获取最后一个插入id但是,Columnstore似乎不支持锁定表。
是否有可能实现与Columnstore一致的最后插入id (每个会话)?
我们的计划是将我们的一些特性从MariaDB/MySQL转换到Columnstore,但是上面的限制是非常阻塞的。
发布于 2017-08-13 21:00:53
对于高速插入,插入到单独的表中,然后定期将数据从该表复制到实际表中。通过使用这个额外的表,您可以更容易地控制规范化和其他可能需要AUTO_INCREMENT值的事情。
并确保在单个线程中执行“复制”,而不是多个线程。
以下是对许多细节的讨论。ColumnStore需要进行一些调整,但我认为它会对您有用。table
注意乒乓球两张桌子的使用情况.这允许在并行复制到ColumnStore时持续摄入。
https://stackoverflow.com/questions/45461572
复制相似问题