Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Gpdb
提交
e44beef7
G
Gpdb
项目概览
Greenplum
/
Gpdb
通知
7
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
Gpdb
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e44beef7
编写于
8月 11, 2002
作者:
T
Tom Lane
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Code review of CLUSTER patch. Clean up problems with relcache getting
confused, toasted data getting lost, etc.
上级
9bccdf17
变更
12
展开全部
隐藏空白更改
内联
并排
Showing
12 changed file
with
558 addition
and
429 deletion
+558
-429
doc/src/sgml/release.sgml
doc/src/sgml/release.sgml
+2
-1
src/backend/catalog/heap.c
src/backend/catalog/heap.c
+11
-15
src/backend/catalog/index.c
src/backend/catalog/index.c
+7
-8
src/backend/catalog/pg_depend.c
src/backend/catalog/pg_depend.c
+7
-3
src/backend/commands/cluster.c
src/backend/commands/cluster.c
+262
-166
src/backend/storage/buffer/bufmgr.c
src/backend/storage/buffer/bufmgr.c
+18
-6
src/backend/utils/cache/relcache.c
src/backend/utils/cache/relcache.c
+34
-24
src/include/catalog/dependency.h
src/include/catalog/dependency.h
+2
-2
src/include/storage/bufmgr.h
src/include/storage/bufmgr.h
+2
-1
src/include/utils/rel.h
src/include/utils/rel.h
+5
-1
src/test/regress/expected/cluster.out
src/test/regress/expected/cluster.out
+196
-193
src/test/regress/sql/cluster.sql
src/test/regress/sql/cluster.sql
+12
-9
未找到文件。
doc/src/sgml/release.sgml
浏览文件 @
e44beef7
<!--
$Header: /cvsroot/pgsql/doc/src/sgml/release.sgml,v 1.14
5 2002/08/02 18:15:0
4 tgl Exp $
$Header: /cvsroot/pgsql/doc/src/sgml/release.sgml,v 1.14
6 2002/08/11 21:17:3
4 tgl Exp $
-->
<appendix id="release">
...
...
@@ -24,6 +24,7 @@ CDATA means the content is "SGML-free", so you can write without
worries about funny characters.
-->
<literallayout><![CDATA[
CLUSTER is no longer hazardous to your schema
COPY accepts a list of columns to copy
ALTER TABLE DROP COLUMN
CREATE OPERATOR CLASS/DROP OPERATOR CLASS
...
...
src/backend/catalog/heap.c
浏览文件 @
e44beef7
...
...
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.2
19 2002/08/06 02:36:33
tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.2
20 2002/08/11 21:17:34
tgl Exp $
*
*
* INTERFACE ROUTINES
...
...
@@ -198,7 +198,8 @@ SystemAttributeByName(const char *attname, bool relhasoids)
* Remove the system relation specific code to elsewhere eventually.
*
* If storage_create is TRUE then heap_storage_create is called here,
* else caller must call heap_storage_create later.
* else caller must call heap_storage_create later (or not at all,
* if the relation doesn't need physical storage).
* ----------------------------------------------------------------
*/
Relation
...
...
@@ -291,7 +292,7 @@ heap_create(const char *relname,
nailme
);
/*
* have the storage manager create the relation.
* have the storage manager create the relation
's disk file, if wanted
.
*/
if
(
storage_create
)
heap_storage_create
(
rel
);
...
...
@@ -684,20 +685,21 @@ heap_create_with_catalog(const char *relname,
tupdesc
->
tdhasoid
=
BoolToHasOid
(
relhasoids
);
/*
* Tell heap_create not to create a physical file; we'll do that below
* after all our catalog updates are done. (This isn't really
* necessary anymore, but we may as well avoid the cycles of creating
* and deleting the file in case we fail.)
* Create the relcache entry (mostly dummy at this point) and the
* physical disk file. (If we fail further down, it's the smgr's
* responsibility to remove the disk file again.)
*
* NB: create a physical file only if it's not a view.
*/
new_rel_desc
=
heap_create
(
relname
,
relnamespace
,
tupdesc
,
shared_relation
,
false
,
(
relkind
!=
RELKIND_VIEW
)
,
allow_system_table_mods
);
/* Fetch the relation OID assigned by heap_create */
new_rel_oid
=
new_rel_desc
->
rd_att
->
attrs
[
0
]
->
attrelid
;
new_rel_oid
=
RelationGetRelid
(
new_rel_desc
)
;
/* Assign an OID for the relation's tuple type */
new_type_oid
=
newoid
();
...
...
@@ -761,12 +763,6 @@ heap_create_with_catalog(const char *relname,
*/
StoreConstraints
(
new_rel_desc
,
tupdesc
);
/*
* We create the disk file for this relation here
*/
if
(
relkind
!=
RELKIND_VIEW
)
heap_storage_create
(
new_rel_desc
);
/*
* ok, the relation has been cataloged, so close our relations and
* return the oid of the newly created relation.
...
...
src/backend/catalog/index.c
浏览文件 @
e44beef7
...
...
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.18
8 2002/08/05 03:29:16
tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.18
9 2002/08/11 21:17:34
tgl Exp $
*
*
* INTERFACE ROUTINES
...
...
@@ -578,14 +578,18 @@ index_create(Oid heapRelationId,
indexTupDesc
->
tdhasoid
=
WITHOUTOID
;
/*
* create the index relation (but don't create storage yet)
* create the index relation's relcache entry and physical disk file.
* (If we fail further down, it's the smgr's responsibility to remove
* the disk file again.)
*/
indexRelation
=
heap_create
(
indexRelationName
,
namespaceId
,
indexTupDesc
,
shared_relation
,
fals
e
,
tru
e
,
allow_system_table_mods
);
/* Fetch the relation OID assigned by heap_create */
indexoid
=
RelationGetRelid
(
indexRelation
);
/*
...
...
@@ -611,11 +615,6 @@ index_create(Oid heapRelationId,
*/
UpdateRelationRelation
(
indexRelation
);
/*
* We create the disk file for this relation here
*/
heap_storage_create
(
indexRelation
);
/*
* now update the object id's of all the attribute tuple forms in the
* index relation's tuple descriptor
...
...
src/backend/catalog/pg_depend.c
浏览文件 @
e44beef7
...
...
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_depend.c,v 1.
4 2002/08/05 03:29:16
tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_depend.c,v 1.
5 2002/08/11 21:17:34
tgl Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -121,15 +121,16 @@ recordMultipleDependencies(const ObjectAddress *depender,
/*
* deleteDependencyRecordsFor -- delete all records with given depender
* classId/objectId.
* classId/objectId.
Returns the number of records deleted.
*
* This is used when redefining an existing object. Links leading to the
* object do not change, and links leading from it will be recreated
* (possibly with some differences from before).
*/
void
long
deleteDependencyRecordsFor
(
Oid
classId
,
Oid
objectId
)
{
long
count
=
0
;
Relation
depRel
;
ScanKeyData
key
[
2
];
SysScanDesc
scan
;
...
...
@@ -150,11 +151,14 @@ deleteDependencyRecordsFor(Oid classId, Oid objectId)
while
(
HeapTupleIsValid
(
tup
=
systable_getnext
(
scan
)))
{
simple_heap_delete
(
depRel
,
&
tup
->
t_self
);
count
++
;
}
systable_endscan
(
scan
);
heap_close
(
depRel
,
RowExclusiveLock
);
return
count
;
}
/*
...
...
src/backend/commands/cluster.c
浏览文件 @
e44beef7
此差异已折叠。
点击以展开。
src/backend/storage/buffer/bufmgr.c
浏览文件 @
e44beef7
...
...
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.12
8 2002/08/06 02:36
:34 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.12
9 2002/08/11 21:17
:34 tgl Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -1038,11 +1038,6 @@ BufferReplace(BufferDesc *bufHdr)
* RelationGetNumberOfBlocks
* Determines the current number of pages in the relation.
* Side effect: relation->rd_nblocks is updated.
*
* Note:
* XXX may fail for huge relations.
* XXX should be elsewhere.
* XXX maybe should be hidden
*/
BlockNumber
RelationGetNumberOfBlocks
(
Relation
relation
)
...
...
@@ -1061,6 +1056,23 @@ RelationGetNumberOfBlocks(Relation relation)
return
relation
->
rd_nblocks
;
}
/*
* RelationUpdateNumberOfBlocks
* Forcibly update relation->rd_nblocks.
*
* If the relcache drops an entry for a temp relation, it must call this
* routine after recreating the relcache entry, so that rd_nblocks is
* re-sync'd with reality. See RelationGetNumberOfBlocks.
*/
void
RelationUpdateNumberOfBlocks
(
Relation
relation
)
{
if
(
relation
->
rd_rel
->
relkind
==
RELKIND_VIEW
)
relation
->
rd_nblocks
=
0
;
else
relation
->
rd_nblocks
=
smgrnblocks
(
DEFAULT_SMGR
,
relation
);
}
/* ---------------------------------------------------------------------
* DropRelationBuffers
*
...
...
src/backend/utils/cache/relcache.c
浏览文件 @
e44beef7
...
...
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.17
1 2002/08/06 02:36
:35 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.17
2 2002/08/11 21:17
:35 tgl Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -860,11 +860,12 @@ RelationBuildDesc(RelationBuildDescInfo buildinfo,
/*
* normal relations are not nailed into the cache; nor can a pre-existing
* relation be new or temp.
* relation be new. It could be temp though. (Actually, it could be new
* too, but it's okay to forget that fact if forced to flush the entry.)
*/
relation
->
rd_isnailed
=
false
;
relation
->
rd_isnew
=
false
;
relation
->
rd_istemp
=
false
;
relation
->
rd_istemp
=
isTempNamespace
(
relation
->
rd_rel
->
relnamespace
)
;
/*
* initialize the tuple descriptor (relation->rd_att).
...
...
@@ -909,13 +910,23 @@ RelationBuildDesc(RelationBuildDescInfo buildinfo,
relation
->
rd_fd
=
-
1
;
/*
* insert newly created relation into proper relcaches, restore memory
* context and return the new reldesc.
* Insert newly created relation into relcache hash tables.
*/
oldcxt
=
MemoryContextSwitchTo
(
CacheMemoryContext
);
RelationCacheInsert
(
relation
);
MemoryContextSwitchTo
(
oldcxt
);
/*
* If it's a temp rel, RelationGetNumberOfBlocks will assume that
* rd_nblocks is correct. Must forcibly update the block count when
* creating the relcache entry. But if we are doing a rebuild, don't
* do this yet; leave it to RelationClearRelation to do at the end.
* (Otherwise, an elog in RelationUpdateNumberOfBlocks would leave us
* with inconsistent relcache state.)
*/
if
(
relation
->
rd_istemp
&&
oldrelation
==
NULL
)
RelationUpdateNumberOfBlocks
(
relation
);
return
relation
;
}
...
...
@@ -1601,8 +1612,7 @@ RelationClose(Relation relation)
#ifdef RELCACHE_FORCE_RELEASE
if
(
RelationHasReferenceCountZero
(
relation
)
&&
!
relation
->
rd_isnew
&&
!
relation
->
rd_istemp
)
!
relation
->
rd_isnew
)
RelationClearRelation
(
relation
,
false
);
#endif
}
...
...
@@ -1733,19 +1743,15 @@ RelationClearRelation(Relation relation, bool rebuild)
{
/*
* When rebuilding an open relcache entry, must preserve ref count
* and new/temp flags. Also attempt to preserve the tupledesc,
* rewrite rules, and trigger substructures in place. Furthermore
* we save/restore rd_nblocks (in case it is a new/temp relation)
* *and* call RelationGetNumberOfBlocks (in case it isn't).
* and rd_isnew flag. Also attempt to preserve the tupledesc,
* rewrite rules, and trigger substructures in place.
*/
int
old_refcnt
=
relation
->
rd_refcnt
;
bool
old_isnew
=
relation
->
rd_isnew
;
bool
old_istemp
=
relation
->
rd_istemp
;
TupleDesc
old_att
=
relation
->
rd_att
;
RuleLock
*
old_rules
=
relation
->
rd_rules
;
MemoryContext
old_rulescxt
=
relation
->
rd_rulescxt
;
TriggerDesc
*
old_trigdesc
=
relation
->
trigdesc
;
BlockNumber
old_nblocks
=
relation
->
rd_nblocks
;
RelationBuildDescInfo
buildinfo
;
buildinfo
.
infotype
=
INFO_RELID
;
...
...
@@ -1764,7 +1770,6 @@ RelationClearRelation(Relation relation, bool rebuild)
}
RelationSetReferenceCount
(
relation
,
old_refcnt
);
relation
->
rd_isnew
=
old_isnew
;
relation
->
rd_istemp
=
old_istemp
;
if
(
equalTupleDescs
(
old_att
,
relation
->
rd_att
))
{
FreeTupleDesc
(
relation
->
rd_att
);
...
...
@@ -1791,13 +1796,14 @@ RelationClearRelation(Relation relation, bool rebuild)
}
else
FreeTriggerDesc
(
old_trigdesc
);
relation
->
rd_nblocks
=
old_nblocks
;
/*
* this is kind of expensive, but I think we must do it in case
* relation has been truncated...
* Update rd_nblocks. This is kind of expensive, but I think we must
* do it in case relation has been truncated... we definitely must
* do it if the rel is new or temp, since RelationGetNumberOfBlocks
* will subsequently assume that the block count is correct.
*/
relation
->
rd_nblocks
=
RelationGet
NumberOfBlocks
(
relation
);
RelationUpdate
NumberOfBlocks
(
relation
);
}
}
...
...
@@ -1811,18 +1817,19 @@ RelationFlushRelation(Relation relation)
{
bool
rebuild
;
if
(
relation
->
rd_isnew
||
relation
->
rd_istemp
)
if
(
relation
->
rd_isnew
)
{
/*
* New and temp relcache entries must always be rebuilt, not
* flushed; else we'd forget those two important status bits.
* New relcache entries are always rebuilt, not flushed; else we'd
* forget the "new" status of the relation, which is a useful
* optimization to have.
*/
rebuild
=
true
;
}
else
{
/*
*
Nonlocal
rels can be dropped from the relcache if not open.
*
Pre-existing
rels can be dropped from the relcache if not open.
*/
rebuild
=
!
RelationHasReferenceCountZero
(
relation
);
}
...
...
@@ -1921,7 +1928,7 @@ RelationCacheInvalidate(void)
relcacheInvalsReceived
++
;
if
(
RelationHasReferenceCountZero
(
relation
)
&&
!
relation
->
rd_istemp
)
if
(
RelationHasReferenceCountZero
(
relation
))
{
/* Delete this entry immediately */
RelationClearRelation
(
relation
,
false
);
...
...
@@ -1965,7 +1972,10 @@ AtEOXact_RelationCache(bool commit)
*
* During commit, reset the flag to false, since we are now out of the
* creating transaction. During abort, simply delete the relcache
* entry --- it isn't interesting any longer.
* entry --- it isn't interesting any longer. (NOTE: if we have
* forgotten the isnew state of a new relation due to a forced cache
* flush, the entry will get deleted anyway by shared-cache-inval
* processing of the aborted pg_class insertion.)
*/
if
(
relation
->
rd_isnew
)
{
...
...
src/include/catalog/dependency.h
浏览文件 @
e44beef7
...
...
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: dependency.h,v 1.
3 2002/07/16 22:12:20
tgl Exp $
* $Id: dependency.h,v 1.
4 2002/08/11 21:17:35
tgl Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -98,6 +98,6 @@ extern void recordMultipleDependencies(const ObjectAddress *depender,
int
nreferenced
,
DependencyType
behavior
);
extern
void
deleteDependencyRecordsFor
(
Oid
classId
,
Oid
objectId
);
extern
long
deleteDependencyRecordsFor
(
Oid
classId
,
Oid
objectId
);
#endif
/* DEPENDENCY_H */
src/include/storage/bufmgr.h
浏览文件 @
e44beef7
...
...
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: bufmgr.h,v 1.6
2 2002/08/06 02:36
:35 tgl Exp $
* $Id: bufmgr.h,v 1.6
3 2002/08/11 21:17
:35 tgl Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -161,6 +161,7 @@ extern void AtEOXact_Buffers(bool isCommit);
extern
void
FlushBufferPool
(
void
);
extern
BlockNumber
BufferGetBlockNumber
(
Buffer
buffer
);
extern
BlockNumber
RelationGetNumberOfBlocks
(
Relation
relation
);
extern
void
RelationUpdateNumberOfBlocks
(
Relation
relation
);
extern
int
FlushRelationBuffers
(
Relation
rel
,
BlockNumber
firstDelBlock
);
extern
void
DropRelationBuffers
(
Relation
rel
);
extern
void
DropRelFileNodeBuffers
(
RelFileNode
rnode
,
bool
istemp
);
...
...
src/include/utils/rel.h
浏览文件 @
e44beef7
...
...
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: rel.h,v 1.6
1 2002/08/06 02:36
:35 tgl Exp $
* $Id: rel.h,v 1.6
2 2002/08/11 21:17
:35 tgl Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -113,6 +113,10 @@ typedef struct RelationData
* InvalidBlockNumber */
int
rd_refcnt
;
/* reference count */
bool
rd_isnew
;
/* rel was created in current xact */
/*
* NOTE: rd_isnew should be relied on only for optimization purposes;
* it is possible for new-ness to be "forgotten" (eg, after CLUSTER).
*/
bool
rd_istemp
;
/* rel uses the local buffer mgr */
bool
rd_isnailed
;
/* rel is nailed in cache */
bool
rd_indexfound
;
/* true if rd_indexlist is valid */
...
...
src/test/regress/expected/cluster.out
浏览文件 @
e44beef7
...
...
@@ -8,6 +8,7 @@ NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index 'clstr_tst_s_pkey
CREATE TABLE clstr_tst (a SERIAL PRIMARY KEY,
b INT,
c TEXT,
d TEXT,
CONSTRAINT clstr_tst_con FOREIGN KEY (b) REFERENCES clstr_tst_s);
NOTICE: CREATE TABLE will create implicit sequence 'clstr_tst_a_seq' for SERIAL column 'clstr_tst.a'
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index 'clstr_tst_pkey' for table 'clstr_tst'
...
...
@@ -54,220 +55,222 @@ INSERT INTO clstr_tst (b, c) VALUES (15, 'quince');
INSERT INTO clstr_tst (b, c) VALUES (7, 'siete');
INSERT INTO clstr_tst (b, c) VALUES (16, 'dieciseis');
INSERT INTO clstr_tst (b, c) VALUES (8, 'ocho');
INSERT INTO clstr_tst (b, c) VALUES (6, 'seis');
-- This entry is needed to test that TOASTED values are copied correctly.
INSERT INTO clstr_tst (b, c, d) VALUES (6, 'seis', repeat('xyzzy', 100000));
CLUSTER clstr_tst_c ON clstr_tst;
SELECT
*
from clstr_tst;
a | b | c
----+----+---------------
10 | 14 | catorce
18 | 5 | cinco
9 | 4 | cuatro
26 | 19 | diecinueve
12 | 18 | dieciocho
30 | 16 | dieciseis
24 | 17 | diecisiete
2 | 10 | diez
23 | 12 | doce
11 | 2 | dos
25 | 9 | nueve
31 | 8 | ocho
1 | 11 | once
28 | 15 | quince
32 | 6 | seis
29 | 7 | siete
15 | 13 | trece
22 | 30 | treinta
17 | 32 | treinta y dos
3 | 31 | treinta y uno
5 | 3 | tres
20 | 1 | uno
6 | 20 | veinte
14 | 25 | veinticinco
21 | 24 | veinticuatro
4 | 22 | veintidos
19 | 29 | veintinueve
16 | 28 | veintiocho
27 | 26 | veintiseis
13 | 27 | veintisiete
7 | 23 | veintitres
8 | 21 | veintiuno
SELECT
a,b,c,substring(d for 30), length(d)
from clstr_tst;
a | b | c
| substring | length
----+----+---------------
+--------------------------------+--------
10 | 14 | catorce
| |
18 | 5 | cinco
| |
9 | 4 | cuatro
| |
26 | 19 | diecinueve
| |
12 | 18 | dieciocho
| |
30 | 16 | dieciseis
| |
24 | 17 | diecisiete
| |
2 | 10 | diez
| |
23 | 12 | doce
| |
11 | 2 | dos
| |
25 | 9 | nueve
| |
31 | 8 | ocho
| |
1 | 11 | once
| |
28 | 15 | quince
| |
32 | 6 | seis
| xyzzyxyzzyxyzzyxyzzyxyzzyxyzzy | 500000
29 | 7 | siete
| |
15 | 13 | trece
| |
22 | 30 | treinta
| |
17 | 32 | treinta y dos
| |
3 | 31 | treinta y uno
| |
5 | 3 | tres
| |
20 | 1 | uno
| |
6 | 20 | veinte
| |
14 | 25 | veinticinco
| |
21 | 24 | veinticuatro
| |
4 | 22 | veintidos
| |
19 | 29 | veintinueve
| |
16 | 28 | veintiocho
| |
27 | 26 | veintiseis
| |
13 | 27 | veintisiete
| |
7 | 23 | veintitres
| |
8 | 21 | veintiuno
| |
(32 rows)
SELECT
*
from clstr_tst ORDER BY a;
a | b | c
----+----+---------------
1 | 11 | once
2 | 10 | diez
3 | 31 | treinta y uno
4 | 22 | veintidos
5 | 3 | tres
6 | 20 | veinte
7 | 23 | veintitres
8 | 21 | veintiuno
9 | 4 | cuatro
10 | 14 | catorce
11 | 2 | dos
12 | 18 | dieciocho
13 | 27 | veintisiete
14 | 25 | veinticinco
15 | 13 | trece
16 | 28 | veintiocho
17 | 32 | treinta y dos
18 | 5 | cinco
19 | 29 | veintinueve
20 | 1 | uno
21 | 24 | veinticuatro
22 | 30 | treinta
23 | 12 | doce
24 | 17 | diecisiete
25 | 9 | nueve
26 | 19 | diecinueve
27 | 26 | veintiseis
28 | 15 | quince
29 | 7 | siete
30 | 16 | dieciseis
31 | 8 | ocho
32 | 6 | seis
SELECT
a,b,c,substring(d for 30), length(d)
from clstr_tst ORDER BY a;
a | b | c
| substring | length
----+----+---------------
+--------------------------------+--------
1 | 11 | once
| |
2 | 10 | diez
| |
3 | 31 | treinta y uno
| |
4 | 22 | veintidos
| |
5 | 3 | tres
| |
6 | 20 | veinte
| |
7 | 23 | veintitres
| |
8 | 21 | veintiuno
| |
9 | 4 | cuatro
| |
10 | 14 | catorce
| |
11 | 2 | dos
| |
12 | 18 | dieciocho
| |
13 | 27 | veintisiete
| |
14 | 25 | veinticinco
| |
15 | 13 | trece
| |
16 | 28 | veintiocho
| |
17 | 32 | treinta y dos
| |
18 | 5 | cinco
| |
19 | 29 | veintinueve
| |
20 | 1 | uno
| |
21 | 24 | veinticuatro
| |
22 | 30 | treinta
| |
23 | 12 | doce
| |
24 | 17 | diecisiete
| |
25 | 9 | nueve
| |
26 | 19 | diecinueve
| |
27 | 26 | veintiseis
| |
28 | 15 | quince
| |
29 | 7 | siete
| |
30 | 16 | dieciseis
| |
31 | 8 | ocho
| |
32 | 6 | seis
| xyzzyxyzzyxyzzyxyzzyxyzzyxyzzy | 500000
(32 rows)
SELECT
*
from clstr_tst ORDER BY b;
a | b | c
----+----+---------------
20 | 1 | uno
11 | 2 | dos
5 | 3 | tres
9 | 4 | cuatro
18 | 5 | cinco
32 | 6 | seis
29 | 7 | siete
31 | 8 | ocho
25 | 9 | nueve
2 | 10 | diez
1 | 11 | once
23 | 12 | doce
15 | 13 | trece
10 | 14 | catorce
28 | 15 | quince
30 | 16 | dieciseis
24 | 17 | diecisiete
12 | 18 | dieciocho
26 | 19 | diecinueve
6 | 20 | veinte
8 | 21 | veintiuno
4 | 22 | veintidos
7 | 23 | veintitres
21 | 24 | veinticuatro
14 | 25 | veinticinco
27 | 26 | veintiseis
13 | 27 | veintisiete
16 | 28 | veintiocho
19 | 29 | veintinueve
22 | 30 | treinta
3 | 31 | treinta y uno
17 | 32 | treinta y dos
SELECT
a,b,c,substring(d for 30), length(d)
from clstr_tst ORDER BY b;
a | b | c
| substring | length
----+----+---------------
+--------------------------------+--------
20 | 1 | uno
| |
11 | 2 | dos
| |
5 | 3 | tres
| |
9 | 4 | cuatro
| |
18 | 5 | cinco
| |
32 | 6 | seis
| xyzzyxyzzyxyzzyxyzzyxyzzyxyzzy | 500000
29 | 7 | siete
| |
31 | 8 | ocho
| |
25 | 9 | nueve
| |
2 | 10 | diez
| |
1 | 11 | once
| |
23 | 12 | doce
| |
15 | 13 | trece
| |
10 | 14 | catorce
| |
28 | 15 | quince
| |
30 | 16 | dieciseis
| |
24 | 17 | diecisiete
| |
12 | 18 | dieciocho
| |
26 | 19 | diecinueve
| |
6 | 20 | veinte
| |
8 | 21 | veintiuno
| |
4 | 22 | veintidos
| |
7 | 23 | veintitres
| |
21 | 24 | veinticuatro
| |
14 | 25 | veinticinco
| |
27 | 26 | veintiseis
| |
13 | 27 | veintisiete
| |
16 | 28 | veintiocho
| |
19 | 29 | veintinueve
| |
22 | 30 | treinta
| |
3 | 31 | treinta y uno
| |
17 | 32 | treinta y dos
| |
(32 rows)
SELECT
*
from clstr_tst ORDER BY c;
a | b | c
----+----+---------------
10 | 14 | catorce
18 | 5 | cinco
9 | 4 | cuatro
26 | 19 | diecinueve
12 | 18 | dieciocho
30 | 16 | dieciseis
24 | 17 | diecisiete
2 | 10 | diez
23 | 12 | doce
11 | 2 | dos
25 | 9 | nueve
31 | 8 | ocho
1 | 11 | once
28 | 15 | quince
32 | 6 | seis
29 | 7 | siete
15 | 13 | trece
22 | 30 | treinta
17 | 32 | treinta y dos
3 | 31 | treinta y uno
5 | 3 | tres
20 | 1 | uno
6 | 20 | veinte
14 | 25 | veinticinco
21 | 24 | veinticuatro
4 | 22 | veintidos
19 | 29 | veintinueve
16 | 28 | veintiocho
27 | 26 | veintiseis
13 | 27 | veintisiete
7 | 23 | veintitres
8 | 21 | veintiuno
SELECT
a,b,c,substring(d for 30), length(d)
from clstr_tst ORDER BY c;
a | b | c
| substring | length
----+----+---------------
+--------------------------------+--------
10 | 14 | catorce
| |
18 | 5 | cinco
| |
9 | 4 | cuatro
| |
26 | 19 | diecinueve
| |
12 | 18 | dieciocho
| |
30 | 16 | dieciseis
| |
24 | 17 | diecisiete
| |
2 | 10 | diez
| |
23 | 12 | doce
| |
11 | 2 | dos
| |
25 | 9 | nueve
| |
31 | 8 | ocho
| |
1 | 11 | once
| |
28 | 15 | quince
| |
32 | 6 | seis
| xyzzyxyzzyxyzzyxyzzyxyzzyxyzzy | 500000
29 | 7 | siete
| |
15 | 13 | trece
| |
22 | 30 | treinta
| |
17 | 32 | treinta y dos
| |
3 | 31 | treinta y uno
| |
5 | 3 | tres
| |
20 | 1 | uno
| |
6 | 20 | veinte
| |
14 | 25 | veinticinco
| |
21 | 24 | veinticuatro
| |
4 | 22 | veintidos
| |
19 | 29 | veintinueve
| |
16 | 28 | veintiocho
| |
27 | 26 | veintiseis
| |
13 | 27 | veintisiete
| |
7 | 23 | veintitres
| |
8 | 21 | veintiuno
| |
(32 rows)
-- Verify that inheritance link still works
INSERT INTO clstr_tst_inh VALUES (0, 100, 'in child table');
SELECT
*
from clstr_tst;
a | b | c
----+-----+----------------
10 | 14 | catorce
18 | 5 | cinco
9 | 4 | cuatro
26 | 19 | diecinueve
12 | 18 | dieciocho
30 | 16 | dieciseis
24 | 17 | diecisiete
2 | 10 | diez
23 | 12 | doce
11 | 2 | dos
25 | 9 | nueve
31 | 8 | ocho
1 | 11 | once
28 | 15 | quince
32 | 6 | seis
29 | 7 | siete
15 | 13 | trece
22 | 30 | treinta
17 | 32 | treinta y dos
3 | 31 | treinta y uno
5 | 3 | tres
20 | 1 | uno
6 | 20 | veinte
14 | 25 | veinticinco
21 | 24 | veinticuatro
4 | 22 | veintidos
19 | 29 | veintinueve
16 | 28 | veintiocho
27 | 26 | veintiseis
13 | 27 | veintisiete
7 | 23 | veintitres
8 | 21 | veintiuno
0 | 100 | in child table
SELECT
a,b,c,substring(d for 30), length(d)
from clstr_tst;
a | b | c
| substring | length
----+-----+----------------
+--------------------------------+--------
10 | 14 | catorce
| |
18 | 5 | cinco
| |
9 | 4 | cuatro
| |
26 | 19 | diecinueve
| |
12 | 18 | dieciocho
| |
30 | 16 | dieciseis
| |
24 | 17 | diecisiete
| |
2 | 10 | diez
| |
23 | 12 | doce
| |
11 | 2 | dos
| |
25 | 9 | nueve
| |
31 | 8 | ocho
| |
1 | 11 | once
| |
28 | 15 | quince
| |
32 | 6 | seis
| xyzzyxyzzyxyzzyxyzzyxyzzyxyzzy | 500000
29 | 7 | siete
| |
15 | 13 | trece
| |
22 | 30 | treinta
| |
17 | 32 | treinta y dos
| |
3 | 31 | treinta y uno
| |
5 | 3 | tres
| |
20 | 1 | uno
| |
6 | 20 | veinte
| |
14 | 25 | veinticinco
| |
21 | 24 | veinticuatro
| |
4 | 22 | veintidos
| |
19 | 29 | veintinueve
| |
16 | 28 | veintiocho
| |
27 | 26 | veintiseis
| |
13 | 27 | veintisiete
| |
7 | 23 | veintitres
| |
8 | 21 | veintiuno
| |
0 | 100 | in child table
| |
(33 rows)
-- Verify that foreign key link still works
INSERT INTO clstr_tst (b, c) VALUES (1111, 'this should fail');
ERROR: clstr_tst_con referential integrity violation - key referenced from clstr_tst not found in clstr_tst_s
SELECT conname FROM pg_constraint WHERE conrelid=(SELECT oid FROM pg_class
WHERE relname='clstr_tst');
SELECT conname FROM pg_constraint WHERE conrelid = 'clstr_tst'::regclass;
conname
----------------
clstr_tst_pkey
clstr_tst_con
(2 rows)
SELECT relname FROM pg_class WHERE relname LIKE 'clstr_tst%' ORDER BY relname;
relname
----------------------
clstr_tst
clstr_tst_a_seq
clstr_tst_b
clstr_tst_b_c
clstr_tst_c
clstr_tst_c_b
clstr_tst_inh
clstr_tst_pkey
clstr_tst_s
clstr_tst_s_pkey
clstr_tst_s_rf_a_seq
SELECT relname, relkind,
EXISTS(SELECT 1 FROM pg_class WHERE oid = c.reltoastrelid) AS hastoast
FROM pg_class c WHERE relname LIKE 'clstr_tst%' ORDER BY relname;
relname | relkind | hastoast
----------------------+---------+----------
clstr_tst | r | t
clstr_tst_a_seq | S | f
clstr_tst_b | i | f
clstr_tst_b_c | i | f
clstr_tst_c | i | f
clstr_tst_c_b | i | f
clstr_tst_inh | r | t
clstr_tst_pkey | i | f
clstr_tst_s | r | f
clstr_tst_s_pkey | i | f
clstr_tst_s_rf_a_seq | S | f
(11 rows)
src/test/regress/sql/cluster.sql
浏览文件 @
e44beef7
...
...
@@ -8,6 +8,7 @@ CREATE TABLE clstr_tst_s (rf_a SERIAL PRIMARY KEY,
CREATE
TABLE
clstr_tst
(
a
SERIAL
PRIMARY
KEY
,
b
INT
,
c
TEXT
,
d
TEXT
,
CONSTRAINT
clstr_tst_con
FOREIGN
KEY
(
b
)
REFERENCES
clstr_tst_s
);
CREATE
INDEX
clstr_tst_b
ON
clstr_tst
(
b
);
...
...
@@ -55,24 +56,26 @@ INSERT INTO clstr_tst (b, c) VALUES (15, 'quince');
INSERT
INTO
clstr_tst
(
b
,
c
)
VALUES
(
7
,
'siete'
);
INSERT
INTO
clstr_tst
(
b
,
c
)
VALUES
(
16
,
'dieciseis'
);
INSERT
INTO
clstr_tst
(
b
,
c
)
VALUES
(
8
,
'ocho'
);
INSERT
INTO
clstr_tst
(
b
,
c
)
VALUES
(
6
,
'seis'
);
-- This entry is needed to test that TOASTED values are copied correctly.
INSERT
INTO
clstr_tst
(
b
,
c
,
d
)
VALUES
(
6
,
'seis'
,
repeat
(
'xyzzy'
,
100000
));
CLUSTER
clstr_tst_c
ON
clstr_tst
;
SELECT
*
from
clstr_tst
;
SELECT
*
from
clstr_tst
ORDER
BY
a
;
SELECT
*
from
clstr_tst
ORDER
BY
b
;
SELECT
*
from
clstr_tst
ORDER
BY
c
;
SELECT
a
,
b
,
c
,
substring
(
d
for
30
),
length
(
d
)
from
clstr_tst
;
SELECT
a
,
b
,
c
,
substring
(
d
for
30
),
length
(
d
)
from
clstr_tst
ORDER
BY
a
;
SELECT
a
,
b
,
c
,
substring
(
d
for
30
),
length
(
d
)
from
clstr_tst
ORDER
BY
b
;
SELECT
a
,
b
,
c
,
substring
(
d
for
30
),
length
(
d
)
from
clstr_tst
ORDER
BY
c
;
-- Verify that inheritance link still works
INSERT
INTO
clstr_tst_inh
VALUES
(
0
,
100
,
'in child table'
);
SELECT
*
from
clstr_tst
;
SELECT
a
,
b
,
c
,
substring
(
d
for
30
),
length
(
d
)
from
clstr_tst
;
-- Verify that foreign key link still works
INSERT
INTO
clstr_tst
(
b
,
c
)
VALUES
(
1111
,
'this should fail'
);
SELECT
conname
FROM
pg_constraint
WHERE
conrelid
=
(
SELECT
oid
FROM
pg_class
WHERE
relname
=
'clstr_tst'
);
SELECT
conname
FROM
pg_constraint
WHERE
conrelid
=
'clstr_tst'
::
regclass
;
SELECT
relname
FROM
pg_class
WHERE
relname
LIKE
'clstr_tst%'
ORDER
BY
relname
;
SELECT
relname
,
relkind
,
EXISTS
(
SELECT
1
FROM
pg_class
WHERE
oid
=
c
.
reltoastrelid
)
AS
hastoast
FROM
pg_class
c
WHERE
relname
LIKE
'clstr_tst%'
ORDER
BY
relname
;
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录