Series of articles written for DBA’s and developers who know Oracle and want to learn about NonStop SQL/MX. Useful for people who know NonStop, and would like to know about similarities and differences between the two products.
Concepts of NonStop SQL/MX: Part 3 - Introduction to Metadata
1. Concepts of NonStop SQL/MX
Introduction to SQL/MX Metadata
Technical white paper
Table of contents
Introduction ..................................................................................................................................2
Intended audience ....................................................................................................................2
Examples .................................................................................................................................2
Introduction to SQL/MX metadata ..................................................................................................2
Metadata .................................................................................................................................2
The system catalog ....................................................................................................................3
User catalogs ...........................................................................................................................3
Exploring object definitions ........................................................................................................4
Commands for showing row layout .............................................................................................4
Commands for showing object definitions ....................................................................................5
Metadata views ............................................................................................................................7
ZZSYSSCHEMAS ......................................................................................................................8
ZZSYSTABLES ...........................................................................................................................8
ZZTABLES and ZZALLTABLES ......................................................................................................8
ZZPARTITIONS .........................................................................................................................8
ZZPRIVILEGES ..........................................................................................................................9
The mxschema script .....................................................................................................................9
Legal status ..............................................................................................................................9
Catalog and schema options ......................................................................................................9
Action options ..........................................................................................................................9
Configuration options ..............................................................................................................10
Online help ............................................................................................................................11
Conclusion .................................................................................................................................12
References .................................................................................................................................12
Other interesting reads ................................................................................................................12
2. Introduction
When customers migrate Oracle applications to NonStop SQL/MX, DBAs with an Oracle background may feel a bit
lost, because both products have their specific solutions to common practices such as disk storage and user access.
This article is one in a series, inspired by the Oracle Database: Concepts 11g Release 2 manual, and tries to explain
some of those differences in implementation. Other articles will address other differences.
Intended audience
This article is written for DBAs and developers who know Oracle and want to learn about NonStop SQL/MX. It may
also be useful for people who know NonStop and would like to know about similarities and differences between the
two products.
Examples
In this article, the Oracle examples use the SQL*Plus command interface and the NonStop SQL/MX examples are
made using the mxci equivalent. The SQL*Plus commands are indicated by the “SQL>” prompt; those in mxci are
indicated by “>>”.
Introduction to SQL/MX metadata
Oracle maintains a set of read-only reference tables and views for each Oracle database that it calls the data
dictionary. NonStop SQL/MX maintains a set of read-only reference tables that it calls the catalog, or more broadly,
the metadata tables. Both products provide read-only access to these tables using the SQL language. Any direct
modifications, however, are prohibited to users. Instead, the metadata is updated as the result of Data Definition
Language (DDL) operations such as CREATE TABLE, CREATE VIEW, ALTER TABLE, and DROP INDEX statements.
Metadata
NonStop SQL/MX stores metadata for all objects in designated SQL/MX tables that are automatically maintained as
a result of DDL operations or when table statistics are updated by the UPDATE STATISTICS 1 command. Other tables
may contain information about the status of certain DDL operations, such as on-line movement of data, the fastcopy
utility, and (online) populating of indexes.
A complete description of all the metadata tables can be found in Chapter 10 of the SQL/MX Reference Manual,
which can be found through the technical documents site: http://www.hp.com/go/nonstop-docs.
SQL/MX metadata is structured in catalogs and schemas, which are used to logically group definitions of databases.
Most customers use multiple catalogs and each catalog can have multiple schemas.
Part of the metadata is contained in other locations on a system, such as the file labels and resource forks. That
information, however, is for use by internal, low-level SQL/MX routines only and typically is not accessible via the
SQL language but instead, when applicable, via dedicated tools.
1
UPDATE STATISTICS is similar in function to the Oracle ANALYZE TABLE command; it gathers per-column statistics that are used by the SQL Query
compiler to determine an optimal query execution plan.
2
3. The system catalog
In Oracle, each database includes a dedicated tablespace, called SYSTEM, which stores dictionary tables and is the
default location for user definitions. NonStop SQL/MX is quite different.
Every NonStop node where SQL/MX is installed has exactly one system catalog. It contains five schemas that
collectively hold the system’s definitions. It cannot be used to store user definitions.
In this case “system” refers to the local node instead of an Oracle instance. System-wide defaults are maintained in
the SYSTEM_DEFAULTS table in the SYSTEM_DEFAULTS_SCHEMA.
Each node in a NonStop EXPAND 2 cluster network has its own SQL/MX system catalog, if SQL/MX is installed on
that node. The system catalog is created and automatically named when SQL/MX is installed. The unique system
name, as used by EXPAND, is used as a suffix to ensure system catalog names are consistent and yet unique across
the network. For example, the system catalog for the node named NSKIT11 would be called
NONSTOP_SQLMX_NSKIT11.
User catalogs
User catalogs and schemas need to be created before tables and other user objects can be defined. A user
catalog contains one system schema and one or more user schemas. The system schema,
DEFINITION_SCHEMA_VERSION_3000 3, includes the tables that contain the definitions of all the objects in the
catalog. Each user schema contains user data tables as well as metadata tables that contain database statistics
for these user tables.
Figure 1 shows how catalogs, schemas, and tables are related. It shows a system schema, called
DEFINITION_SCHEMA_VERSION_3000, and two user schemas, one for test, and another for production. The user
schemas share the OBJECTS and ACCESS_PATHS metadata tables. Each schema has its own HISTOGRAMS and
HISTOGRAM_INTERVALS table and, if the mxschema script has been executed, its own copy of the convenience
views such as ZZTABLES. The mxschema script is discussed later in this article.
Figure 1: Catalog object hierarchy
2
The Expand product allows the distribution of database data across geographically separated systems, up to 255 servers in a network. This is
transparent to the applications, which only refer to the tables by their ANSI table names as if all data is local.
3
This is the version as of SQL/MX release 3.0. Previous releases used version number 1200.
3
4. Exploring object definitions
Many DBAs use command line interfaces such as SQL*Plus and mxci to get information about the definitions of
database objects. Typical questions are: “What is the layout of this table?” and “what does the DDL look like?”. The
sections below briefly explain how to answer these questions.
Commands for showing row layout
In SQL*Plus, the desc command can be used to show which columns are present in a table definition. In SQL/MX, the
invoke command has a similar function. Example 1 shows the output side by side.
Example 1: Obtaining a record layout
Oracle SQL*Plus command NonStop SQL/MX mxci command
SQL> desc emp2m; >>invoke emp2m;
Name Null? Type
--------- --------- --------- -- Definition of table FRANS.HPJ.EMP2M
EMPNO NOT NULL NUMBER(38) -- Definition current Wed May 11 07:14:12 2011
UPDATABLE NOT NULL NUMBER(38) (
ENAME NOT NULL CHAR(16) JOB
NOT NULL CHAR(20) SAL EMPNO INT NO DEFAULT NOT NULL NOT DROPPABLE
NOT NULL NUMBER(38) , UPDATABLE INT NO DEFAULT NOT NULL NOT DROPPABLE
DEPTNO NOT NULL NUMBER(38) , ENAME CHAR(16) CHARACTER SET ISO88591 COLLATE
DMY NOT NULL CHAR(80)
DEFAULT NO DEFAULT NOT NULL NOT DROPPABLE
, JOB CHAR(20)
CHARACTER SET ISO88591 COLLATE
SQL>
DEFAULT NO DEFAULT NOT NULL NOT DROPPABLE
, SAL INT NO DEFAULT NOT NULL NOT DROPPABLE
, DEPTNO INT NO DEFAULT NOT NULL NOT DROPPABLE
, DMY CHAR(80) CHARACTER SET ISO88591 COLLATE
DEFAULT NO DEFAULT NOT NULL NOT DROPPABLE
)
--- SQL operation complete.
>>
4
5. Commands for showing object definitions
In SQL*Plus, DBAs use the GET_DDL function of the DBMS_METADATA package to get the definitions of an object. The
function requires the object type (for example, ‘TABLE’) and the name. The command shown in example 2 is used on a
table called EMP2M. The output reflects the full table name (SYSTEM.EMP2M) and its defaults and storage parameters.
Example 2: Using the Oracle DBMS_METADATA.GET_DDL function
SQL> select dbms_metadata.get_ddl('TABLE','EMP2M') from DUAL;
DBMS_METADATA.GET_DDL('TABLE','EMP2M')
-------------------------------------------------------------------------------
CREATE TABLE "SYSTEM"."EMP2M"
( "EMPNO" NUMBER(*,0) NOT NULL ENABLE, "UPDATABLE" NUMBER(*,0) NOT NULL ENABLE, "ENAME"
CHAR(16) NOT NULL ENABLE,
"JOB" CHAR(20) NOT NULL ENABLE, "SAL" NUMBER(*,0) NOT NULL ENABLE, "DEPTNO" NUMBER(*,0)
NOT NULL ENABLE, "DMY" CHAR(80) NOT NULL ENABLE,
PRIMARY KEY ("EMPNO")
USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT
CELL_FLASH_CACHE DEFAULT)
TABLESPACE "SYSTEM" ENABLE
) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING STORAGE(INITIAL 65536 NEXT
1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT
CELL_FLASH_CACHE DEFAULT)
TABLESPACE "SYSTEM"
SQL>
NonStop SQL/MX uses a similar function, called SHOWDDL, which requires only the object name. Example 3 and 4
shows similar output as that produced by DBMS_METADATA.GET_DDL. As in SQL*Plus, the command lists
information about specific storage locations as well as the index and column definitions.
5
6. Example 3: Using SHOWDDL to obtain DDL information
>>showddl emp2m;
CREATE TABLE FRANS.HPJ.EMP2M (
EMPNO INT NO DEFAULT -- NOT NULL NOT DROPPABLE
, UPDATABLE INT NO DEFAULT -- NOT NULL NOT DROPPABLE
, ENAME CHAR(16) CHARACTER SET ISO88591 COLLATE DEFAULT NO DEFAULT -- NOT NULL NOT DROPPABLE
, JOB CHAR(20) CHARACTER SET ISO88591 COLLATE DEFAULT NO DEFAULT -- NOT NULL NOT DROPPABLE
, SAL INT NO DEFAULT -- NOT NULL NOT DROPPABLE
, DEPTNO INT NO DEFAULT -- NOT NULL NOT DROPPABLE
, DMY CHAR(80) CHARACTER SET ISO88591 COLLATE DEFAULT NO DEFAULT -- NOT NULL NOT DROPPABLE
, CONSTRAINT FRANS.HPJ.EMP2M_898213697_6493 PRIMARY KEY (EMPNO ASC) NOT DROPPABLE
, CONSTRAINT FRANS.HPJ.EMP2M_948592697_6493 CHECK (FRANS.HPJ.EMP2M.EMPNO IS NOT NULL AND
FRANS.HPJ.EMP2M.UPDATABLE IS NOT NULL AND FRANS.HPJ.EMP2M.ENAME IS NOT NULL AND
FRANS.HPJ.EMP2M.JOB IS NOT NULL AND FRANS.HPJ.EMP2M.SAL IS NOT NULL AND FRANS.HPJ.EMP2M.DEPTNO
IS NOT NULL
AND FRANS.HPJ.EMP2M.DMY IS NOT NULL) NOT DROPPABLE
)
LOCATION NSKIT11.$DATA08.ZSDFJ006.N5G48T00
NAME NSKIT11_DATA08_ZSDFJ006_N5G48T00
ATTRIBUTES BLOCKSIZE 4096, EXTENT (50000, 50000) HASH PARTITION
(
ADD LOCATION NSKIT11.$DATA09.ZSDFJ006.FDH48T00
NAME NSKIT11_DATA09_ZSDFJ006_FDH48T00
EXTENT (50000, 50000)
, ADD LOCATION NSKIT11.$DATA10.ZSDFJ006.HHJ48T00
NAME NSKIT11_DATA10_ZSDFJ006_HHJ48T00
EXTENT (50000, 50000)
, ADD LOCATION NSKIT11.$DATA07.ZSDFJ006.S8J48T00
NAME NSKIT11_DATA07_ZSDFJ006_S8J48T00
EXTENT (50000, 50000)
)
STORE BY (EMPNO ASC)
;
CREATE INDEX EMP2M_IX ON FRANS.HPJ.EMP2M (
UPDATABLE ASC
)
LOCATION NSKIT11.$DATA08.ZSDFJ006.Q9W1WV00
NAME NSKIT11_DATA08_ZSDFJ006_Q9W1WV00
ATTRIBUTES BLOCKSIZE 4096, EXTENT (50000, 50000), MAXEXTENTS 400
PARTITION (
ADD FIRST KEY (500001)
LOCATION NSKIT11.$DATA09.ZSDFJ006.QJX1WV00
NAME NSKIT11_DATA09_ZSDFJ006_QJX1WV00
EXTENT (50000, 50000) MAXEXTENTS 400
, ADD FIRST KEY (1000001)
LOCATION NSKIT11.$DATA10.ZSDFJ006.STZ1WV00
NAME NSKIT11_DATA10_ZSDFJ006_STZ1WV00
EXTENT (50000, 50000) MAXEXTENTS 400
, ADD FIRST KEY (1500001)
LOCATION NSKIT11.$DATA07.ZSDFJ006.SP11WV00
NAME NSKIT11_DATA07_ZSDFJ006_SP11WV00
EXTENT (50000, 50000) MAXEXTENTS 400
)
;
--- SQL operation complete.
>>
6
7. SHOWDDL can also be used to obtain view definitions, as is shown in example 4 for the DUAL view in SQL/MX.
Example 4: SHOWDDL command applied to views
>>showddl dual;
CREATE VIEW FRANS.HPJ.DUAL AS
SELECT D.D FROM (VALUES (0)) D(D) ;
--- SQL operation complete.
>>
Metadata views
As the descriptions of the NonStop SQL/MX system tables in the earlier sections make clear, a query to retrieve all
the table names of a schema involves joining multiple catalog tables. To simplify such queries, the NonStop
Advanced Technology Center (ATC) designed a set of convenience views on the system metadata. These views give
easy access to the metadata on a schema level because they are part of the user schema. Convenience views are
created by a shell script called mxschema. The script and its options are described later in this article in The
mxschema script.
Oracle’s dictionary views are grouped in sets, prefixed by ALL_, DBA_, and USER_; according to their use. The
convenience views for SQL/MX, except the special DUAL view, are prefixed with “ZZ”. This query, against
ZZVIEWS, returns the list of views in the current schema.
Example 5: SQL/MX metadata convenience views
>>select view_name from zzviews;
VIEW_NAME
------------------------------
DUAL ZZALLTABLES
ZZCOLUMNS
ZZCONSTRAINTS
ZZIDENTITIES
ZZINDEXES
ZZPARTITIONS
ZZPRIVILEGES
ZZPROCEDURES
ZZSCHEMA
ZZSTATISTICS
ZZSYSSCHEMAS
ZZSYSTABLES
ZZTABLES
ZZTABLES_DISTHIST
ZZVIEWS
--- 16 row(s) selected.
>>
The SQL/MX metadata views show data for the current schema except for the ZZSYSSCHEMAS and ZZSYSTABLES
views, which show information at the system level. The next sections describe commonly used views.
Important note: Some of the fields have been deliberately truncated in the view definitions to allow for an easy
readable overview on a terminal screen. This does not mean that SQL/MX has truncated the names in any way; it just
means that the view may not show the complete names if they are very long.
7
8. ZZSYSSCHEMAS
This view shows the full catalog and schema name as well as the schema owner and metadata storage location
information for all the catalog and schemas on the system. It provides an overview similar to the list option of the
mxschema shell script.
ZZSYSTABLES
This view shows the names of the system-wide DEFAULTS table, the names of the tables in the system-wide
SYSTEM_SCHEMA, and the names of the metadata tables in the current user catalog.
Example 6: The ZZSYSTABLES view
>>select * from zzsystables; SYSTABLE_NAME
-----------------------------------------------------------------------
NONSTOP_SQLMX_NSKIT11.SYSTEM_DEFAULTS_SCHEMA.SYSTEM_DEFAULTS
NONSTOP_SQLMX_NSKIT11.SYSTEM_SCHEMA.CATSYS
NONSTOP_SQLMX_NSKIT11.SYSTEM_SCHEMA.CAT_REFERENCES
NONSTOP_SQLMX_NSKIT11.SYSTEM_SCHEMA.SCHEMATA
NONSTOP_SQLMX_NSKIT11.SYSTEM_SCHEMA.SCHEMA_REPLICAS
DEFINITION_SCHEMA_VERSION_3000.ACCESS_PATHS
DEFINITION_SCHEMA_VERSION_3000.ACCESS_PATH_COLS
……
……
--- 42 row(s) selected.
>>
Note:
The system-wide table names have three-part table names (catalog name,
schema name, and table name), but the names of tables in the current schema
only contain the name of the DEFINITION_SCHEMA and the table. The reason
for this is the intended use of this view: to copy and paste the name in a DBA
metadata query.
ZZTABLES and ZZALLTABLES
ZZTABLES provides information about the individual table, such as the size of the row, the block size, the size of the
key, the partition type (hash, range, or not partitioned), and also the time when the last statistics were collected.
The ZZALLTABLES view is helpful to customers who use SQL/MX to access tables managed by the previous version of
NonStop SQL, called SQL/MP, which uses a different file system structure. These tables can be used by programs as
if they were native tables; however, the SQL/MX metadata contains only a reference to metadata in SQL/MP.
ZZPARTITIONS
ZZPARTITIONS shows how the tables and indexes are distributed over the available storage and, where applicable,
over the various nodes in a NonStop cluster. When statistics have been updated, the view also shows the partition
size and the index levels of the B-tree indexes as well as the number of non-empty blocks.
8
9. ZZPRIVILEGES
This view shows, per object, such as table view or Stored Procedure, the privileges that are granted to users. The
users (the grantor and grantees) are NonStop OS users, displayed in the form GROUP_NAME.USER_NAME. Note
that users may have alias names for the GROUP.USER name. For example, user jane could map to the full name
ADMINS.JANE.
The mxschema script
The metadata views are shorthand convenience views on tables in the SQL/MX catalog that allow a user to enter
simple SQL queries rather than creating complex queries to join multiple tables. Every change in the metadata as a
result of DDL actions will automatically be present when the views are used in queries.
The views are created by running a shell script called mxschema.
Legal status
This script is provided by HP “as-is” and without warranty, and it can be modified by users if so desired. The full legal
text is available when the script is called with the –X option.
Catalog and schema options
The script requires a catalog and schema name for all except the “list” option which is described below. The catalog
name is passed using the –C option and the schema name is passed using the –S option.
Action options
The action options are specified in lower case and invoke the following functions:
Help (-h) is the default option and shows the full list of options with a short explanation. When errors occur, such
as an invalid or missing option, these will be displayed along with the help text. Example 8 shows an
example of this help text.
List (-l) produces an overview of all catalogs and schemas on the system. Example 7 shows an example of the
schemas in catalog FRANS and those in the system catalog. Note that the long names may be truncated
in order to produce a report that fits on an 80 column screen.
Create (-c) is used to create a new catalog (when the –S option is not present) or to create a new schema and,
following, the convenience views. The views can also be created in an existing schema using this
option. Note that in that case, the CREATE SCHEMA command will return an error that can be ignored.
Delete (-d) is used to drop the views that were created by this script or an earlier version of it. The script attempts to
drop the views it would create in its current version. Therefore errors might occur if a new version of the
script is executed against an older version of the views. However, these errors can safely be ignored.
Note that the -d option does not drop the DUAL view, because DUAL may be used in user programs
and dropping it will invalidate these user programs.
Refresh (-r) is used to replace an older version of the views by a newer version. Refresh executes the delete option,
followed by the create option. The expected errors 1022, “Schema already exists” and 1055, “View
DUAL already exists” error can be ignored.
9
10. Example 7: Output of the mxschema list option
~> mxschema -l
mxschema Version 10.0 May 16, 2011. Listing of SQL/MX schemas on NSKIT11.
CATALOG_NAME VOLUME SCHEMA_NAME SCHEMA_SUBVOL
----------------------- -------- ------------------------------ ------------
FRANS $DATA01 DEFINITION_SCHEMA_VERSION_300 ZSD99Q2D
FRANS $DATA01 PERF ZSDFJ000
FRANS $DATA01 MX30 ZSDFJ001
FRANS $DATA01 HPJ ZSDFJ006
NONSTOP_SQLMX_NSKIT11 $DSMSCM SYSTEM_SCHEMA ZSD0
NONSTOP_SQLMX_NSKIT11 $DSMSCM MXCS_SCHEMA ZSD1
NONSTOP_SQLMX_NSKIT11 $DSMSCM DEFINITION_SCHEMA_VERSION_300 ZSD4KFDD
NONSTOP_SQLMX_NSKIT11 $DSMSCM SYSTEM_SQLJ_SCHEMA ZSD591VH
NONSTOP_SQLMX_NSKIT11 $DSMSCM SYSTEM_DEFAULTS_SCHEMA ZSD5K7KH
Configuration options
When a catalog or schema is created, additional configuration options can be passed to the script. These
configuration options, just like the catalog (–C) and schema (–S) options described earlier, are given in uppercase.
Location (-L) sets the Guardian subvolume 4, used when a new schema is created. The location may not
exceed 8 characters and must start with the letters ZSD. Objects for this schema will be stored
on disk volumes using this subvolume name.
Volume (-V) sets the Guardian volume default for the duration of the script. By default, SQL/MX creates
metadata tables on the OS user’s default Guardian volume. The –V option changes the default
volume for the duration of the script so that the metadata tables and the views will be created
on the volume of choice.
User (-U) group.user grants SELECT access to the metadata views to this user. The user name is in the form
GROUPNAME.USERNAME (for example ADMINS.JOE). By default, the script grants SELECT
access to PUBLIC, so that every user can query the metadata. The DUAL view will always be
readable by everyone.
4
The LOCATION clause defines the subvolume for the schema objects when a schema is created. A LOCATION can also be given when user objects,
like tables, are created. For these user objects however, the LOCATION refers to disk VOLUMEs.
10
11. Online help
Calling mxschema with the –h option, or just by itself, shows an overview of all the options with a short explanation.
Example 8: mxschema help text
~> mxschema -h
mxschema: valid options are XlcrdhC:S:V:L:U:m:
--
Version 10.0 May 16, 2011
List and create SQL/MX Schemas and create convenience views
Supported options are:
h = This help
l = List schema information.
c = create a new catalog or a schema in an already existing catalog d = delete
r = refresh
C = Set CATALOG to use
S = Set SCHEMA to use. When not set, try to create catalog
L = Set the LOCATION when creating a schema. Must start with ZSD and not exceed 8 characters
V = Set the default VOLUME when creating a catalog or schema. The $ sign is optional but when
specified must be 'escaped'.
The V option sets the _DEFAULTS define prior to invoking mxci.
U = Optional USER.GROUP name that gets granted SELECT access to the created metadata views. By
default, mxschema will grant access to PUBLIC
d = Delete the metadata views. This option is used when upgrading the SQL/MX metadata from e.g.
Version 1200 to Version 3000. NOTE: The DUAL view will not be dropped.
r = Refresh (delete the views and then create the views). This option is used when new views
have been introduced and an existing schema wants to have them installed.
NOTE: The DUAL view will not be refreshed.
m = alternative location of mxci. Currently set to: /usr/tandem/sqlmx/bin/mxci
X = DISCLAIMER
11