Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb7edbdf

Browse files
committed
Merge branch 'CORE-155-covering-indexes' of gitlab.postgrespro.ru:pgpro-dev/postgrespro into CORE-155-covering-indexes
2 parents52ccd00 +8e6554b commitb7edbdf

File tree

4 files changed

+47
-6
lines changed

4 files changed

+47
-6
lines changed

‎contrib/dblink/dblink.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2058,7 +2058,7 @@ get_pkey_attnames(Relation rel, int16 *numatts)
20582058
/* we're only interested if it is the primary key */
20592059
if (index->indisprimary)
20602060
{
2061-
*numatts=index->indnatts;
2061+
*numatts=index->indnkeyatts;
20622062
if (*numatts>0)
20632063
{
20642064
result= (char**)palloc(*numatts*sizeof(char*));

‎src/backend/catalog/index.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ UpdateIndexRelation(Oid indexoid,
564564
for (i=0;i<indexInfo->ii_NumIndexAttrs;i++)
565565
indkey->values[i]=indexInfo->ii_KeyAttrNumbers[i];
566566
indcollation=buildoidvector(collationOids,indexInfo->ii_NumIndexAttrs);
567-
indclass=buildoidvector(classOids,indexInfo->ii_NumIndexAttrs);
567+
indclass=buildoidvector(classOids,indexInfo->ii_NumIndexKeyAttrs);
568568
indoption=buildint2vector(coloptions,indexInfo->ii_NumIndexAttrs);
569569

570570
/*

‎src/backend/commands/indexcmds.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ DefineIndex(Oid relationId,
578578

579579
typeObjectId= (Oid*)palloc(numberOfAttributes*sizeof(Oid));
580580
collationObjectId= (Oid*)palloc(numberOfAttributes*sizeof(Oid));
581-
classObjectId= (Oid*)palloc(numberOfAttributes*sizeof(Oid));
581+
classObjectId= (Oid*)palloc(numberOfKeyAttributes*sizeof(Oid));
582582
coloptions= (int16*)palloc(numberOfAttributes*sizeof(int16));
583583
ComputeIndexAttrs(indexInfo,
584584
typeObjectId,collationObjectId,classObjectId,
@@ -1128,6 +1128,16 @@ ComputeIndexAttrs(IndexInfo *indexInfo,
11281128

11291129
collationOidP[attn]=attcollation;
11301130

1131+
/*
1132+
* Skip opclass and ordering options for included columns.
1133+
*/
1134+
if (attn >=nkeycols)
1135+
{
1136+
colOptionP[attn]=0;
1137+
attn++;
1138+
continue;
1139+
}
1140+
11311141
/*
11321142
* Identify the opclass to use.
11331143
*/

‎src/backend/parser/parse_utilcmd.c

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,14 +1193,14 @@ generateClonedIndexStmt(CreateStmtContext *cxt, Relation source_idx,
11931193

11941194
/* Build the list of IndexElem */
11951195
index->indexParams=NIL;
1196+
index->indexIncludingParams=NIL;
11961197

11971198
indexpr_item=list_head(indexprs);
1198-
for (keyno=0;keyno<idxrec->indnatts;keyno++)
1199+
for (keyno=0;keyno<idxrec->indnkeyatts;keyno++)
11991200
{
12001201
IndexElem*iparam;
12011202
AttrNumberattnum=idxrec->indkey.values[keyno];
12021203
int16opt=source_idx->rd_indoption[keyno];
1203-
12041204
iparam=makeNode(IndexElem);
12051205

12061206
if (AttributeNumberIsValid(attnum))
@@ -1282,6 +1282,36 @@ generateClonedIndexStmt(CreateStmtContext *cxt, Relation source_idx,
12821282
index->indexParams=lappend(index->indexParams,iparam);
12831283
}
12841284

1285+
/* Handle included columns separately */
1286+
for (keyno=idxrec->indnkeyatts;keyno<idxrec->indnatts;keyno++)
1287+
{
1288+
IndexElem*iparam;
1289+
AttrNumberattnum=idxrec->indkey.values[keyno];
1290+
1291+
iparam=makeNode(IndexElem);
1292+
1293+
if (AttributeNumberIsValid(attnum))
1294+
{
1295+
/* Simple index column */
1296+
char*attname;
1297+
1298+
attname=get_relid_attribute_name(indrelid,attnum);
1299+
keycoltype=get_atttype(indrelid,attnum);
1300+
1301+
iparam->name=attname;
1302+
iparam->expr=NULL;
1303+
}
1304+
else
1305+
elog(ERROR,"Expressions are not supported in included columns.");
1306+
1307+
/* Copy the original index column name */
1308+
iparam->indexcolname=pstrdup(NameStr(attrs[keyno]->attname));
1309+
1310+
/* Add the collation name, if non-default */
1311+
iparam->collation=get_collation(indcollation->values[keyno],keycoltype);
1312+
1313+
index->indexIncludingParams=lappend(index->indexIncludingParams,iparam);
1314+
}
12851315
/* Copy reloptions if any */
12861316
datum=SysCacheGetAttr(RELOID,ht_idxrel,
12871317
Anum_pg_class_reloptions,&isnull);
@@ -1544,6 +1574,7 @@ transformIndexConstraint(Constraint *constraint, CreateStmtContext *cxt)
15441574
index->tableSpace=constraint->indexspace;
15451575
index->whereClause=constraint->where_clause;
15461576
index->indexParams=NIL;
1577+
index->indexIncludingParams=NIL;
15471578
index->excludeOpNames=NIL;
15481579
index->idxcomment=NULL;
15491580
index->indexOid=InvalidOid;
@@ -1671,7 +1702,7 @@ transformIndexConstraint(Constraint *constraint, CreateStmtContext *cxt)
16711702
Assert(!isnull);
16721703
indclass= (oidvector*)DatumGetPointer(indclassDatum);
16731704

1674-
for (i=0;i<index_form->indnatts;i++)
1705+
for (i=0;i<index_form->indnkeyatts;i++)
16751706
{
16761707
int16attnum=index_form->indkey.values[i];
16771708
Form_pg_attributeattform;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp