我有一个像这样的表(Postgresql 9.6)
CREATE TABLE m_trade (
"alias" Character Varying( 32 ),
"ts" Bigint NOT NULL,
"side" Character( 1 ),
"price" Double Precision,
"qty" Bigint );
有 50 000 000 行。
创建 timescaledb 扩展后 -
CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;
我从空表创建 hyper_table -
CREATE TABLE d_trade (
"alias" Character Varying( 32 ),
"ts" Bigint NOT NULL,
"side" Character( 1 ),
"price" Double Precision,
"qty" Bigint );
SELECT create_hypertable('d_trade', 'ts', chunk_time_interval => 86400 , number_partitions =>31);
在这张d_trade
桌子上之后我得到
INDEX "d_trade_ts_idx" and
TRIGGER ts_insert_blocker BEFORE INSERT
INSERT INTO
"public"."d_trade"( "alias", "price", "qty", "side", "ts" )
select "alias", "price", "qty", "side", "ts" from m_trade
现在,如果我尝试m_trade
通过
INSERT INTO
"public"."m_trade"( "alias", "price", "qty", "side", "ts" )
VALUES
('TESTALS', 16000, 5, 2, 1545307519)
这将需要 1-1.5 毫秒,但这会延迟 4-5 毫秒
INSERT INTO
"public"."d_trade"( "alias", "price", "qty", "side", "ts" )
VALUES
('TESTALS', 16000, 5, 2, 1545307519)
如何优化d_trade
表上的插入速度?