2017-12-17 11:28:20 +01:00
|
|
|
|
#include "PgIndexContainer.h"
|
2018-11-25 19:45:06 +01:00
|
|
|
|
#include "PgClassContainer.h"
|
2017-12-19 18:18:21 +01:00
|
|
|
|
#include "PgDatabaseCatalog.h"
|
2017-12-17 11:28:20 +01:00
|
|
|
|
#include "Pgsql_Col.h"
|
|
|
|
|
|
#include <iterator>
|
|
|
|
|
|
|
|
|
|
|
|
std::string PgIndexContainer::getLoadQuery() const
|
|
|
|
|
|
{
|
2017-12-19 18:18:21 +01:00
|
|
|
|
std::string q = R"__(
|
2017-12-17 11:28:20 +01:00
|
|
|
|
SELECT indexrelid, indrelid, indnatts, indisunique, indisprimary,
|
|
|
|
|
|
indisexclusion, indimmediate, indisclustered, indisvalid,
|
2017-12-19 18:18:21 +01:00
|
|
|
|
indcheckxmin, indisready, indislive, indkey,
|
2017-12-17 19:34:28 +01:00
|
|
|
|
indcollation, indclass, indoption, indexprs, indpred,
|
2021-03-10 19:06:40 +01:00
|
|
|
|
pg_get_indexdef(indexrelid), pg_total_relation_size(indexrelid))__";
|
2017-12-19 18:18:21 +01:00
|
|
|
|
|
2018-11-18 19:30:45 +01:00
|
|
|
|
if (minimumVersion(90400))
|
2017-12-19 18:18:21 +01:00
|
|
|
|
q += ", indisreplident ";
|
|
|
|
|
|
q += "\nFROM pg_index";
|
|
|
|
|
|
return q;
|
2017-12-17 11:28:20 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PgIndex PgIndexContainer::loadElem(const Pgsql::Row &row)
|
|
|
|
|
|
{
|
|
|
|
|
|
Pgsql::Col col(row);
|
2018-11-25 19:45:06 +01:00
|
|
|
|
Oid indexrelid = col.nextValue();
|
|
|
|
|
|
auto&& cls = m_catalog.classes()->getByKey(indexrelid);
|
|
|
|
|
|
auto&& name = cls->objectName();
|
|
|
|
|
|
auto&& nsoid = cls->nsOid();
|
|
|
|
|
|
|
|
|
|
|
|
PgIndex v(m_catalog, indexrelid, name, nsoid);
|
|
|
|
|
|
col >> v.relid >> v.natts >> v.isunique
|
2017-12-17 11:28:20 +01:00
|
|
|
|
>> v.isprimary >> v.isexclusion >> v.immediate >> v.isclustered
|
2017-12-19 18:18:21 +01:00
|
|
|
|
>> v.isvalid >> v.checkxmin >> v.isready >> v.islive;
|
2017-12-17 11:28:20 +01:00
|
|
|
|
col.getAsVector<int16_t>(std::back_inserter(v.key));
|
|
|
|
|
|
col.getAsVector<Oid>(std::back_inserter(v.collation));
|
|
|
|
|
|
col.getAsVector<Oid>(std::back_inserter(v.indclass));
|
|
|
|
|
|
col.getAsVector<int16_t>(std::back_inserter(v.option));
|
2021-03-10 19:06:40 +01:00
|
|
|
|
col >> v.exprs >> v.pred >> v.definition >> v.sizeBytes;
|
2018-11-18 19:30:45 +01:00
|
|
|
|
if (minimumVersion(90400))
|
2017-12-19 18:18:21 +01:00
|
|
|
|
col >> v.isreplident;
|
|
|
|
|
|
|
2017-12-17 11:28:20 +01:00
|
|
|
|
return v;
|
|
|
|
|
|
}
|
2017-12-17 19:34:28 +01:00
|
|
|
|
|
|
|
|
|
|
std::vector<PgIndex> PgIndexContainer::getIndexesForTable(Oid table_oid) const
|
|
|
|
|
|
{
|
|
|
|
|
|
std::vector<PgIndex> result;
|
|
|
|
|
|
for (const auto &e : m_container)
|
|
|
|
|
|
if (e.relid == table_oid)
|
|
|
|
|
|
result.push_back(e);
|
|
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
}
|