Make sure unique or multicol index are allowed

This commit is contained in:
Julien Rouhaud 2016-11-15 16:20:07 +01:00
parent 59e02ae069
commit beb223ab41
2 changed files with 18 additions and 1 deletions

View file

@ -24,7 +24,7 @@ Less important
- [ ] specify tablespace
- [ ] Compatibility PG 9.2-
- [ ] handle unique index, still need to see if there is an impact somewhere...
- [X] handle unique index
- [X] handle reverse and nulls first
- [X] handle index on expression
- [X] handle index on predicate

View file

@ -138,6 +138,8 @@ typedef struct hypoEntry
bool amsearchnulls; /* can AM search for NULL/NOT NULL entries? */
bool amhasgettuple; /* does AM have amgettuple interface? */
bool amhasgetbitmap; /* does AM have amgetbitmap interface? */
bool amcanunique; /* does AM support UNIQUE indexes? */
bool amcanmulticol; /* does AM support multi-column indexes? */
/* store some informations usually saved in catalogs */
List *options; /* WITH clause options: a list of DefElem */
@ -312,6 +314,8 @@ hypo_newEntry(Oid relid, char *accessMethod, int ncolumns, List *options)
entry->amsearchnulls = amroutine->amsearchnulls;
entry->amhasgettuple = OidIsValid(amroutine->amgettuple);
entry->amhasgetbitmap = OidIsValid(amroutine->amgetbitmap);
entry->amcanunique = amroutine->amcanunique;
entry->amcanmulticol = amroutine->amcanmulticol;
amoptions = amroutine->amoptions;
entry->amcanorder = amroutine->amcanorder;
#else
@ -324,6 +328,8 @@ hypo_newEntry(Oid relid, char *accessMethod, int ncolumns, List *options)
entry->amsearchnulls = ((Form_pg_am) GETSTRUCT(tuple))->amsearchnulls;
entry->amhasgettuple = OidIsValid(((Form_pg_am) GETSTRUCT(tuple))->amgettuple);
entry->amhasgetbitmap = OidIsValid(((Form_pg_am) GETSTRUCT(tuple))->amgetbitmap);
entry->amcanunique = ((Form_pg_am) GETSTRUCT(tuple))->amcanunique;
entry->amcanmulticol = ((Form_pg_am) GETSTRUCT(tuple))->amcanmulticol;
amoptions = ((Form_pg_am) GETSTRUCT(tuple))->amoptions;
entry->amcanorder = ((Form_pg_am) GETSTRUCT(tuple))->amcanorder;
#endif
@ -539,6 +545,17 @@ hypo_entry_store_parsetree(IndexStmt *node, const char *queryString)
HeapTuple tuple;
int ind_avg_width = 0;
if (node->unique && !entry->amcanunique)
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("hypopg: access method \"%s\" does not support unique indexes",
node->accessMethod)));
if (ncolumns > 1 && !entry->amcanmulticol)
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("hypopg: access method \"%s\" does not support multicolumn indexes",
node->accessMethod)));
entry->unique = node->unique;
entry->ncolumns = ncolumns;