From b6baf06b67294ecb142cfa3ff526a6753b2fb415 Mon Sep 17 00:00:00 2001 From: Julien Rouhaud Date: Wed, 1 Jul 2015 16:52:29 +0200 Subject: [PATCH] Fix segfault when an expression is used. If an expression is used, just don't create an hypothetical index. An index on the remaining columns could be built, but it would not be intuitive, and it may not remain any column left. Thanks Thom Brown for reporting it. --- hypopg.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/hypopg.c b/hypopg.c index e8da0d1..df947e8 100644 --- a/hypopg.c +++ b/hypopg.c @@ -390,8 +390,30 @@ entry_store_parsetree(IndexStmt *node) int ncolumns; ListCell *lc; int j; + bool ok = true; + /* check first if there's an expression. + * the column list will probably be checked twice, but it avoids the need + * to worry about freeing memory later. + */ + foreach(lc, node->indexParams) + { + IndexElem *indexelem = (IndexElem *) lfirst(lc); + + if (indexelem->expr != NULL) + { + ok = false; + break; + } + } + + if (!ok) + { + elog(WARNING, "hypopg: hypothetical indexes on expression are not supported yet"); + return false; + } + ncolumns = list_length(node->indexParams); initStringInfo(&indexRelationName);