10000 check first index column · postgrespro/pgsphere@7bc3591 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7bc3591

Browse files
committed
check first index column
1 parent 5ba59b9 commit 7bc3591

File tree

1 file changed

+16
-24
lines changed

1 file changed

+16
-24
lines changed

init.c

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -205,36 +205,28 @@ pick_suitable_index(Oid relation, AttrNumber column)
205205
index_am = index->rd_rel->relam;
206206
index_close(index, AccessShareLock);
207207

208-
/* check if this is a valid GIST index with no predicates */
208+
/*
209+
* check if this is a valid GIST index with no predicates and
210+
* its first column is the required spoint with opclass 'spoint2'.
211+
*/
209212
if (index_am == GIST_AM_OID && pg_ind->indisvalid &&
210-
heap_attisnull(htup, Anum_pg_index_indpred))
213+
heap_attisnull(htup, Anum_pg_index_indpred) &&
214+
pg_ind->indkey.dim1 >= 1 && pg_ind->indkey.values[0] == column)
211215
{
212-
int i;
216+
int64 cur_index_size = get_index_size(pg_ind->indexrelid);
213217

214-
for (i = 0; i < pg_ind->indkey.dim1; i++)
218+
if (found_index == InvalidOid || cur_index_size < found_index_size)
215219
{
216-
int64 cur_index_size = 0;
220+
bool is_null;
221+
Datum indclass = heap_getattr(htup, Anum_pg_index_indclass,
222+
pg_index->rd_att, &is_null);
223+
oidvector *indclasses = (oidvector *) DatumGetPointer(indclass);
217224

218-
if (pg_ind->indkey.values[i] == column)
225+
/* column must use 'spoint2' opclass */
226+
if (!is_null && indclasses->values[0] == spoint2_opclass)
219227
{
220-
cur_index_size = get_index_size(pg_ind->indexrelid);
221-
222-
if (found_index == InvalidOid || cur_index_size < found_index_size)
223-
{
224-
bool is_null;
225-
Datum indclass = heap_getattr(htup, Anum_pg_index_indclass,
226-
pg_index->rd_att, &is_null);
227-
oidvector *indclasses = (oidvector *) DatumGetPointer(indclass);
228-
229-
/* column must use 'spoint2' opclass */
230-
if (!is_null && indclasses->values[i] == spoint2_opclass)
231-
{
232-
found_index = pg_ind->indexrelid;
233-
found_index_size = cur_index_size;
234-
}
235-
}
236-
237-
break; /* no need to scan 'indkey' further */
228+
found_index = pg_ind->indexrelid;
229+
found_index_size = cur_index_size;
238230
}
239231
}
240232
}

0 commit comments

Comments
 (0)
0