Skip to content

Commit

Permalink
1. Added USING method while creating the table. #6378
Browse files Browse the repository at this point in the history
2. Added USING method while creating the materialized view. #6400
  • Loading branch information
pravesh-sharma authored Sep 6, 2023
1 parent 095e112 commit a43b70e
Show file tree
Hide file tree
Showing 58 changed files with 3,064 additions and 58 deletions.
Binary file added docs/en_US/images/materialized_view_code.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/en_US/images/materialized_view_definition.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/en_US/images/materialized_view_parameter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/en_US/images/materialized_view_security.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/en_US/images/materialized_view_sql.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/en_US/images/materialized_view_storage.png
Binary file not shown.
Binary file modified docs/en_US/images/table_advanced.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 14 additions & 11 deletions docs/en_US/materialized_view_dialog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,6 @@ Use the fields in the *General* tab to identify the materialized view:
Click the *Definition* tab to continue.

.. image:: images/materialized_view_definition.png
:alt: Materialized view dialog definition tab
:align: center

Use the text editor field in the *Definition* tab to provide the query that will
populate the materialized view. Please note that updating the definition of existing
materialized view would result in loss of Parameter(Table, Toast), Security(Privileges & Security labels),
Indexes and other dependent objects.

Click the *Storage* tab to continue.

.. image:: images/materialized_view_storage.png
:alt: Materialized view dialog storage tab
:align: center

Expand All @@ -52,10 +41,24 @@ Use the fields in the *Storage* tab to maintain the materialized view:
cannot be queried until you invoke REFRESH MATERIALIZED VIEW.
* Use the drop-down listbox next to *Tablespace* to select a location for the
materialized view.
* Use the drop-down list box next to Access Method to specify the table access method to use to store the contents
for the new materialized view; the method needs to be an access method of type TABLE. This field is optional.
This option is available from v12 and above.
* Use the *Fill Factor* field to specify a fill factor for the materialized
view. The fill factor for a table is a percentage between 10 and 100. 100
(complete packing) is the default.

Click the *Code* tab to continue.

.. image:: images/materialized_view_code.png
:alt: Materialized view dialog definition tab
:align: center

Use the text editor field in the *Code* tab to provide the query that will
populate the materialized view. Please note that updating the definition of existing
materialized view would result in loss of Parameter(Table, Toast), Security(Privileges & Security labels),
Indexes and other dependent objects.

Click the *Parameter* tab to continue.

.. image:: images/materialized_view_parameter.png
Expand Down
3 changes: 3 additions & 0 deletions docs/en_US/table_dialog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,9 @@ Use the fields in the *Advanced* tab to define advanced features for the table:
* Use the drop-down listbox next to *Of type* to copy the table structure from
the specified composite type. Please note that a typed table will be dropped
if the type is dropped (with DROP TYPE ... CASCADE).
* Use the drop-down list box next to Access Method to specify the table access method to use to store
the contents for the new table; the method needs to be an access method of type TABLE. This field is optional.
This option is available from v12 and above.
* Use the *Fill Factor* field to specify a fill factor for the table. The fill
factor for a table is a percentage between 10 and 100. 100 (complete packing)
is the default.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ class TableView(BaseTableView, DataTypeReader, SchemaDiffTableCompare):
'get_toast_table_vacuum': [{}, {'get': 'get_toast_table_vacuum'}],
'all_tables': [{}, {'get': 'get_all_tables'}],
'get_access_methods': [{}, {'get': 'get_access_methods'}],
'get_table_access_methods': [{}, {'get': 'get_table_access_methods'}],
'get_oper_class': [{}, {'get': 'get_oper_class'}],
'get_operator': [{}, {'get': 'get_operator'}],
'get_attach_tables': [
Expand Down Expand Up @@ -538,6 +539,28 @@ def get_access_methods(self, gid, sid, did, scid, tid=None):
status=200
)

@BaseTableView.check_precondition
def get_table_access_methods(self, gid, sid, did, scid, tid=None):
"""
This function returns access methods for table.
Args:
gid: Server Group ID
sid: Server ID
did: Database ID
scid: Schema ID
tid: Table ID
Returns:
Returns list of access methods for table
"""
res = BaseTableView.get_access_methods(self)

return make_json_response(
data=res,
status=200
)

@BaseTableView.check_precondition
def get_oper_class(self, gid, sid, did, scid, tid=None):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,31 +186,6 @@
"expected_sql_file": "create_btree_expr_asc_null_last.sql",
"expected_msql_file": "create_btree_expr_asc_null_last_msql.sql"
},
{
"type": "alter",
"name": "Alter index statistics of expression",
"endpoint": "NODE-index.obj_id",
"sql_endpoint": "NODE-index.sql_id",
"msql_endpoint": "NODE-index.msql_id",
"data": {
"name": "Idx3_$%{}[]()&*^!@\"'`\\/#",
"columns":{
"changed": [{
"is_exp": true,
"col_num": 2,
"colname":"lower(name)",
"collspcname":"pg_catalog.\"POSIX\"",
"op_class":"text_pattern_ops",
"sort_order":false,
"nulls":false,
"is_sort_nulls_applicable":true,
"statistics": 1000
}]
}
},
"expected_sql_file": "alter_expr_statistics.sql",
"expected_msql_file": "alter_expr_statistics_msql.sql"
},
{
"type": "delete",
"name": "Drop index",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,8 @@
"is_positive_test": true,
"update_statistics": true,
"inventory_data": {
"server_min_version": 110000,
"skip_msg": "Update statistics is not supported below PPAS/PG 11.0"
},
"test_data": {
"columns": "PLACE_HOLDER"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from regression import parent_node_dict
from regression.python_test_utils import test_utils as utils
from . import utils as indexes_utils
from pgadmin.utils import server_utils


class IndexesUpdateTestCase(BaseTestGenerator):
Expand All @@ -36,6 +37,16 @@ def setUp(self):
schema_info = parent_node_dict["schema"][-1]
self.server_id = schema_info["server_id"]
self.db_id = schema_info["db_id"]

if "server_min_version" in self.inventory_data:
server_con = server_utils.connect_server(self, self.server_id)
if not server_con["info"] == "Server connected.":
raise Exception("Could not connect to server to add "
"partitioned table.")
if server_con["data"]["version"] < \
self.inventory_data["server_min_version"]:
self.skipTest(self.inventory_data["skip_msg"])

db_con = database_utils.connect_database(self, utils.SERVER_GROUP,
self.server_id, self.db_id)
if not db_con['data']["connected"]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ class PartitionsView(BaseTableView, DataTypeReader, SchemaDiffObjectCompare):
'msql': [{'get': 'msql'}, {}],
'detach': [{'put': 'detach'}],
'truncate': [{'put': 'truncate'}],
'set_trigger': [{'put': 'enable_disable_triggers'}]
'set_trigger': [{'put': 'enable_disable_triggers'}],
'get_table_access_methods': [{}, {'get': 'get_table_access_methods'}],
})

# Schema Diff: Keys to ignore while comparing
Expand Down Expand Up @@ -865,6 +866,29 @@ def ddl_compare(self, **kwargs):

return diff + '\n'

@BaseTableView.check_precondition
def get_table_access_methods(self, gid, sid, did, scid, tid, ptid=None):
"""
This function returns access methods for table.
Args:
gid: Server Group ID
sid: Server ID
did: Database ID
scid: Schema ID
tid: Table ID
ptid: Partition Table ID
Returns:
Returns list of access methods for partition table
"""
res = BaseTableView.get_access_methods(self)

return make_json_response(
data=res,
status=200
)


SchemaDiffRegistry(blueprint.node_type, PartitionsView, 'table')
PartitionsView.register_node_view(blueprint)
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export function getNodePartitionTableSchema(treeNodeInfo, itemNodeData, pgBrowse
coll_inherits: ()=>getNodeAjaxOptions('get_inherits', partNode, treeNodeInfo, itemNodeData),
typname: ()=>getNodeAjaxOptions('get_oftype', partNode, treeNodeInfo, itemNodeData),
like_relation: ()=>getNodeAjaxOptions('get_relations', partNode, treeNodeInfo, itemNodeData),
table_amname_list: ()=>getNodeAjaxOptions('get_table_access_methods', partNode, treeNodeInfo, itemNodeData),
},
treeNodeInfo,
{
Expand Down Expand Up @@ -110,6 +111,7 @@ export default class PartitionTableSchema extends BaseUISchema {
partition_type: 'range',
is_partitioned: false,
partition_value: undefined,
amname: undefined,
...initValues,
});

Expand All @@ -121,7 +123,7 @@ export default class PartitionTableSchema extends BaseUISchema {
this.getAttachTables = getAttachTables;

this.partitionKeysObj = new PartitionKeysSchema([], getCollations, getOperatorClass);
this.partitionsObj = new PartitionsSchema(this.nodeInfo, getCollations, getOperatorClass, getAttachTables);
this.partitionsObj = new PartitionsSchema(this.nodeInfo, getCollations, getOperatorClass, getAttachTables, fieldOptions.table_amname_list);
this.constraintsObj = this.schemas.constraints();
}

Expand Down Expand Up @@ -229,6 +231,23 @@ export default class PartitionTableSchema extends BaseUISchema {
mode: ['create', 'edit'], group: 'advanced', min_version: 90600,
disabled: obj.isPartitioned,
},
{
id: 'amname', label: gettext('Access Method'), group: 'advanced',
type: (state)=>{
return {
type: 'select', options: this.fieldOptions.table_amname_list,
controlProps: {
allowClear: obj.isNew(state) ? true : false,
}
};
}, mode: ['create', 'properties', 'edit'], min_version: 120000,
disabled: (state) => {
if (obj.getServerVersion() < 150000 && !obj.isNew(state)) {
return true;
}
return obj.isPartitioned(state);
},
},
{
id: 'relhasoids', label: gettext('Has OIDs?'), cell: 'switch',
type: 'switch', mode: ['properties', 'create', 'edit'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export class PartitionKeysSchema extends BaseUISchema {
}
}
export class PartitionsSchema extends BaseUISchema {
constructor(nodeInfo, getCollations, getOperatorClass, getAttachTables=()=>[]) {
constructor(nodeInfo, getCollations, getOperatorClass, getAttachTables=()=>[], table_amname_list) {
super({
oid: undefined,
is_attach: false,
Expand All @@ -126,11 +126,13 @@ export class PartitionsSchema extends BaseUISchema {
values_remainder: undefined,
is_sub_partitioned: false,
sub_partition_type: 'range',
amname: undefined,
});

this.subPartitionsObj = new PartitionKeysSchema([], getCollations, getOperatorClass);
this.getAttachTables = getAttachTables;
this.nodeInfo = nodeInfo;
this.table_amname_list = table_amname_list;
}

changeColumnOptions(columns) {
Expand Down Expand Up @@ -198,6 +200,27 @@ export class PartitionsSchema extends BaseUISchema {
readonly: function(state) {
return !obj.isNew(state);
}, noEmpty: true,
},{
id: 'amname', label: gettext('Access Method'), deps: ['is_sub_partitioned'], cell: 'select',
type: (state)=>{
return {
type: 'select', options: this.table_amname_list,
controlProps: {
allowClear: obj.isNew(state) ? true : false,
}
};
}, min_version: 120000, disabled: state => {
if (obj.getServerVersion() < 150000 && !obj.isNew(state)) {
return true;
}
return state.is_sub_partitioned;
}, depChange: state => {
if (state.is_sub_partitioned) {
return {
amname: undefined
};
}
},
},{
id: 'is_default', label: gettext('Default'), type: 'switch', cell:'switch',
width: 55, disableResizing: true, min_version: 110000,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export function getNodeTableSchema(treeNodeInfo, itemNodeData, pgBrowser) {
coll_inherits: ()=>getNodeAjaxOptions('get_inherits', tableNode, treeNodeInfo, itemNodeData),
typname: ()=>getNodeAjaxOptions('get_oftype', tableNode, treeNodeInfo, itemNodeData),
like_relation: ()=>getNodeAjaxOptions('get_relations', tableNode, treeNodeInfo, itemNodeData),
table_amname_list: ()=>getNodeAjaxOptions('get_table_access_methods', tableNode, treeNodeInfo, itemNodeData),
},
treeNodeInfo,
{
Expand Down Expand Up @@ -343,6 +344,7 @@ export default class TableSchema extends BaseUISchema {
partition_type: 'range',
is_partitioned: false,
columns: [],
amname: undefined,
...initValues,
});

Expand All @@ -352,7 +354,7 @@ export default class TableSchema extends BaseUISchema {
this.nodeInfo = nodeInfo;
this.getColumns = getColumns;

this.partitionsObj = new PartitionsSchema(this.nodeInfo, getCollations, getOperatorClass, getAttachTables);
this.partitionsObj = new PartitionsSchema(this.nodeInfo, getCollations, getOperatorClass, getAttachTables, fieldOptions.table_amname_list);
this.constraintsObj = this.schemas.constraints && this.schemas.constraints() || {};
this.columnsSchema = this.schemas.columns && this.schemas.columns() || {};
this.vacuumSettingsSchema = this.schemas.vacuum_settings && this.schemas.vacuum_settings() || {};
Expand Down Expand Up @@ -760,6 +762,29 @@ export default class TableSchema extends BaseUISchema {
}
},
},
{
id: 'amname', label: gettext('Access Method'), group: 'advanced',
deps:['is_partitioned'], type: (state)=>{
return {
type: 'select', options: this.fieldOptions.table_amname_list,
controlProps: {
allowClear: obj.isNew(state) ? true : false,
}
};
}, mode: ['create', 'properties', 'edit'], min_version: 120000,
disabled: (state) => {
if (obj.getServerVersion() < 150000 && !obj.isNew(state)) {
return true;
}
return obj.isPartitioned(state);
}, depChange: state => {
if (state.is_partitioned) {
return {
amname: undefined
};
}
},
},
{
id: 'fillfactor', label: gettext('Fill factor'), type: 'int',
mode: ['create', 'edit'], min: 10, max: 100,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ FIRST{% else %}LAST{% endif %}{% endif %}{% endif %}{% endfor %})
FIRST{% else %}LAST{% endif %}{% endif %}{% endfor %})
{% endif %}
{% if data.fillfactor %}
WITH (FILLFACTOR={{data.fillfactor}})
WITH (fillfactor={{data.fillfactor}})
{% endif %}{% if data.spcname %}
TABLESPACE {{conn|qtIdent(data.spcname)}}{% endif %}{% if data.indconstraint %}

Expand Down
Loading

0 comments on commit a43b70e

Please sign in to comment.