国产成人AV无码一二三区,少女1到100集,国产精品久久久久精品综合紧,巜公妇之诱感肉欲HD在线播放

文章 > PostgreSQL > postgresql有rowid吗

postgresql有rowid吗

头像

爱喝马黛茶的安东尼

2019-12-25 15:17:598260浏览 · 0收藏 · 0评论

oracle中可以通过rowid定位到一条数据。索引扫描就是先根据查询条件的到对应数据的rowid,然后通过rowid得到数据,也可以直接使用rowid来查询数据,比如select * from tbl where rowid=xxx; 在没有行迁移的情况下,rowid是固定不变的。

在pg中索引扫描是先查询到数据的ctid,然后根据ctid去得到相应的数据。但是ctid和oracle中的rowid并不完全相同,因为pg中多版本的原因,ctid是会发生变化的,例如:

bill=# select ctid,* from t1 limit 5;
 ctid | id 
--------+----
 (0,1) | 1
 (0,2) | 2
 (0,3) | 3
 (0,4) | 4
 (0,5) | 5
(5 rows)
bill=# update t1 set id=111 where id =1;
UPDATE 1
bill=# vacuum ANALYZE t1;
VACUUM
bill=# select ctid,* from t1 limit 5;   
 ctid | id 
--------+----
 (0,2) | 2
 (0,3) | 3
 (0,4) | 4
 (0,5) | 5
 (0,6) | 6
(5 rows)

那在pg中如何实现类似rowid类似的功能呢?

—方法一:sequence 唯一标识

bill=# create table tbl (rowid serial8 not null, c1 int, c2 int);  
CREATE TABLE
bill=# create unique index idx_tbl_1 on tbl(rowid);  
CREATE INDEX
bill=# insert into tbl (c1,c2) values (1,2);  
INSERT 0 1
bill=# insert into tbl (c1,c2) values (1,2);  
INSERT 0 1
bill=# insert into tbl (c1,c2) values (1,2);  
INSERT 0 1
bill=# select * from tbl;
rowid | c1 | c2 
------+----+----
   1 |  1 | 2
   2 |  1 | 2
   3 |  1 | 2
(3 rows)

—方法二:identify列

bill=# create table tbl (rowid int8 GENERATED ALWAYS AS IDENTITY not null, c1 int, c2 int);  
create unique index idx_tbl_1 on tbl(rowid);  CREATE TABLE
bill=# create unique index idx_tbl_1 on tbl(rowid);  
CREATE INDEX
bill=# insert into tbl (c1,c2) values (1,2);  
INSERT 0 1
bill=# insert into tbl (c1,c2) values (1,2);  
INSERT 0 1
bill=# insert into tbl (c1,c2) values (1,2);  
INSERT 0 1
bill=# select * from tbl;  
rowid | c1 | c2 
------+----+----
  1  | 1 |  2
  2  |  1 | 2
  3  | 1 | 2
(3 rows)

—方法三:oid

bill=# /dT oid
              List of data types
Schema   | Name |  Description                
-----------+------+-------------------------------------------
pg_catalog | oid |  object identifier(oid), maximum 4 billion
(1 row)

不过oid不适合存储超过40亿条记录的表。

postgres=# create table tbl (c1 int, c2 int) with oids;  
CREATE TABLE
postgres=# create unique index idx_tbl_oid on tbl(oid); 
CREATE INDEX
postgres=# insert into tbl (c1,c2) values (1,2);  
INSERT 168528 1
postgres=# insert into tbl (c1,c2) values (1,2);  
INSERT 168529 1
postgres=# insert into tbl (c1,c2) values (1,2);  
INSERT 168530 1
postgres=# select oid,* from tbl;  
oid    | c1 | c2 
--------+----+----
168528  | 1 | 2
168529  | 1 | 2
168530  | 1 | 2
(3 rows)

不过需要注意的是,在pg12中已经不支持create table xxx with oids这种语法了。

bill=# create table tbl (c1 int, c2 int) with oids; 
psql: ERROR:  syntax error at or near "oids"
LINE 1: create table tbl (c1 int, c2 int) with oids;

pg12中是将oid作为一种数据类型来使用:

d547fe2e9793aa4530fb05ebdaf5b6b.png

bill=# create table tbl(oid oid,c1 int,c2 int);
CREATE TABLE

Python学习网,大量的免费PostgreSQL入门教程,欢迎在线学习!

关注

关注公众号,随时随地在线学习

本教程部分素材来源于网络,版权问题联系站长!

老牛耕田陈雪435章| 《再来一次好吗》动漫观看| 《女学生做爰》| 公交车上荫蒂添的好舒服H漫画| 17.C-起草口在哪| 麻花传MV在线观看的最新进展| 《相濡以沫的夜晚》动漫免费观看 | 出差被最讨厌上司夺走的相似电影| 《好好疼爱里面》免费看| 老公边日边叫我小骚B| 苍空电影在线观看完整| 妈妈让我戴上避孕套的下一句是啥| 第九大陆| 《有夫之妇的秘书》演员表| 蜜桃臀| 啵啵浏览器| 妈妈你真棒里面的插曲叫什么 | 为啥越骚的女人干的越爽| 斗破苍穹年番免费高清观看| 《法国啄木鸟:会议2》| 《警花交换做爰》| 电影《满足2》完整版在线观看| 小峡子边喂奶边和我做爰好吗| 麻花星空天美MV免费观看电视剧 | 1尿到0的直肠里| 强伦轩女教师在线播放| 美女打屁股| 女被扒开腿狂躁XXXXX视频| 美女图片| 《交换做爰》在线观看| 人野兽马狗猪大全| 《家访的老师》动漫在线观看| 小扫货几天没弄了| 妈妈叫我戴上避孕套英文| 初中小姐姐脚丫踩在男生困困 | 日本大片又大又好看的PPT| 邻居熟妇的乳峰| 两个女人的战争在线观看| 欲奴性猛交2无删减| 《黏糊糊的你》免费观看| 成品人和精品人的区别在哪里知乎