On the list of indexes of a table show which were created as part of the creation of a constraint

The explicit column is true when the index was manually created
In SQL only a comment is given that the index was implicitly created
This commit is contained in:
eelke 2021-04-11 07:56:37 +02:00
parent 60bbb4c445
commit fd5ad9bbf0
6 changed files with 56 additions and 20 deletions

View file

@ -1,6 +1,8 @@
#include "PgIndex.h"
#include "PgDatabaseCatalog.h"
#include "PgClassContainer.h"
#include "PgConstraint.h"
#include "PgConstraintContainer.h"
#include "PgAmContainer.h"
#include <QStringBuilder>
@ -19,6 +21,8 @@ QString PgIndex::getAm() const
QString PgIndex::createSql() const
{
if (isSupportingIndex())
return "-- implicitly created index";
return definition + ";";
// const PgClass *table_class = catalog.classes()->getByKey(index.relid);
@ -69,7 +73,10 @@ QString PgIndex::createSql() const
QString PgIndex::dropSql() const
{
QString result;
if (isSupportingIndex())
return "-- implicitly created index";
QString result;
result = "DROP INDEX "
% fullyQualifiedQuotedObjectName()
% ";";
@ -78,5 +85,19 @@ QString PgIndex::dropSql() const
QString PgIndex::typeName() const
{
return "INDEX";
return "INDEX";
}
bool PgIndex::isSupportingIndex() const
{
// This function looks at the supporting index for constaints but this is not completely the
// same thing. For example a fkey is supported by a unique constraint on the referred table but this
// index has not been created as part of the constraint creation so it does not count.
//
// For now we assume that when the constraint and index are on the same table the index was created
// implicitly.
auto c = catalog().constraints()->getSupportedByIndex(oid());
auto find_result = std::find_if(c.begin(), c.end(), [this] (auto && item) { return item.relid == relid; });
return (find_result != c.end());
}