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

Commit554edcf

Browse files
committed
revert ALTER INDEX stuff
1 parentd69f106 commit554edcf

File tree

21 files changed

+39
-598
lines changed

21 files changed

+39
-598
lines changed

‎src/backend/commands/indexcmds.c‎

Lines changed: 0 additions & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
#include"commands/tablespace.h"
3535
#include"mb/pg_wchar.h"
3636
#include"miscadmin.h"
37-
#include"funcapi.h"
3837
#include"nodes/nodeFuncs.h"
3938
#include"optimizer/clauses.h"
4039
#include"optimizer/planner.h"
@@ -53,9 +52,6 @@
5352
#include"utils/snapmgr.h"
5453
#include"utils/syscache.h"
5554
#include"utils/tqual.h"
56-
#include"utils/ruleutils.h"
57-
#include"executor/executor.h"
58-
#include"executor/spi.h"
5955

6056

6157
/* non-export function prototypes */
@@ -284,160 +280,6 @@ CheckIndexCompatible(Oid oldId,
284280
returnret;
285281
}
286282

287-
staticvoid
288-
UpdateIndex(OidindexRelationId,Node*whereClause)
289-
{
290-
Datumvalues[Natts_pg_index];
291-
boolisnull[Natts_pg_index];
292-
HeapTupleoldTuple;
293-
HeapTuplenewTuple;
294-
Relationpg_index;
295-
296-
pg_index=heap_open(IndexRelationId,RowExclusiveLock);
297-
oldTuple=SearchSysCacheCopy1(INDEXRELID,ObjectIdGetDatum(indexRelationId));
298-
if (!HeapTupleIsValid(oldTuple))
299-
elog(ERROR,"cache lookup failed for index %u",indexRelationId);
300-
301-
heap_deform_tuple(oldTuple,RelationGetDescr(pg_index),values,isnull);
302-
values[Anum_pg_index_indpred-1]=CStringGetTextDatum(nodeToString(whereClause));
303-
isnull[Anum_pg_index_indpred-1]= false;
304-
newTuple=heap_form_tuple(RelationGetDescr(pg_index),values,isnull);
305-
simple_heap_update(pg_index,&oldTuple->t_self,newTuple);
306-
CatalogUpdateIndexes(pg_index,newTuple);
307-
heap_freetuple(newTuple);
308-
heap_freetuple(oldTuple);
309-
heap_close(pg_index,NoLock);
310-
}
311-
312-
void
313-
AlterIndex(OidindexRelationId,IndexStmt*stmt)
314-
{
315-
char*select;
316-
OidheapRelationId;
317-
IndexUniqueCheckcheckUnique;
318-
Datumvalues[INDEX_MAX_KEYS];
319-
boolisnull[INDEX_MAX_KEYS];
320-
RelationheapRelation;
321-
RelationindexRelation;
322-
SPIPlanPtrplan;
323-
Portalportal;
324-
HeapTupletuple;
325-
TupleTableSlot*slot;
326-
ItemPointertupleid;
327-
IndexInfo*indexInfo;
328-
EState*estate;
329-
OidnamespaceId;
330-
List*deparseCtx;
331-
char*oldIndexPredicate;
332-
char*newIndexPredicate;
333-
char*relationName;
334-
335-
Assert(stmt->whereClause);
336-
CheckPredicate((Expr*)stmt->whereClause);
337-
338-
/* Open and lock the parent heap relation */
339-
heapRelationId=IndexGetRelation(indexRelationId, false);
340-
heapRelation=heap_open(heapRelationId,AccessShareLock);
341-
342-
/* Open the target index relation */
343-
/*indexRelation = index_open(indexRelationId, RowExclusiveLock); */
344-
indexRelation=index_open(indexRelationId,ShareUpdateExclusiveLock);
345-
/* indexRelation = index_open(indexRelationId, AccessShareLock); */
346-
namespaceId=RelationGetNamespace(indexRelation);
347-
348-
indexInfo=BuildIndexInfo(indexRelation);
349-
Assert(!indexInfo->ii_ExclusionOps);
350-
351-
/*
352-
* Generate the constraint and default execution states
353-
*/
354-
estate=CreateExecutorState();
355-
356-
checkUnique=indexRelation->rd_index->indisunique ?UNIQUE_CHECK_YES :UNIQUE_CHECK_NO;
357-
358-
slot=MakeSingleTupleTableSlot(RelationGetDescr(heapRelation));
359-
360-
deparseCtx=deparse_context_for(RelationGetRelationName(heapRelation),heapRelationId);
361-
relationName=quote_qualified_identifier(get_namespace_name(namespaceId),
362-
get_rel_name(heapRelationId)),
363-
newIndexPredicate=deparse_expression(stmt->whereClause,deparseCtx, false, false);
364-
oldIndexPredicate=indexInfo->ii_Predicate
365-
?deparse_expression((Node*)make_ands_explicit(indexInfo->ii_Predicate),deparseCtx, false, false)
366-
:"true";
367-
368-
SPI_connect();
369-
370-
select=psprintf("select * from %s where %s and not (%s) limit 1",
371-
relationName,oldIndexPredicate,newIndexPredicate);
372-
if (SPI_execute(select, true,1)!=SPI_OK_SELECT)
373-
{
374-
ereport(ERROR,
375-
(errcode(ERRCODE_INVALID_CURSOR_STATE),
376-
errmsg("Failed to execute statement %s",select)));
377-
}
378-
if (SPI_processed) {
379-
/* There is no way in Postgres to exclude records from index, so we have to completelty rebuild index in this case */
380-
boolrelpersistence=indexRelation->rd_rel->relpersistence;
381-
index_close(indexRelation,NoLock);
382-
indexRelation->rd_indpred=make_ands_implicit((Expr*)stmt->whereClause);
383-
indexRelation=NULL;
384-
UpdateIndex(indexRelationId,stmt->whereClause);
385-
reindex_index(indexRelationId, false,relpersistence,0);
386-
}else {
387-
select=psprintf("select * from %s where %s and not (%s)",
388-
relationName,newIndexPredicate,oldIndexPredicate);
389-
plan=SPI_prepare(select,0,NULL);
390-
if (plan==NULL) {
391-
ereport(ERROR,
392-
(errcode(ERRCODE_INVALID_CURSOR_STATE),
393-
errmsg("Failed to preapre statement %s",select)));
394-
}
395-
portal=SPI_cursor_open(NULL,plan,NULL,NULL, true);
396-
if (portal==NULL) {
397-
ereport(ERROR,
398-
(errcode(ERRCODE_INVALID_CURSOR_STATE),
399-
errmsg("Failed to open cursor for %s",select)));
400-
}
401-
while (true)
402-
{
403-
SPI_cursor_fetch(portal, true,1);
404-
if (!SPI_processed) {
405-
break;
406-
}
407-
tuple=SPI_tuptable->vals[0];
408-
tupleid=&tuple->t_data->t_ctid;
409-
ExecStoreTuple(tuple,slot,InvalidBuffer, false);
410-
411-
FormIndexDatum(indexInfo,
412-
slot,
413-
estate,
414-
values,
415-
isnull);
416-
index_insert(indexRelation,/* index relation */
417-
values,/* array of index Datums */
418-
isnull,/* null flags */
419-
tupleid,/* tid of heap tuple */
420-
heapRelation,/* heap relation */
421-
checkUnique);/* type of uniqueness check to do */
422-
423-
SPI_freetuple(tuple);
424-
SPI_freetuptable(SPI_tuptable);
425-
}
426-
SPI_cursor_close(portal);
427-
428-
UpdateIndex(indexRelationId,stmt->whereClause);
429-
}
430-
SPI_finish();
431-
432-
ExecDropSingleTupleTableSlot(slot);
433-
FreeExecutorState(estate);
434-
435-
heap_close(heapRelation,NoLock);
436-
if (indexRelation) {
437-
index_close(indexRelation,NoLock);
438-
}
439-
}
440-
441283
/*
442284
* DefineIndex
443285
*Creates a new index.

‎src/backend/nodes/copyfuncs.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3128,7 +3128,6 @@ _copyIndexStmt(const IndexStmt *from)
31283128
COPY_SCALAR_FIELD(transformed);
31293129
COPY_SCALAR_FIELD(concurrent);
31303130
COPY_SCALAR_FIELD(if_not_exists);
3131-
COPY_SCALAR_FIELD(is_alter);
31323131

31333132
returnnewnode;
31343133
}

‎src/backend/nodes/equalfuncs.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1243,7 +1243,6 @@ _equalIndexStmt(const IndexStmt *a, const IndexStmt *b)
12431243
COMPARE_SCALAR_FIELD(transformed);
12441244
COMPARE_SCALAR_FIELD(concurrent);
12451245
COMPARE_SCALAR_FIELD(if_not_exists);
1246-
COMPARE_SCALAR_FIELD(is_alter);
12471246

12481247
return true;
12491248
}

‎src/backend/nodes/outfuncs.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2191,7 +2191,6 @@ _outIndexStmt(StringInfo str, const IndexStmt *node)
21912191
WRITE_BOOL_FIELD(transformed);
21922192
WRITE_BOOL_FIELD(concurrent);
21932193
WRITE_BOOL_FIELD(if_not_exists);
2194-
WRITE_BOOL_FIELD(is_alter);
21952194
}
21962195

21972196
staticvoid

‎src/backend/optimizer/path/costsize.c‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@
8989
#include"optimizer/placeholder.h"
9090
#include"optimizer/plancat.h"
9191
#include"optimizer/planmain.h"
92-
#include"optimizer/predtest.h"
9392
#include"optimizer/restrictinfo.h"
9493
#include"parser/parsetree.h"
9594
#include"utils/lsyscache.h"
@@ -430,7 +429,7 @@ cost_index(IndexPath *path, PlannerInfo *root, double loop_count)
430429
path->path.rows=path->path.param_info->ppi_rows;
431430
/* qpquals come from the rel's restriction clauses and ppi_clauses */
432431
qpquals=list_concat(
433-
extract_nonindex_conditions(path->indexrinfos,
432+
extract_nonindex_conditions(baserel->baserestrictinfo,
434433
path->indexquals),
435434
extract_nonindex_conditions(path->path.param_info->ppi_clauses,
436435
path->indexquals));
@@ -439,7 +438,7 @@ cost_index(IndexPath *path, PlannerInfo *root, double loop_count)
439438
{
440439
path->path.rows=baserel->rows;
441440
/* qpquals come from just the rel's restriction clauses */
442-
qpquals=extract_nonindex_conditions(path->indexrinfos,
441+
qpquals=extract_nonindex_conditions(baserel->baserestrictinfo,
443442
path->indexquals);
444443
}
445444

@@ -640,7 +639,6 @@ extract_nonindex_conditions(List *qual_clauses, List *indexquals)
640639
continue;/* simple duplicate */
641640
if (is_redundant_derived_clause(rinfo,indexquals))
642641
continue;/* derived from same EquivalenceClass */
643-
644642
/* ... skip the predicate proof attempts createplan.c will try ... */
645643
result=lappend(result,rinfo);
646644
}

‎src/backend/optimizer/path/indxpath.c‎

Lines changed: 12 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ typedef struct
5959
boolnonempty;/* True if lists are not all empty */
6060
/* Lists of RestrictInfos, one per index column */
6161
List*indexclauses[INDEX_MAX_KEYS];
62-
List*indexrinfos;/* clauses not implied by predicate */
6362
}IndexClauseSet;
6463

6564
/* Per-path data used within choose_bitmap_and() */
@@ -130,7 +129,7 @@ static PathClauseUsage *classify_index_clause_usage(Path *path,
130129
staticRelidsget_bitmap_tree_required_outer(Path*bitmapqual);
131130
staticvoidfind_indexpath_quals(Path*bitmapqual,List**quals,List**preds);
132131
staticintfind_list_position(Node*node,List**nodelist);
133-
staticboolcheck_index_only(RelOptInfo*rel,IndexOptInfo*index,List*clauses);
132+
staticboolcheck_index_only(RelOptInfo*rel,IndexOptInfo*index);
134133
staticdoubleget_loop_count(PlannerInfo*root,Indexcur_relid,Relidsouter_relids);
135134
staticdoubleadjust_rowcount_for_semijoins(PlannerInfo*root,
136135
Indexcur_relid,
@@ -867,7 +866,6 @@ build_index_paths(PlannerInfo *root, RelOptInfo *rel,
867866
doubleloop_count;
868867
List*orderbyclauses;
869868
List*orderbyclausecols;
870-
List*restrictinfo;
871869
List*index_pathkeys;
872870
List*useful_pathkeys;
873871
boolfound_lower_saop_clause;
@@ -1015,16 +1013,13 @@ build_index_paths(PlannerInfo *root, RelOptInfo *rel,
10151013
orderbyclausecols=NIL;
10161014
}
10171015

1018-
restrictinfo
1019-
= (index->indpred!=NIL) ?clauses->indexrinfos :rel->baserestrictinfo;
1020-
10211016
/*
10221017
* 3. Check if an index-only scan is possible. If we're not building
10231018
* plain indexscans, this isn't relevant since bitmap scans don't support
10241019
* index data retrieval anyway.
10251020
*/
10261021
index_only_scan= (scantype!=ST_BITMAPSCAN&&
1027-
check_index_only(rel,index,restrictinfo));
1022+
check_index_only(rel,index));
10281023

10291024
/*
10301025
* 4. Generate an indexscan path if there are relevant restriction clauses
@@ -1038,7 +1033,6 @@ build_index_paths(PlannerInfo *root, RelOptInfo *rel,
10381033
ipath=create_index_path(root,index,
10391034
index_clauses,
10401035
clause_columns,
1041-
restrictinfo,
10421036
orderbyclauses,
10431037
orderbyclausecols,
10441038
useful_pathkeys,
@@ -1065,7 +1059,6 @@ build_index_paths(PlannerInfo *root, RelOptInfo *rel,
10651059
ipath=create_index_path(root,index,
10661060
index_clauses,
10671061
clause_columns,
1068-
restrictinfo,
10691062
NIL,
10701063
NIL,
10711064
useful_pathkeys,
@@ -1789,7 +1782,7 @@ find_list_position(Node *node, List **nodelist)
17891782
*Determine whether an index-only scan is possible for this index.
17901783
*/
17911784
staticbool
1792-
check_index_only(RelOptInfo*rel,IndexOptInfo*index,List*clauses)
1785+
check_index_only(RelOptInfo*rel,IndexOptInfo*index)
17931786
{
17941787
boolresult;
17951788
Bitmapset*attrs_used=NULL;
@@ -1805,13 +1798,13 @@ check_index_only(RelOptInfo *rel, IndexOptInfo *index, List *clauses)
18051798
* Check that all needed attributes of the relation are available from the
18061799
* index.
18071800
*
1808-
*For partial indexes we won't consider attributes involved in clauses
1809-
*implied bythe index predicate, asthose won't be needed at runtime.
1810-
*
1811-
*XXX The same istrue for attributes used only in index quals, if we
1812-
*are certain thatthe index is not lossy.However, it would be quite
1813-
*expensive todetermine that accurately at this point, so for now we
1814-
*take the easyway out.
1801+
*XXX this is overly conservative for partial indexes, since we will
1802+
*consider attributes involved inthe index predicate asrequired even
1803+
* though the predicate won't need to be checked at runtime. (The same is
1804+
* true for attributes used only in index quals, if we are certain that
1805+
* the index is not lossy.)However, it would be quite expensive to
1806+
* determine that accurately at this point, so for now we take the easy
1807+
* way out.
18151808
*/
18161809

18171810
/*
@@ -1821,11 +1814,8 @@ check_index_only(RelOptInfo *rel, IndexOptInfo *index, List *clauses)
18211814
*/
18221815
pull_varattnos((Node*)rel->reltargetlist,rel->relid,&attrs_used);
18231816

1824-
/*
1825-
* Add all the attributes used by restriction clauses (only those not
1826-
* implied by the index predicate for partial indexes).
1827-
*/
1828-
foreach(lc,clauses)
1817+
/* Add all the attributes used by restriction clauses. */
1818+
foreach(lc,rel->baserestrictinfo)
18291819
{
18301820
RestrictInfo*rinfo= (RestrictInfo*)lfirst(lc);
18311821

@@ -2130,14 +2120,6 @@ match_clauses_to_index(IndexOptInfo *index,
21302120
* If the clause is usable, add it to the appropriate list in *clauseset.
21312121
* *clauseset must be initialized to zeroes before first call.
21322122
*
2133-
* For partial indexes we ignore clauses that are implied by the index
2134-
* predicate - no need to to re-evaluate those, and the columns may not
2135-
* even be included in the index itself.
2136-
*
2137-
* We also build a list of clauses that are not implied by the index
2138-
* predicate so that we don't need calling predicate_implied_by again
2139-
* (e.g. in check_index_only).
2140-
*
21412123
* Note: in some circumstances we may find the same RestrictInfos coming from
21422124
* multiple places. Defend against redundant outputs by refusing to add a
21432125
* clause twice (pointer equality should be a good enough check for this).
@@ -2154,16 +2136,6 @@ match_clause_to_index(IndexOptInfo *index,
21542136
{
21552137
intindexcol;
21562138

2157-
if (index->indpred!=NIL)
2158-
{
2159-
if (predicate_implied_by(list_make1(rinfo->clause),
2160-
index->indpred))
2161-
return;
2162-
2163-
/* track non-implied restriction clauses */
2164-
clauseset->indexrinfos=lappend(clauseset->indexrinfos,rinfo);
2165-
}
2166-
21672139
for (indexcol=0;indexcol<index->ncolumns;indexcol++)
21682140
{
21692141
if (match_clause_to_indexcol(index,

‎src/backend/optimizer/plan/planner.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4758,7 +4758,7 @@ plan_cluster_use_sort(Oid tableOid, Oid indexOid)
47584758

47594759
/* Estimate the cost of index scan */
47604760
indexScanPath=create_index_path(root,indexInfo,
4761-
NIL,NIL,NIL,NIL,NIL,NIL,
4761+
NIL,NIL,NIL,NIL,NIL,
47624762
ForwardScanDirection, false,
47634763
NULL,1.0);
47644764

‎src/backend/optimizer/util/pathnode.c‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,6 @@ create_index_path(PlannerInfo *root,
993993
IndexOptInfo*index,
994994
List*indexclauses,
995995
List*indexclausecols,
996-
List*indexrinfos,
997996
List*indexorderbys,
998997
List*indexorderbycols,
999998
List*pathkeys,
@@ -1025,7 +1024,6 @@ create_index_path(PlannerInfo *root,
10251024
pathnode->indexclauses=indexclauses;
10261025
pathnode->indexquals=indexquals;
10271026
pathnode->indexqualcols=indexqualcols;
1028-
pathnode->indexrinfos=indexrinfos;
10291027
pathnode->indexorderbys=indexorderbys;
10301028
pathnode->indexorderbycols=indexorderbycols;
10311029
pathnode->indexscandir=indexscandir;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp