~ubuntu-branches/debian/sid/pgadmin3/sid

« back to all changes in this revision

Viewing changes to pgadmin/schema/gpPartition.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Gerfried Fuchs
  • Date: 2009-07-30 12:27:16 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20090730122716-fddbh42on721bbs2
Tags: 1.10.0-1
* New upstream release.
* Adjusted watch file to match release candidates.
* Updated to Standards-Version 3.8.2:
  - Moved to Section: database.
  - Add DEB_BUILD_OPTIONS support for parallel building.
  - Move from findstring to filter suggestion for DEB_BUILD_OPTIONS parsing.
* pgagent got split into its own separate source package by upstream.
* Exclude Docs.vcproj from installation.
* Move doc-base.enus from pgadmin3 to pgadmin3-data package, the files are
  in there too.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//////////////////////////////////////////////////////////////////////////
 
2
//
 
3
// pgAdmin III - PostgreSQL Tools
 
4
// RCS-ID:      $Id:  $
 
5
// Copyright (C) 2002 - 2009, The pgAdmin Development Team
 
6
// This software is released under the BSD Licence
 
7
//
 
8
// gpPartition.cpp - Greenplum Table Partition class
 
9
//
 
10
//////////////////////////////////////////////////////////////////////////
 
11
 
 
12
#include "pgAdmin3.h"
 
13
 
 
14
 
 
15
#include "utils/misc.h"
 
16
#include "frm/frmHint.h"
 
17
#include "frm/frmMain.h"
 
18
#include "frm/frmMaintenance.h"
 
19
#include "schema/pgTable.h"
 
20
#include "schema/gpPartition.h"
 
21
#include "schema/pgColumn.h"
 
22
#include "schema/pgIndexConstraint.h"
 
23
#include "schema/pgForeignKey.h"
 
24
#include "schema/pgCheck.h"
 
25
#include "utils/sysSettings.h"
 
26
#include "utils/pgfeatures.h"
 
27
#include "schema/pgRule.h"
 
28
#include "schema/pgTrigger.h"
 
29
#include "schema/pgConstraints.h"
 
30
 
 
31
 
 
32
// App headers
 
33
 
 
34
gpPartition::gpPartition(pgSchema *newSchema, const wxString& newName)
 
35
: pgTable(newSchema, partitionFactory, newName)
 
36
{
 
37
}
 
38
 
 
39
gpPartition::~gpPartition()
 
40
{
 
41
}
 
42
 
 
43
bool gpPartition::CanCreate() { return false; }
 
44
 
 
45
wxMenu *gpPartition::GetNewMenu()
 
46
{
 
47
    wxMenu *menu=pgObject::GetNewMenu();
 
48
    if (schema->GetCreatePrivilege())
 
49
    {
 
50
        
 
51
    }
 
52
    return menu;
 
53
}
 
54
/*
 
55
wxString gpPartition::GetCreate()
 
56
{
 
57
    wxString sql;
 
58
 
 
59
   // sql = GetQuotedIdentifier() + wxT(" ") 
 
60
    //    + GetTypeName().Upper() + GetDefinition();
 
61
    sql = wxT("Not implemented yet..sorry");
 
62
    return sql;
 
63
};
 
64
*/
 
65
 
 
66
wxString gpPartition::GetSql(ctlTree *browser)
 
67
{
 
68
        wxString sql;
 
69
        sql = wxT("-- ");
 
70
    sql += _("Note: This DDL is a representation of how the partition might look as a table.");
 
71
    sql += wxT("\n\n");
 
72
 
 
73
        sql += pgTable::GetSql(browser);
 
74
        return sql;
 
75
}
 
76
 
 
77
pgObject *gpPartition::Refresh(ctlTree *browser, const wxTreeItemId item)
 
78
{
 
79
    gpPartition *partition=0;
 
80
    pgCollection *coll=browser->GetParentCollection(item);
 
81
    if (coll)
 
82
        partition = (gpPartition*)partitionFactory.CreateObjects(coll, 0, wxT("\n   AND rel.oid=") + GetOidStr());
 
83
 
 
84
    return partition;
 
85
}
 
86
 
 
87
///////////////////////////////////////////////////////////
 
88
 
 
89
gpPartitionCollection::gpPartitionCollection(pgaFactory *factory, gpPartition *_table)
 
90
: pgTableCollection(factory, _table->GetSchema()) { iSetOid(_table->GetOid()); }
 
91
 
 
92
 
 
93
pgObject *gpPartitionFactory::CreateObjects(pgCollection *coll, ctlTree *browser, const wxString &restriction)
 
94
{
 
95
        gpPartitionCollection *collection=(gpPartitionCollection*)coll;
 
96
    wxString query;
 
97
    gpPartition *table=0;
 
98
 
 
99
    // Greenplum returns reltuples and relpages as tuples per segmentDB and pages per segmentDB,
 
100
    // so we need to multiply them by the number of segmentDBs to get reasonable values.
 
101
    long gp_segments =1;
 
102
 
 
103
    query = wxT("SELECT count(*) AS gp_segments from pg_catalog.gp_configuration where definedprimary = 't' and content >= 0");
 
104
    gp_segments = StrToLong(collection->GetDatabase()->ExecuteScalar(query));
 
105
    if (gp_segments <= 1)
 
106
        gp_segments = 1;
 
107
 
 
108
 
 
109
        pgSet *tables;
 
110
 
 
111
        query= wxT("SELECT rel.oid, relname, rel.reltablespace AS spcoid, spcname, pg_get_userbyid(relowner) AS relowner, relacl, relhasoids, ")
 
112
                wxT("relhassubclass, reltuples, description, conname, conkey, parname, \n")
 
113
                wxT("       EXISTS(select 1 FROM pg_trigger\n")
 
114
                wxT("                       JOIN pg_proc pt ON pt.oid=tgfoid AND pt.proname='logtrigger'\n")
 
115
                wxT("                       JOIN pg_proc pc ON pc.pronamespace=pt.pronamespace AND pc.proname='slonyversion'\n")
 
116
                wxT("                     WHERE tgrelid=rel.oid) AS isrepl\n");
 
117
 
 
118
        query += wxT(", substring(array_to_string(reloptions, ',') from 'fillfactor=([0-9]*)') AS fillfactor \n");
 
119
        query += wxT(", gpd.localoid, gpd.attrnums \n");
 
120
        query += wxT(", substring(array_to_string(reloptions, ',') from 'appendonly=([a-z]*)') AS appendonly \n");
 
121
        query += wxT(", substring(array_to_string(reloptions, ',') from 'compresslevel=([0-9]*)') AS compresslevel \n");
 
122
    query += wxT(", substring(array_to_string(reloptions, ',') from 'columnstore=([a-z]*)') AS columnstore \n");
 
123
    query += wxT(", substring(array_to_string(reloptions, ',') from 'compresstype=([a-z0-9]*)') AS compresstype \n");
 
124
    query += wxT(", substring(array_to_string(reloptions, ',') from 'blocksize=([0-9]*)') AS blocksize \n");
 
125
    query += wxT(", substring(array_to_string(reloptions, ',') from 'checksum=([a-z]*)') AS checksum \n");
 
126
        //query += wxT(", rel.oid in (select parrelid from pg_partition) as ispartitioned\n"); // This only works for top-level tables, not intermediate ones
 
127
        // This looks for intermediate partitions that have subpartitions
 
128
        query += wxT(", rel.oid in (select pr.parchildrelid from pg_partition_rule pr, pg_partition pp where pr.paroid = pp.oid and pp.parlevel < (select max(parlevel) from pg_partition where parrelid = pp.parrelid)) as ispartitioned \n");
 
129
 
 
130
 
 
131
        query += wxT("  FROM pg_class rel JOIN pg_partition_rule pr ON(rel.oid = pr.parchildrelid) JOIN pg_partition p ON (pr.paroid = p.oid)\n")
 
132
        wxT("  JOIN pg_inherits i ON (rel.oid = i.inhrelid) \n")
 
133
                wxT("  LEFT OUTER JOIN pg_tablespace ta on ta.oid=rel.reltablespace\n")
 
134
                wxT("  LEFT OUTER JOIN pg_description des ON (des.objoid=rel.oid AND des.objsubid=0)\n")
 
135
                wxT("  LEFT OUTER JOIN pg_constraint c ON c.conrelid=rel.oid AND c.contype='p'\n");
 
136
        query += wxT("  LEFT OUTER JOIN gp_distribution_policy gpd ON gpd.localoid=rel.oid\n");
 
137
        query += wxT(" WHERE relkind = 'r' ");
 
138
    query += wxT(" AND i.inhparent = ") + collection->GetOidStr() + wxT("\n"); 
 
139
 
 
140
        query += restriction + 
 
141
                wxT(" ORDER BY relname");
 
142
 
 
143
 
 
144
    tables= collection->GetDatabase()->ExecuteSet(query);
 
145
    if (tables)
 
146
    {
 
147
        while (!tables->Eof())
 
148
        {
 
149
            table = new gpPartition(collection->GetSchema(), tables->GetVal(wxT("relname")));
 
150
 
 
151
                        table->iSetOid(tables->GetOid(wxT("oid")));
 
152
                        table->iSetOwner(tables->GetVal(wxT("relowner")));
 
153
                        table->iSetAcl(tables->GetVal(wxT("relacl")));
 
154
 
 
155
                        if (tables->GetOid(wxT("spcoid")) == 0)
 
156
                                table->iSetTablespaceOid(collection->GetDatabase()->GetTablespaceOid());
 
157
                        else
 
158
                                table->iSetTablespaceOid(tables->GetOid(wxT("spcoid")));
 
159
 
 
160
                        if (tables->GetVal(wxT("spcname")) == wxEmptyString)
 
161
                                table->iSetTablespace(collection->GetDatabase()->GetTablespace());
 
162
                        else
 
163
                                table->iSetTablespace(tables->GetVal(wxT("spcname")));
 
164
 
 
165
                        table->iSetComment(tables->GetVal(wxT("description")));
 
166
                        table->iSetHasOids(tables->GetBool(wxT("relhasoids")));
 
167
                        table->iSetEstimatedRows(tables->GetDouble(wxT("reltuples")) * gp_segments);
 
168
 
 
169
                        table->iSetFillFactor(tables->GetVal(wxT("fillfactor")));
 
170
 
 
171
                        table->iSetHasSubclass(tables->GetBool(wxT("relhassubclass")));
 
172
            table->iSetPartitionName(tables->GetVal(wxT("parname")));
 
173
                        table->iSetPrimaryKeyName(tables->GetVal(wxT("conname")));
 
174
                        table->iSetIsReplicated(tables->GetBool(wxT("isrepl")));
 
175
                        wxString cn=tables->GetVal(wxT("conkey"));
 
176
                        cn=cn.Mid(1, cn.Length()-2);
 
177
                        table->iSetPrimaryKeyColNumbers(cn);
 
178
 
 
179
 
 
180
                        Oid lo=tables->GetOid(wxT("localoid"));
 
181
                        wxString db=tables->GetVal(wxT("attrnums"));
 
182
                        db=db.Mid(1, db.Length()-2);
 
183
                        table->iSetDistributionColNumbers(db);
 
184
                        if (lo > 0 && db.Length() == 0)
 
185
                                table->iSetDistributionIsRandom();
 
186
                        table->iSetAppendOnly(tables->GetVal(wxT("appendonly")));
 
187
                        table->iSetCompressLevel(tables->GetVal(wxT("compresslevel")));
 
188
            table->iSetIsColumnStore(tables->GetVal(wxT("columnstore")));
 
189
            table->iSetCompressType(tables->GetVal(wxT("compresstype")));
 
190
            table->iSetBlocksize(tables->GetVal(wxT("blocksize")));
 
191
            table->iSetChecksum(tables->GetVal(wxT("checksum")));
 
192
 
 
193
                        table->iSetPartitionDef(wxT(""));
 
194
                        table->iSetIsPartitioned(tables->GetBool(wxT("ispartitioned"))); 
 
195
        
 
196
                        if (browser)
 
197
                        {
 
198
                                browser->AppendObject(collection, table);
 
199
                                tables->MoveNext();
 
200
                        }
 
201
                        else
 
202
                                break;
 
203
                }
 
204
 
 
205
                delete tables;
 
206
        }
 
207
    return table;
 
208
}
 
209
 
 
210
void gpPartitionFactory::AppendMenu(wxMenu *menu)
 
211
{
 
212
}
 
213
 
 
214
#include "images/table.xpm"
 
215
#include "images/table-sm.xpm"
 
216
#include "images/tables.xpm"
 
217
 
 
218
gpPartitionFactory::gpPartitionFactory() 
 
219
: pgTableObjFactory(__("Partition"), __("New Partition..."), __("Create a new Partition."), table_xpm, table_sm_xpm)
 
220
{
 
221
    metaType = GP_PARTITION;
 
222
}
 
223
 
 
224
pgCollection *gpPartitionFactory::CreateCollection(pgObject *obj)
 
225
{
 
226
    return new gpPartitionCollection(GetCollectionFactory(), (gpPartition *)obj );
 
227
}
 
228
 
 
229
gpPartitionFactory partitionFactory;
 
230
static pgaCollectionFactory cf(&partitionFactory, __("Partitions"), tables_xpm);
 
231
 
 
232