这篇文章主要讲解了“PostgreSQL 12 B-tree的改进是什么”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“PostgreSQL 12 B-tree的改进是什么”吧!

创建数据表,创建索引

[local]:5110xdb@testdb=#droptablerel;DROPTABLETime:130.868ms[local]:5110xdb@testdb=#CREATETABLErel(xdb@testdb(#aidbigintNOTNULL,xdb@testdb(#bidbigintNOTNULLxdb@testdb(#);CREATETABLETime:16.041ms[local]:5110xdb@testdb=#[local]:5110xdb@testdb=#ALTERTABLErelxdb@testdb-#ADDCONSTRAINTrel_pkeyPRIMARYKEY(aid,bid);ALTERTABLETime:5.236ms[local]:5110xdb@testdb=#[local]:5110xdb@testdb=#CREATEINDEXrel_bid_idxONrel(bid);CREATEINDEXTime:1.838ms[local]:5110xdb@testdb=#[local]:5110xdb@testdb=#INSERTINTOrel(aid,bid)xdb@testdb-#SELECTi,i/10000xdb@testdb-#FROMgenerate_series(1,20000000)ASi;INSERT020000000Time:152699.275ms(02:32.699)[local]:5110xdb@testdb=#[local]:5110xdb@testdb=#

查看索引信息

[local]:5110xdb@testdb=#[local]:5110xdb@testdb=#\drelTable"public.rel"Column|Type|Collation|Nullable|Default--------+--------+-----------+----------+---------aid|bigint||notnull|bid|bigint||notnull|Indexes:"rel_pkey"PRIMARYKEY,btree(aid,bid)"rel_bid_idx"btree(bid)[local]:5110xdb@testdb=#\di+rel_pkeyListofrelationsSchema|Name|Type|Owner|Table|Size|Description--------+----------+-------+-------+-------+--------+-------------public|rel_pkey|index|xdb|rel|602MB|(1row)[local]:5110xdb@testdb=#\di+rel_bid_idxListofrelationsSchema|Name|Type|Owner|Table|Size|Description--------+-------------+-------+-------+-------+--------+-------------public|rel_bid_idx|index|xdb|rel|545MB|(1row)

创建数据表,创建索引

[local:/run/pg12]:5120pg12@testdb=#\timingonTimingison.[local:/run/pg12]:5120pg12@testdb=#droptablerel;DROPTABLETime:279.144ms[local:/run/pg12]:5120pg12@testdb=#CREATETABLErel(pg12@testdb(#aidbigintNOTNULL,pg12@testdb(#bidbigintNOTNULLpg12@testdb(#);CREATETABLETime:1.579ms[local:/run/pg12]:5120pg12@testdb=#[local:/run/pg12]:5120pg12@testdb=#ALTERTABLErelpg12@testdb-#ADDCONSTRAINTrel_pkeyPRIMARYKEY(aid,bid);ALTERTABLETime:3.450ms[local:/run/pg12]:5120pg12@testdb=#[local:/run/pg12]:5120pg12@testdb=#CREATEINDEXrel_bid_idxONrel(bid);CREATEINDEXTime:1.201ms[local:/run/pg12]:5120pg12@testdb=#[local:/run/pg12]:5120pg12@testdb=#INSERTINTOrel(aid,bid)pg12@testdb-#SELECTi,i/10000pg12@testdb-#FROMgenerate_series(1,20000000)ASi;INSERT020000000Time:124503.212ms(02:04.503)[local:/run/pg12]:5120pg12@testdb=#

查看索引信息

[local:/run/pg12]:5120pg12@testdb=#\di+rel_pkeyListofrelationsSchema|Name|Type|Owner|Table|Size|Description--------+----------+-------+-------+-------+--------+-------------public|rel_pkey|index|pg12|rel|601MB|(1row)[local:/run/pg12]:5120pg12@testdb=#\di+rel_bid_idxListofrelationsSchema|Name|Type|Owner|Table|Size|Description--------+-------------+-------+-------+-------+--------+-------------public|rel_bid_idx|index|pg12|rel|408MB|(1row)[local:/run/pg12]:5120pg12@testdb=#

可以看到PK没有太大的变化,但有很多重复值的bid列索引则有明显的变化,比PG 11少了25%的空间。

感谢各位的阅读,以上就是“PostgreSQL 12 B-tree的改进是什么”的内容了,经过本文的学习后,相信大家对PostgreSQL 12 B-tree的改进是什么这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是亿速云,小编将为大家推送更多相关知识点的文章,欢迎关注!