Generate PARTITIONED BY SQL for partitioned tables.
Expressions not yet supported.
This commit is contained in:
parent
61f90668d8
commit
2c899bd799
8 changed files with 243 additions and 41 deletions
|
|
@ -14,19 +14,55 @@ std::string PgClassContainer::getLoadQuery() const
|
|||
" reloptions, d.description, "
|
||||
" relacl, pg_get_viewdef(pg_class.oid)";
|
||||
|
||||
if (lessThenVersion(120000))
|
||||
if (lessThenVersion(120000))
|
||||
q += ", relhasoids ";
|
||||
if (minimumVersion(100000))
|
||||
q += ", pg_get_expr(relpartbound, oid)"; // partition specification
|
||||
q +=
|
||||
", pg_get_expr(relpartbound, oid)"
|
||||
", partstrat, partnatts, partattrs, partclass, partcollation"; // TODO: , partexprs";
|
||||
if (minimumVersion(110000))
|
||||
q += ", partdefid";
|
||||
|
||||
q +=
|
||||
// pg_get_expr must be called on each element in partexprs
|
||||
|
||||
q +=
|
||||
"\nFROM pg_catalog.pg_class \n"
|
||||
" LEFT JOIN pg_catalog.pg_description AS d ON (objoid=pg_class.oid AND objsubid=0) \n"
|
||||
" LEFT JOIN pg_catalog.pg_description AS d ON (objoid=pg_class.oid AND objsubid=0) \n";
|
||||
|
||||
if (minimumVersion(100000))
|
||||
q += " LEFT JOIN pg_partitioned_table AS pt ON (partrelid=pg_class.oid) \n";
|
||||
|
||||
q +=
|
||||
"WHERE relkind IN ('r', 'i', 'p', 'I', 'v', 'm', 'f')";
|
||||
|
||||
return q;
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
class PartitionedTableKeyItemsBuilder {
|
||||
public:
|
||||
int16_t attCount;
|
||||
std::vector<int16_t> attNums;
|
||||
std::vector<Oid> attOpClass;
|
||||
std::vector<Oid> attCollation;
|
||||
|
||||
PartitioningKeyItems Build()
|
||||
{
|
||||
PartitioningKeyItems result(attCount);
|
||||
for (int attIdx = 0; attIdx < attCount; ++attIdx)
|
||||
{
|
||||
auto& item = result[attIdx];
|
||||
item.attNum = attNums[attIdx];
|
||||
item.opClass = attOpClass[attIdx];
|
||||
item.collation = attCollation[attIdx];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
PgClass PgClassContainer::loadElem(const Pgsql::Row &row)
|
||||
{
|
||||
Pgsql::Col col(row);
|
||||
|
|
@ -35,7 +71,7 @@ PgClass PgClassContainer::loadElem(const Pgsql::Row &row)
|
|||
Oid schema_oid = col.nextValue();
|
||||
|
||||
PgClass v(m_catalog, class_oid, name, schema_oid);
|
||||
Oid owner ;
|
||||
Oid owner;
|
||||
col >> v.type >> v.oftype
|
||||
>> owner >> v.am >> v.filenode >> v.tablespace >> v.pages_est
|
||||
>> v.tuples_est >> v.toastrelid >> v.isshared >> v.persistence
|
||||
|
|
@ -55,8 +91,32 @@ PgClass PgClassContainer::loadElem(const Pgsql::Row &row)
|
|||
if (lessThenVersion(120000))
|
||||
col >> v.hasoids;
|
||||
|
||||
PgPartitionedTable &pt = v.partitionedTable;
|
||||
if (minimumVersion(100000))
|
||||
{
|
||||
PartitionedTableKeyItemsBuilder kibuilder;
|
||||
|
||||
col >> v.partitionBoundaries;
|
||||
|
||||
auto strategy = col.nextValue();
|
||||
if (strategy.null())
|
||||
{
|
||||
int s = minimumVersion(110000) ? 5 : 4;
|
||||
col.skip(s);
|
||||
}
|
||||
else
|
||||
{
|
||||
pt.strategy << strategy;
|
||||
col >> kibuilder.attCount;
|
||||
col.getAsVector<int16_t>(std::back_inserter(kibuilder.attNums));
|
||||
col.getAsVector<Oid>(std::back_inserter(kibuilder.attOpClass));
|
||||
col.getAsVector<Oid>(std::back_inserter(kibuilder.attCollation));
|
||||
|
||||
pt.keyColumns = kibuilder.Build();
|
||||
if (minimumVersion(110000))
|
||||
col >> pt.defaultPartition;
|
||||
}
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue