2017-12-17 11:28:20 +01:00
|
|
|
|
#include "PgIndex.h"
|
2018-08-25 18:11:12 +02:00
|
|
|
|
#include "PgDatabaseCatalog.h"
|
|
|
|
|
|
#include "PgClassContainer.h"
|
|
|
|
|
|
#include "PgAmContainer.h"
|
2018-11-30 18:41:38 +01:00
|
|
|
|
#include <QStringBuilder>
|
2017-12-16 21:43:51 +01:00
|
|
|
|
|
2018-08-25 18:11:12 +02:00
|
|
|
|
QString PgIndex::getAm() const
|
|
|
|
|
|
{
|
2018-11-18 19:30:45 +01:00
|
|
|
|
auto&& cat = catalog();
|
2018-08-25 18:11:12 +02:00
|
|
|
|
QString result;
|
2018-11-25 19:45:06 +01:00
|
|
|
|
auto idxcls = cat.classes()->getByKey(oid());
|
2018-11-18 19:30:45 +01:00
|
|
|
|
if (idxcls) {
|
|
|
|
|
|
auto am = cat.ams()->getByKey(idxcls->am);
|
|
|
|
|
|
if (am)
|
2018-11-25 19:45:06 +01:00
|
|
|
|
result = am->name; // objectName();
|
2018-08-25 18:11:12 +02:00
|
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
|
|
|
}
|
2018-11-30 18:41:38 +01:00
|
|
|
|
|
|
|
|
|
|
QString PgIndex::createSql() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return definition + ";";
|
|
|
|
|
|
|
|
|
|
|
|
// const PgClass *table_class = catalog.classes()->getByKey(index.relid);
|
|
|
|
|
|
// const PgClass *index_class = catalog.classes()->getByKey(index.indexrelid);
|
|
|
|
|
|
|
|
|
|
|
|
// QString result;
|
|
|
|
|
|
// result = "CREATE ";
|
|
|
|
|
|
// if (index.isunique)
|
|
|
|
|
|
// result += "UNIQUE ";
|
|
|
|
|
|
// result += "INDEX "
|
|
|
|
|
|
//// % quoteIdent(getIndexDisplayString(catalog, index.indexrelid))
|
|
|
|
|
|
// % quoteIdent(index_class.name)
|
|
|
|
|
|
// % "\n ON " % genFQTableName(catalog, table_class);
|
|
|
|
|
|
//// % "\n USING " % index_class.am lookup in pg_am table
|
|
|
|
|
|
// return result;
|
|
|
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
|
|
+ wxT("\n USING ") + GetIndexType()
|
|
|
|
|
|
+ wxT("\n (");
|
|
|
|
|
|
if (GetProcName().IsNull())
|
|
|
|
|
|
str += GetQuotedColumns();
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
str += GetQuotedSchemaPrefix(GetProcNamespace()) + qtIdent(GetProcName()) + wxT("(") + GetQuotedColumns() + wxT(")");
|
|
|
|
|
|
if (!this->GetOperatorClasses().IsNull())
|
|
|
|
|
|
str += wxT(" ") + GetOperatorClasses();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
str += wxT(")");
|
|
|
|
|
|
|
|
|
|
|
|
if (GetConnection()->BackendMinimumVersion(8, 2) && GetFillFactor().Length() > 0)
|
|
|
|
|
|
str += wxT("\n WITH (FILLFACTOR=") + GetFillFactor() + wxT(")");
|
|
|
|
|
|
|
|
|
|
|
|
if (GetConnection()->BackendMinimumVersion(8, 0) && tablespace != GetDatabase()->GetDefaultTablespace())
|
|
|
|
|
|
str += wxT("\nTABLESPACE ") + qtIdent(tablespace);
|
|
|
|
|
|
|
|
|
|
|
|
AppendIfFilled(str, wxT("\n WHERE "), GetConstraint());
|
|
|
|
|
|
|
|
|
|
|
|
str += wxT(";\n");
|
|
|
|
|
|
|
|
|
|
|
|
if (GetConnection()->BackendMinimumVersion(7, 5))
|
|
|
|
|
|
if (GetIsClustered())
|
|
|
|
|
|
str += wxT("ALTER TABLE ") + GetQuotedSchemaPrefix(GetIdxSchema()) + qtIdent(GetIdxTable())
|
|
|
|
|
|
+ wxT(" CLUSTER ON ") + qtIdent(GetName())
|
|
|
|
|
|
+ wxT(";\n");
|
|
|
|
|
|
#endif
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QString PgIndex::dropSql() const
|
|
|
|
|
|
{
|
|
|
|
|
|
QString result;
|
|
|
|
|
|
result = "DROP INDEX "
|
|
|
|
|
|
% fullyQualifiedQuotedObjectName()
|
|
|
|
|
|
% ";";
|
|
|
|
|
|
return result;
|
|
|
|
|
|
}
|