@@ -107,8 +107,13 @@ pick_suitable_index(Oid relation, AttrNumber column)
107107HeapTuple htup ;
108108SysScanDesc scan ;
109109Relation pg_index ;
110+ List * spoint2_opclass_name ;
111+ Oid spoint2_opclass ;
110112ScanKeyData key [3 ];
111113
114+ spoint2_opclass_name = stringToQualifiedNameList ("public.spoint2" );
115+ spoint2_opclass = get_opclass_oid (GIST_AM_OID ,spoint2_opclass_name , false);
116+
112117ScanKeyInit (& key [0 ],
113118Anum_pg_index_indrelid ,
114119BTEqualStrategyNumber ,
@@ -146,9 +151,18 @@ pick_suitable_index(Oid relation, AttrNumber column)
146151PointerGetDatum (cstring_to_text ("main" ))));
147152
148153if (found_index == InvalidOid || cur_index_size < found_index_size )
149- found_index = pg_ind -> indexrelid ;
150-
151- break ;/* no need to go further */
154+ {
155+ bool is_null ;
156+ Datum indclass = heap_getattr (htup ,Anum_pg_index_indclass ,
157+ pg_index -> rd_att ,& is_null );
158+ oidvector * indclasses = (oidvector * )DatumGetPointer (indclass );
159+
160+ /* column must use 'spoint2' opclass */
161+ if (!is_null && indclasses -> values [i ]== spoint2_opclass )
162+ found_index = pg_ind -> indexrelid ;
163+ }
164+
165+ break ;/* no need to scan 'indkey' further */
152166}
153167}
154168}