The table inheritance works mostly

When a table has partitions or inheritance children these are listed as subnodes. A subnode can appear multiple times under different parents as postgresql supports inheriting multiple tables.

The sizes are still missing and maybe some things I have note verified yet are not correct.
This commit is contained in:
eelke 2023-01-22 15:57:22 +01:00
parent ccd88d0578
commit 39dbab4d36
17 changed files with 452 additions and 127 deletions

View file

@ -1,95 +0,0 @@
#ifndef TABLESTABLEMODEL_H
#define TABLESTABLEMODEL_H
#include "BaseTableModel.h"
#include "NamespaceFilter.h"
#include "catalog/PgClass.h"
#include <memory>
#include <vector>
class OpenDatabase;
class PgClass;
class PgDatabaseCatalog;
class TablesTableModel: public QAbstractTableModel {
public:
using RowItem = PgClass;
enum e_Columns : int {
NameCol, ///< either table, ns.table or table (ns) depending on settings/filters
NamespaceCol,
KindCol,
OwnerCol,
TablespaceCol,
OptionsCol,
AclCol,
CommentCol,
TotalSizeCol,
TableSizeCol,
IndexSizeCol,
ToastSizeCol,
colCount };
TablesTableModel(std::shared_ptr<OpenDatabase> opendatabase, QObject *parent);
void setNamespaceFilter(NamespaceFilter nsf);
void setCatalog(std::shared_ptr<const PgDatabaseCatalog> cat);
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
int rowCount(const QModelIndex &parent) const override;
int columnCount(const QModelIndex &parent) const override;
virtual QVariant data(const QModelIndex &index, int role) const override;
PgClass getTable(int row) const;
RowItem rowItem(int row) const
{
return getTable(row);
}
Oid getTableOid(int row) const;
private:
class TableSize {
public:
int oid;
int64_t totalBytes = -1;
int64_t indexBytes = -1;
int64_t toastBytes = -1;
TableSize()
: oid(0)
{}
};
using TableSizes = std::vector<TableSize>;
class Table {
public:
PgClass _class;
TableSize sizes;
Table(const PgClass &cls)
: _class(cls)
{}
};
using t_Tables = std::vector<Table>;
std::shared_ptr<const PgDatabaseCatalog> m_catalog;
NamespaceFilter m_namespaceFilter = NamespaceFilter::User;
t_Tables m_tables;
QMetaObject::Connection refreshConnection;
std::shared_ptr<OpenDatabase> openDatabase;
Oid getType(int column) const;
QVariant getData(const QModelIndex &index) const;
void StartLoadTableSizes(std::map<Oid, int> oidIndex);
TableSizes QueryTableSizes() const;
void PopulateSizes(std::map<Oid, int> oidIndex, std::vector<TableSize> sizes);
private slots:
void refresh();
};
#endif // TABLESTABLEMODEL_H