HP NonStop SqlMx-Mp-Comparison
HP NonStop SqlMx-Mp-Comparison
Abstract
This guide describes SQL differences between HP NonStop™ SQL/MP and NonStop
SQL/MX.
Product Version
NonStop SQL/MX Releases 2.0 and 2.1
Supported Release Version Updates (RVUs)
This publication supports G06.23 and all subsequent G-series RVUs until otherwise
indicated by its replacement publication.
Hewlett-Packard Company—523735-003
i
Contents 4. Embedded SQL
Identifiers (continued)
Date-time Literals 3-6
Interval Literals 3-8
Expressions and Functions 3-8
Numeric Value Expressions and Functions 3-9
Datetime Functions 3-9
Interval Value Expressions 3-10
Mathematical Functions 3-10
Sequence Functions 3-10
Aggregate Functions 3-11
Predicates 3-11
LIKE Predicate 3-11
Sort Operations 3-12
SQL DML Statements 3-12
Nonaudited Tables 3-13
INSERT Statement 3-14
SELECT Statement 3-15
UPDATE Statement 3-16
Access Options and Isolation Levels 3-16
Isolation Levels Contrasted Between NonStop SQL/MP and NonStop
SQL/MX 3-16
STABLE Access 3-17
Transaction Management 3-18
Starting and Ending a Transaction 3-18
SET TRANSACTION Statement 3-19
CONTROL TABLE Directive 3-21
CONTROL QUERY Directive 3-23
Query Caching 3-24
Query Type Comparison 3-27
Versioning 3-29
4. Embedded SQL
Host Variable Declarations 4-1
SETSCALE Function 4-1
Variable-Length Character Data in Embedded SQL C Programs 4-2
INVOKE Directive 4-3
Data Type Conversion 4-3
Host Variables With Date-time Data Types 4-3
Indicator Variables 4-3
Tables 6-4
Clustering Keys 6-4
Table Attributes 6-4
File Types 6-4
Constraints 6-4
Indexes 6-5
Partitions 6-5
Views 6-6
SQL/MX Views 6-6
SQL/MP Views 6-6
Object Security 6-6
7. Utility Differences
DISPLAY USE OF Command 7-1
IMPORT Command 7-1
MXTOOL Utility 7-1
Partition Management: The MODIFY Utility 7-2
POPULATE INDEX Command 7-2
SHOWDDL Command 7-2
SHOWLABEL Command 7-3
Index
Figures
Figure 4-1. SQL/MP Compilation Process 4-11
Figure 4-2. SQL/MX Compilation Process 4-12
Tables
Table 2-1. NonStop SQL/MP Contents Compared to NonStop SQL/MX 2-1
Table 3-1. Support For NonStop SQL/MP DATETIME Literals in NonStop
SQL/MX 3-6
Table 3-2. NonStop SQL/MP and NonStop SQL/MX Functions 3-9
Table 3-3. Mapping NonStop SQL/MP Datetime Functions To NonStop
SQL/MX 3-10
Table 3-4. SQL/MX and SQL/MP DML Statements 3-12
Table 3-5. CONTROL TABLE Directives 3-22
Table 3-6. Query Type Comparison 3-27
Table 4-1. Embedded SQL Statements 4-4
Abstract
This guide describes SQL differences between HP NonStop™ SQL/MP and NonStop
SQL/MX.
Product Version
NonStop SQL/MX Releases 2.0 and 2.1
Supported Release Version Updates (RVUs)
This publication supports G06.23 and all subsequent G-series RVUs until otherwise
indicated by its replacement publication.
Document History
Part Number Product Version Published
429827-001 NonStop SQL/MX Release 1.0 March 2001
429857-001 NonStop SQL/MX Release 1.8 December 2002
523735-001 NonStop SQL/MX Release 2.0 June 2004
523735-002 NonStop SQL/MX Release 2.0 August 2004
523735-003 NonStop SQL/MX Release 2.1 August 2005
Audience
This guide is intended for database administrators and application programmers who
want to:
• Understand how NonStop SQL/MX differs from NonStop SQL/MP.
• Write new SQL/MX applications.
• Write new SQL/MP applications that will be ported to NonStop SQL/MX in the
future.
• Investigate migrating existing SQL/MP applications to NonStop SQL/MX.
Learning about the features of SQL implemented in NonStop SQL/MX enables you, as
a database administrator or an application programmer, to choose the appropriate
database for your needs. In particular, it is important for those who want to rework
SQL/MP applications to NonStop SQL/MX to begin thinking about specific differences.
Related Documentation
This manual is part of the NonStop SQL/MX library of manuals, which includes:
Introductory Guides
SQL/MX Comparison Guide Describes SQL differences between NonStop
for SQL/MP Users SQL/MP and NonStop SQL/MX.
SQL/MX Quick Start Describes basic techniques for using SQL in the
SQL/MX conversational interface (MXCI). Includes
information about installing the sample database.
Reference Manuals
SQL/MX Reference Manual Describes the syntax of SQL/MX statements, MXCI
commands, functions, and other SQL/MX language
elements.
SQL/MX Connectivity Describes the SQL/MX administrative command
Service Administrative library (MACL) available with the SQL/MX
Command Reference conversational interface (MXCI).
DataLoader/MX Reference Describes the features and functions of the
Manual DataLoader/MX product, a tool to load SQL/MX
databases.
This documentation is helpful for understanding the concepts and terminology of this
manual:
Other Related Documentation
C/C++ Programmer’s Guide Describes HP extensions to the C and C++
languages for NonStop servers.
SQL/MX Connectivity Describes how to install and manage MXCS, which
Service Manual enables applications developed for Microsoft Open
Database Connectivity (ODBC) application
programming interface (API) to use SQL/MX.
Extensible Markup Language Describes the W3 standards for XML at
(XML) Web site http://www.w3.org/XML.
Reference Manuals
Reference Messages
SQL/MX SQL/MX SQL/MX Help Help
Installation Query Guide Data Mining
and Guide
Management
Guide
VST001.vsd
Notation Conventions
Hypertext Links
Blue underline is used to indicate a hypertext link within text. By clicking a passage of
text with a blue underline, you are taken to the location described. For example:
This requirement is described under Backup DAM Volumes and Physical Disk
Drives on page 3-2.
UPPERCASE LETTERS. Uppercase letters indicate keywords and reserved words. Type
these items exactly as shown. Items not enclosed in brackets are required. For
example:
MAXATTACH
lowercase italic letters. Lowercase italic letters indicate variable items that you supply.
Items not enclosed in brackets are required. For example:
file-name
computer type. Computer type letters within text indicate C and Open System Services
(OSS) keywords and reserved words. Type these items exactly as shown. Items not
enclosed in brackets are required. For example:
myfile.c
italic computer type. Italic computer type letters within text indicate C and Open
System Services (OSS) variable items that you supply. Items not enclosed in brackets
are required. For example:
pathname
{ } Braces. A group of items enclosed in braces is a list from which you are required to
choose one item. The items in the list can be arranged either vertically, with aligned
braces on each side of the list, or horizontally, enclosed in a pair of braces and
separated by vertical lines. For example:
LISTOPENS PROCESS { $appl-mgr-name }
{ $process-name }
ALLOWSU { ON | OFF }
| Vertical Line. A vertical line separates alternatives in a horizontal list that is enclosed in
brackets or braces. For example:
INSPECT { OFF | ON | SAVEABEND }
… Ellipsis. An ellipsis immediately following a pair of brackets or braces indicates that you
can repeat the enclosed sequence of syntax items any number of times. For example:
M address [ , new-value ]…
[ - ] {0|1|2|3|4|5|6|7|8|9}…
An ellipsis immediately following a single syntax item indicates that you can repeat that
syntax item any number of times. For example:
"s-char…"
Item Spacing. Spaces shown between items are required unless one of the items is a
punctuation symbol such as a parenthesis or a comma. For example:
CALL STEPMOM ( process-id ) ;
If there is no space between two items, spaces are not permitted. In this example, no
spaces are permitted between the period and any other items:
$process-name.#su-name
Line Spacing. If the syntax of a command is too long to fit on a single line, each
continuation line is indented three spaces and is separated from the preceding line by
a blank line. This spacing distinguishes items in a continuation line from items in a
vertical list of selections. For example:
ALTER [ / OUT file-spec / ] LINE
[ , attribute-spec ]…
Yes, but DEFINEs for table naming are not necessary in NonStop SQL/MX.
DEFINES can be used only for SQL/MP objects referenced through the SQL/MX
application. SQL/MX objects cannot be referenced with DEFINES.
In addition, DEFINEs must be available to NonStop SQL/MX at run time, or you will
receive an error. NonStop SQL/MP does not have this requirement.
• Does NonStop SQL/MX support similarity checking and execution-time name
resolution?
Yes. NonStop SQL/MX supports similarity checking and execution-time name
resolution with some limitations.
• Does NonStop SQL/MX support Report Writer?
Yes. In addition, you can use third-party tools for reports. If you need assistance in
choosing a tool, contact your HP representative.
• Can NonStop SQL/MX run under both the HP NonStop Kernel Open System
Services (OSS) and Guardian Services environments?
Many key SQL/MX processes run as OSS processes (as do HP NonStop Tuxedo,
HP NonStop DOM, and Java processes). Your applications can be run on
Guardian with an OSS pass-through command. See the SQL/MX Programming
Guide for C and COBOL for more information.
• What benefits will NonStop SQL/MX provide for OLTP applications?
You can now build your OLTP application by using ANSI-standard SQL. This
feature allows you to leverage the expertise that your developers have gained in
working on other ANSI-standard databases and quickly transfer those skills to
SQL/MX development. It also allows you to build applications that can be ported
between DBMS systems with a minimum of change. Several new SQL/MX
features, including rowsets and compound statements, provide significant
performance improvements for OLTP applications. NonStop SQL/MX also supports
a publish and subscribe feature that supports transactional-based queuing.
• Does TACL support NonStop SQL/MX?
Yes. TACL supports SQL/MX objects when the Guardian name of the object is
specified. TACL commands do not accept ANSI names as input and do not return
ANSI names in their output. These TACL commands support SQL/MX objects:
° FILEINFO
° FILENAMES
° FILES
° #FILEGETLOCKINFO
° #FILEINFO
° #FILENAMES
° #LOCKINFO
° #OPENINFO
° #XFILEINFO
° #XFILENAMES
° #XFILES
In general, the commands work the same and return the same information for
SQL/MX objects as they do for non-SQL/MX objects. Exceptions are noted in the
TACL Reference Manual.
These commands return errors when used with SQL/MX objects and are not
supported:
° COPYDUMP
° PURGE
° RENAME
° #PURGE
° #RENAME
Performance
In addition to considering many more plans, the SQL/MX optimizer allows you to push
down certain plans that involve compound statements or nested joins into the Data
Access Manager. You can influence a query plan by rewriting portions of a plan with
the CONTROL QUERY SHAPE command. NonStop SQL/MX provides histogram
statistics that provide more accurate statistics of the data in the database. These
statistics are also used by the optimizer to create efficient query plans.
For additional information about optimizer features, see Section 5, Optimizer and
Executor.
the ability to divide the data to be processed into partitions and work on each partition
in parallel. In a partitioned parallel plan, multiple operators all work on the same plans,
and results are merged by using multiple pipelines. Although NonStop SQL/MP uses
some partitioned parallelism to process in parallel, NonStop SQL/MX has been
designed to take advantage of both executor server process (ESP) parallelism and
Data Access Manager parallelism.
For additional information about parallelism, see the SQL/MX Query Guide.
Manageability
For parallelism in NonStop SQL/MP, one ESP per partition is started. NonStop SQL/MX
simplifies ESP management by starting only the number of ESPs it needs to process a
plan in parallel if the optimizer determines that ESP partitioned parallelism will provide
the best priced query plan.
NonStop SQL/MX provides a number of user-controlled defaults that allow you to
change default settings that affect optimization, performance, and the generation of
histogram statistics.
Like NonStop SQL/MP, NonStop SQL/MX provides EXPLAIN output. However,
NonStop SQL/MX provides EXPLAIN as a table, and the output is in machine-readable
format. You can easily extract the EXPLAIN output from embedded SQL programs. In
addition, NonStop SQL/MX provides a GUI-based query tool called Visual Query
Planner that graphically displays the results of query plans.
ANSI Compatibility
NonStop SQL/MX is open, portable, and, most important, uses an industry standard:
the American National Standards Institute (ANSI) version of SQL that was created in
1992. This version of SQL is referred to as SQL-92—a standard that is considered far
more complete than earlier versions of SQL for business-critical applications. SQL-92
was replaced by SQL:1999. Core SQL:1999 contains all of Entry SQL-92, plus much of
Intermediate SQL-92 and some of Full SQL-92, plus a few new SQL:1999 features.
NonStop SQL/MX is based on SQL:1999 and includes support for features from higher
levels of the standard. NonStop SQL/MP is based on the SQL-89 standard.
Applications with SQL statements that adhere to the SQL:1999 standard can be ported
to run against a variety of database management systems, including NonStop
SQL/MX. If you are trained to write applications with other SQL-92 compliant database
management systems, you can easily apply your skills to applications for NonStop
SQL/MX.
For details about how NonStop SQL/MX features comply with ANSI standards, see the
SQL/MX Reference Manual.
Other Features
Many other features have been added to NonStop SQL/MX that are not discussed in
this guide. Some of those features include:
• Data mining
• Publish and subscribe
• Compound statements and rowsets
For additional information regarding these topics, see the SQL/MX Data Mining Guide,
the SQL/MX Queuing and Publish/Subscribe Services, and the SQL/MX Programming
Guide for C and COBOL.
Data Types
NonStop SQL/MX supports most SQL/MP data types. Some SQL/MP DATETIME data
types are mapped to the SQL/MX SQL:1999 date-time data types DATE, TIME, and
TIMESTAMP. NonStop SQL/MX recognizes the nonstandard FRACTION keyword and
maps it directly to the fractional precision of the corresponding SQL:1999 compliant
data type.
MPDateTimeCol
-------------
...
03-12
...
This table lists the mapping between the interval data types used in NonStop SQL/MP
and those used in NonStop SQL/MX:
NonStop SQL/MX handles the interval data types in the next list in the same manner
as NonStop SQL/MP:
• YEAR TO (YEAR, MONTH)
• MONTH TO MONTH
• DAY TO (DAY, HOUR, MINUTE)
• HOUR TO (HOUR, MINUTE)
• MINUTE TO MINUTE
For precision and default of interval data types, NonStop SQL/MP and NonStop
SQL/MX are the same. For additional information about interval data types, see the
SQL/MX Reference Manual.
NonStop SQL/MX returns a warning indicating that you selected an unsupported data
type with undefined contents. If you try to use the unsupported data type in any sort of
expression, NonStop SQL/MX returns an error.
File Types
SQL/MP tables can have one of three physical file organizations: key-sequenced,
entry-sequenced, or relative and can be partitioned. You can access these types of
SQL/MP files through NonStop SQL/MX:
• Key-sequenced tables with or without partitions
• Entry-sequenced tables that are not partitioned
You cannot access these types of SQL/MP files through NonStop SQL/MX:
• Entry-sequenced tables that are partitioned
• Relative tables
For more information about SQL/MP file organizations, see the SQL/MP Reference
Manual.
Identifiers
NonStop SQL/MP supports only regular identifiers, formed from alphanumeric
characters and the underscore character. Regular identifiers are not case sensitive. In
NonStop SQL/MP, an SQL identifier can contain up to 30 letters (A through Z or a
through z), digits (0 through 9), or underscore (_) characters. The first character must
be a letter.
NonStop SQL/MX supports both regular and delimited identifiers. An identifier of either
type can contain up to 128 characters. Regular identifiers are defined as they are in
NonStop SQL/MP—with the exception of length. Delimited identifiers are character
strings that appear within double quote characters (") and consist of alphanumeric
characters and any character in the SQL-92 special character set except for the at sign
(@), the forward slash (/), backward slash (\), and circumflex (^).
For additional information about identifiers, see the SQL/MX Reference Manual.
Reserved Words
In NonStop SQL/MP, you should not use reserved words as names of constraints,
columns (including correlation names), cursors, or statements. You can, however, use
reserved words in catalog names, in Guardian names that identify tables, indexes,
views, partitions, collations, and in host variables.
NonStop SQL/MX reserves a longer list of words and allows the use of a reserved
word only if you place double quotes around it and observe case-sensitivity. You
cannot access views that are defined on tables named after reserved words. See the
SQL/MP Reference Manual for a list of SQL/MP reserved words. See the SQL/MX
Reference Manual for a list of SQL/MX reserved words. In addition, see the Identifiers
entry in the SQL/MX Reference Manual for information about how reserved words can
be used and limitations in NonStop SQL/MX.
Literals
NonStop SQL/MX uses single quote characters (') as character string delimiters.
NonStop SQL/MX supports all SQL/MP date-time literals. However, if you try to use a
literal with unsupported FRACTION-only INTERVAL or DATETIME in any sort of
expression, NonStop SQL/MX returns an error.
For additional information about literals, see the SQL/MX Reference Manual.
String Delimiters
NonStop SQL/MP uses both single (') and double quote characters (") to enclose
character, date-time, and interval literals. NonStop SQL/MX uses only single quote
characters for string delimiters, conforming to the SQL:1999 standard. NonStop
SQL/MX uses double quotes for delimited identifiers.
Date-time Literals
In NonStop SQL/MP, a date-time literal is a DATETIME, DATE, TIME, or TIMESTAMP
literal that you can use in an expression and which can appear in default, USA, or
European format.
In NonStop SQL/MX, a date-time literal is a DATE, TIME, or TIMESTAMP literal. An
SQL/MX date-time literal begins with the DATE, TIME, or TIMESTAMP keyword and
can appear in default, USA, or European format.
For example, these DATE literals are in default, USA, and European formats,
respectively:
DATE '1990-01-22'
DATE '01/22/1990'
DATE '22.01.1990'
Interval Literals
As in NonStop SQL/MP, an SQL/MX interval literal is either year-month or day-time. If
you are using SQL/MX DML statements with SQL/MP tables, NonStop SQL/MX
recognizes fields created with the FRACTION keyword and maps them directly to the
fractional precision of the SECOND field.
These are INTERVAL literals:
INTERVAL '7' DAY
INTERVAL '2-7' YEAR TO MONTH
INTERVAL '5:2:15:36.33' DAY TO SECOND(2)
An SQL/MP interval with a literal of DAY TO FRACTION(2) becomes in SQL/MX DAY
TO SECOND(2).
Except for the functions listed previously, NonStop SQL/MX offers all the functions of
NonStop SQL/MP and adds many new functions.
Datetime Functions
In NonStop SQL/MP, the CURRENT function returns a current local DATETIME value,
based on the specified start-end fields, such as CURRENT YEAR TO MONTH,
CURRENT YEAR or CURRENT SECOND. CURRENT by itself is the equivalent of
CURRENT YEAR TO FRACTION.
For the same results in NonStop SQL/MX, use the CURRENT_DATE,
CURRENT_TIME, or CURRENT_TIMESTAMP function. In addition, CURRENT is an
SQL/MX extension that maps to CURRENT_TIMESTAMP, equivalent to its result in
NonStop SQL/MP. NonStop SQL/MX does not support the use of CURRENT with start-
end fields. For this result, you should cast the appropriate form of SQL/MX
CURRENT_DATE, CURRENT_TIME, or CURRENT_TIMESTAMP to the SQL/MP
DATETIME type with the desired start-end fields. Table 3-3 compares SQL/MP and
SQL/MX date-time functions:
Mathematical Functions
NonStop SQL/MP does not support mathematical functions. NonStop SQL/MX
supports many mathematical functions as extensions to the SQL-92 standard.
Sequence Functions
NonStop SQL/MP does not support sequence functions. In NonStop SQL/MX,
sequence functions operate on ordered rows of a SELECT result table that includes a
SEQUENCE BY clause.
Aggregate Functions
In a few cases, NonStop SQL/MP allows a subquery within an aggregate in a
predicate. NonStop SQL/MX follows the ANSI standard and does not allow any
subqueries in an aggregate.
In order to comply with ANSI standards, NonStop SQL/MX does not move aggregate
predicates from the WHERE clause to a HAVING clause and does not move non-
aggregate predicates from the HAVING clause to the WHERE clause, as NonStop
SQL/MP does.
Predicates
Both NonStop SQL/MP and NonStop SQL/MX support the use of row-value
constructors within predicates. However, the NonStop SQL/MP implementation is not
SQL:1999 compliant. In NonStop SQL/MP, you are not required to enclose the
sequence of expressions of a row-value constructor in parentheses. In NonStop
SQL/MX, it is helpful (although not required) to do so. If you do not enclose the
sequence of expressions in parentheses, your resulting queries might be ambiguous.
For example, in this predicate, consisting of a comparison predicate and a NULL
predicate, SQL/MP row-value constructors use no parentheses:
WHERE a,b > 10,c AND p,q,r IS NULL
In contrast, in NonStop SQL/MX, the row-value constructors in this predicate use
parentheses:
WHERE (a,b) > (10,c) AND (p,q,r) IS NULL
Use row-value constructors in comparison predicates, the IN predicate, the NULL
predicate, and the quantified comparison predicates (ALL, ANY, SOME).
LIKE Predicate
Both NonStop SQL/MP and NonStop SQL/MX support the LIKE predicate. However,
NonStop SQL/MP has an extension to the ANSI standard. It allows you to specify a
TERMINATE character to indicate the end of the pattern within the pattern string. You
can use this clause when the column value and the comparison value are of different
lengths. NonStop SQL/MX supports the SUBSTRING and POSITION functions, which
can be used for the same purpose as TERMINATE.
NonStop SQL/MX rewrites SQL/MP constraint and view text that uses the LIKE
predicate and TERMINATE character:
Sort Operations
NonStop SQL/MP uses the FastSort sort/merge program for certain operations. These
operations are described in the SQL/MP Installation and Management Guide. You use
the EXPLAIN utility to determine if a sort occurs. The EXPLAIN reports any sort
operations required to execute the query. You also use certain SORT-related DEFINEs
to influence the effectiveness of some SQL operations.
NonStop SQL/MX does not use the FastSort program or the SORT-related DEFINEs.
In addition, a scratch file in NonStop SQL/MX can overflow to another disk. The
operation will not fail if a scratch file becomes full or if the disk becomes full; NonStop
SQL/MX creates an additional scratch file either on the same or a different disk if the
disk becomes full. The maximum number of scratch files that can be used is 2048.
NonStop SQL/MX provides default settings that influence the choice of scratch disks.
SQL/MX parallelism is performed through ESPs only. Parallel sort can be forced
through CONTROL QUERY SHAPE. When the SQL/MX optimizer runs parallel
queries with ESPs, each ESP tries to use a different disk.
For additional information about how scratch disks are selected and influenced, see
the Defaults section of the SQL/MX Query Guide and the SQL/MX Reference Manual.
Nonaudited Tables
In both NonStop SQL/MP and NonStop SQL/MX, the HP NonStop Transaction
Management Facility (TMF) product works only on audited tables, so a transaction
does not protect operations on nonaudited tables. The simplest approach is to make all
tables audited.
NonStop SQL/MP is designed to avoid any inconsistencies between the base table and
an index for nonaudited tables. Because of its design, NonStop SQL/MX has a greater
likelihood that such inconsistencies might occur.
Nonaudited tables are not protected by transactions and follow a different locking and
error handling model than audited tables. In NonStop SQL/MX, certain situations such
as DML error occurrences or utility operations with DML operations can lead to
inconsistent data within a nonaudited table or between a nonaudited table and its
indexes.
To avoid potential problems, do not create indexes on nonaudited tables. Do not run
DDL or utility operations concurrently with DML operations on nonaudited tables. This
table lists differences in how NonStop SQL/MP and NonStop SQL/MX handle
nonaudited DML operations
Operation NonStop SQL/MP NonStop SQL/MX
Insert/update/delete with a user error No inconsistencies Potentially many rows
during index maintenance affected
Insert/update/delete interrupted by At most one row Potentially many rows
internal program abend or CPU halt affected
NonStop SQL/MX provides a default setting that can warn you at compile time of
nonaudited index maintenance, called IUD_NONAUDITED_INDEX_MAINT. By default,
operations that could lead to an inconsistency between base tables and indexes are
disabled. See the Defaults Table entry in the SQL/MX Reference Manual for further
information.
INSERT Statement
SELECT Statement
UPDATE Statement
Parallel Plans
In NonStop SQL/MP, you cannot have a parallel plan where the UPDATE statement
contains the WHERE CURRENT OF clause. In NonStop SQL/MX, you can have
parallel plans with the WHERE CURRENT OF clause.
Note. Unless you are writing applications for portability, you should use isolation levels at the
statement level. The SET TRANSACTION statement might cause a dynamic recompilation of
DML statements within the next transaction. Further, NonStop SQL/MX does not have the
opportunity to optimize query execution plans as it does during static compilation. You can
achieve better performance if you specify isolation levels for individual DML statements.
• STABLE (NonStop SQL/MP) and STABLE (NonStop SQL/MX) have the same
implementation. This option is available only for the SELECT statement.
• REPEATABLE (NonStop SQL/MP and NonStop SQL/MX) and SERIALIZABLE
(NonStop SQL/MX) have the same implementation; this option holds locks on data
until the end of the transaction.
Note. If your SQL/MP application uses the BROWSE, STABLE, and REPEATABLE keywords,
NonStop SQL/MX accepts the keywords as synonyms for READ UNCOMMITTED, STABLE,
and SERIALIZABLE.
STABLE Access
Transaction Management
A TMF transaction is the basic recoverable unit in case of a failure or transaction
interruption. TMF transactions can be defined during an MXCI session or in a host
program. The typical order of events is:
1. Transaction is started.
2. Database changes are made.
3. Transaction is committed.
If the changes cannot be made or you do not want to complete the transaction, your
program can abort the transaction so the database is rolled back to its original state.
Even if a transaction is initiated implicitly, you must end a transaction explicitly with the
COMMIT WORK statement or the ROLLBACK WORK statement so that either the
entire SQL statement executes or none of it is does.
Auto-Abort
NonStop SQL/MX Release 1.8 automatically aborted transactions if an error occurred
while performing a SQL DELETE, INSERT, UPDATE, or DDL statement. By default,
NonStop SQL/MX Release 2.0 does not automatically abort transactions following an
error. The option to abort the transaction following an error must be determined by the
application program.
You can set a CONTROL QUERY DEFAULT, UPD_ABORT_ON_ERROR, to make
SQL/MX Release 2.0 behave like SQL/MX Release 1.8 and automatically abort
transactions following an error. See the description of this control query default in the
SQL/MX Reference Manual for details.
SQL/MP Behavior
In NonStop SQL/MP, you can use row-not-found warnings or row-already-exists errors
to determine whether to insert or update single rows. You can do an INSERT to find out
if the row already exists, ignore the error, and follow it with an UPDATE statement to
update the row. Or, do an UPDATE on a row to see if it exists, and when no row is
found, use an INSERT statement to insert the row. This process is sometimes called
an “UPSERT.”
SQL/MX Release 2.0 enables you to use row-not-found and row-already exists errors
the same way, by leaving the CONTROL QUERY DEFAULT
UPD_ABORT_ON_ERROR set to OFF, the default. See the description of this control
query default in the SQL/MX Reference Manual for details.
Inherited Transactions
In NonStop SQL/MP and NonStop SQL/MX, if a transaction is started at some point
during the execution of your program (for example, in TMF or MXCS), you do not need
to explicitly start a new SQL transaction. SQL detects that a transaction exists and
inherits that transaction. If an error occurs in an inherited transaction, NonStop
SQL/MX changes the transaction state to doomed (SQLSTATE “25000”). A doomed
transaction is not aborted. However, to proceed, you must manually abort the
transaction. NonStop SQL/MX provides error messages until then.
TMF or MXCS, or inherited from other processes. NonStop SQL/MP provides a similar
SQLCI command, called AUTOWORK.
See Cursor Operations (Embedded SQL) on page 3-21 for information about using the
AUTOCOMMIT option with cursors.
The next statement sets the AUTOCOMMIT option to ON:
SET TRANSACTION AUTOCOMMIT ON;
If this option is set to ON, at the end of each statement execution, NonStop SQL/MX
automatically commits changes made to the database. AUTOCOMMIT is set to ON by
default at the start of an MXCI session.
If this option is set to OFF, the current transaction remains active until the end of the
MXCI session or, for embedded SQL, the end of program execution, at which time the
transaction is aborted—unless you explicitly commit or roll back the transaction. The
default is OFF for embedded SQL.
You can use the MXCI command ENV to check the state of the transaction.
AUTOCOMMIT Example
In the next example, the SET TRANSACTION statement sets AUTOCOMMIT to ON.
The first INSERT statement starts an implicit transaction. When the INSERT finishes
executing, the transaction, consisting of one inserted row, is committed. The next
INSERT statement occurs, and after it finishes, its transaction is committed. You start a
user-defined (explicit) transaction with the BEGIN WORK statement. A series of
UPDATE statements are contained in this user-defined transaction, and after the
COMMIT WORK statement is issued, the updates are committed. Remember that the
AUTOCOMMIT option is still set to ON, so that when the next DML statement is
initiated, an implicit transaction is started, and when the statement successfully
finishes, the transaction is committed.
UPDATE ...
UPDATE ... --AUTOCOMMIT OFF
COMMIT WORK;
--Explicit transaction committed
--AUTOCOMMIT STILL ON
Use the MXCI command, SHOWCONTROL, to see which controls are in effect.
In NonStop SQL/MX, the CONTROL TABLE directive requires that you enclose all
arguments in single quotes. In NonStop SQL/MP, the CONTROL TABLE directive has
no such restriction.
In NonStop SQL/MP, the control TIMEOUT allows you to use a negative value (-1),
which is essentially wait forever. This value is not allowed in NonStop SQL/MX.
The NonStop SQL/MP CONTROL TABLE directive enables you to adjust the timeout
value for compile time. NonStop SQL/MX provides compile time directives for
CONTROL TABLE TIMEOUT and CONTROL TABLE STREAM_TIMEOUT. NonStop
SQL/MX provides for run-time timeout with the SET TABLE TIMEOUT statement as
described in the SQL/MX Reference Manual and SQL/MX Programming Guide for C
and COBOL.
See the SQL/MX Reference Manual for additional information about the CONTROL
TABLE directive.
Query Caching
In NonStop SQL/MP, you control statement and query caching with MXCS and
SQL/MP configuration attributes, system defaults, and control statements. These
settings persist until a user changes a Guardian user ID, a server is reinitialized, or a
rollback condition occurs. Caching takes place at a high level.
In NonStop SQL/MX, caching is controlled by control query default statements.
Caching takes place within each SQL/MX MXCMP compiler session and is applicable
to query compilation requests in that session. MXCS, JDBC, and MXCI clients have
their own MXCMP sessions. Each MXCMP session has caching turned on by default.
MXCS and JDBC/MX clients use control statements that you can store in a named
collection linked to a user and stored in configuration tables for that user, so they are
always set for that user.
See the SQL/MX Reference Manual for details about these settings and the SQL/MX
Query Guide for more information about queries.
This table compares caching features in NonStop SQL/MP and NonStop SQL/MX:
Versioning
NonStop SQL/MX database objects inherit their schema's version, regardless of what
features they use. SQL/MP database objects have a feature-based object version.
SETSCALE Function
In NonStop SQL/MP, using the C programming language, use the SETSCALE function
to set the scale of certain data types. You must use the SETSCALE function whenever
the host variable is used in the query. In NonStop SQL/MX, scale information for a host
variable is supplied when the host variable is declared inside the BEGIN DECLARE
SECTION.
SQL/MP Example
This C program fragment uses SETSCALE with an INSERT statement to create a new
row with the value 98.34 in the PARTS.PRICE column after storing the value in host
variable unit_price. The value is multiplied by 100 for storing as a whole number.
unit_price = 9834;
EXEC SQL INSERT INTO =PARTS (PRICE)
VALUES (SETSCALE (:unit_price, 2));
INVOKE Directive
In NonStop SQL/MP, use the INVOKE directive interactively through SQLCI to create
host variable declarations in an EDIT file. The EDIT file can then be included in an
embedded SQL program.
In NonStop SQL/MX, use the INVOKE directive to create host variable declarations
only directly in an embedded SQL program. Use the INVOKE command in MXCI to
display the table and column names and data types associated with the columns; you
cannot invoke the format of another language (such as COBOL).
For either kind of table, INVOKE does not support the DATEFORMAT clause. INVOKE
returns the ANSI DATETIME data type. The SQL DATEFORMAT function returns a
character string. They are not compatible and cannot be used interchageably.
Indicator Variables
As in NonStop SQL/MP, the primary use of the indicator variable in NonStop SQL/MX
is to indicate whether the value supplied is null. If the source value is null, the value of
the indicator variable is set to less than zero.
However, in NonStop SQL/MX, the indicator variable has another use. If an indicator
variable is associated with a target character host variable in the INTO clause of a
SELECT or FETCH statement, and the length of the target variable is smaller than the
value returned, the truncated string is placed into the host variable, the indicator
variable is set to the length of the source string, and a warning message is issued.
Otherwise, if the length of the target variable is sufficient, the indicator variable is set to
0.
For example, suppose the columns PARTDESC and QTY_AVAILABLE in the PARTS
table allow null. After the SELECT statement executes, this C example tests the
indicator variable for null or a truncated value:
EXEC SQL SELECT partnum, partdesc, price, qty_available INTO
:parts_rec.partnum,
:parts_rec.partdesc
INDICATOR :parts_rec.partdesc_i,
:parts_rec.price,
:parts_rec.qty_available
INDICATOR :parts_rec.qty_available_i,
FROM sales.parts
WHERE partnum = 300380 AND partnum = 2402 ;
...
if (parts.qty_available_i < 0) handle_null_value();
if (parts.partdesc_i > 0 ) handle_truncated_value();
...
In NonStop SQL/MP, the indicator variable is not set to the source length in the case of
truncation. It is set to 0 if it is a nonnull value and if the value is null, the indicator
variable is set to -1.
EXECUTE Statement
In NonStop SQL/MX, input data is supplied by the USING clause that specifies either a
list of host variables or an SQL descriptor area. Output data is provided by the INTO
clause that specifies either a list of host variables or an SQL descriptor area. See
Descriptor Area.
NonStop SQL/MP implements the RETURNING clause for output data. NonStop
SQL/MX does not provide a RETURNING clause.
In both NonStop SQL/MX and NonStop SQL/MP, if you perform a PREPARE and an
EXECUTE of an SQL UPDATE, INSERT or DELETE statement on a non-audited table,
NonStop SQL/MX does not close the table and will not release record and table locks.
You can use FUP LISTLOCKS to check if locks are kept on that table by your MXCI
session after completion of the EXECUTE statement, then manually execute an
UNLOCK command or exit the MXCI session. You can also use standalone UPDATE,
INSERT or DELETE statements instead of using PREPARE and EXECUTE. Only
SQL/MP tables can be non-audited.
Updatable Cursors
In NonStop SQL/MP, delete operations using a cursor do not require the FOR UPDATE
OF clause of the DECLARE CURSOR statement; you must use this clause when you
update rows, but it is optional when you delete rows. In NonStop SQL/MX, both update
and delete operations require an updatable cursor.
In NonStop SQL/MP, the cursor defaults to read only unless specified FOR UPDATE.
In NonStop SQL/MX, within the DECLARE CURSOR statement, the optional FOR
clause has this form:
FOR {READ ONLY | UPDATE [OF colname [,colname]...]}
By using the FOR clause, you can specify whether the cursor is FOR READ ONLY
(read-only cursor) or FOR UPDATE OF (updatable cursor). If you do not specify the
FOR clause, and if ORDER BY or GROUP BY is specified for the cursor or if the query
expression defining the cursor specifies a read-only table, the cursor defaults to
read-only. It is the query that determines that the table is read-only, not the table’s
attributes. Otherwise, the cursor defaults to updatable (without a column list). If you
know that you are not going to update a cursor, specify FOR READ ONLY.
FETCH Statement
In NonStop SQL/MP, when a FETCH statement executes, if the number of host
variables is different from the number of columns in the result table of the declared
cursor, a warning is issued, and NonStop SQL/MP returns the number of values in the
shorter list.
In NonStop SQL/MX, the number of host variables must be the same as the number of
columns in the result table or an error is returned.
Dynamic SQL
Dynamic SQL allows a program to construct, compile, and execute all or part of an
SQL statement at run time. NonStop SQL/MP provides a descriptor area, referred to as
the SQLDA, containing information about input parameters and output variables in
dynamic SQL statements.
NonStop SQL/MX provides for the allocation of a descriptor area with the use of
SQL:1999 dynamic SQL statements. This descriptor area consists of multiple item
descriptor areas, together with a count of the number of those item descriptor areas.
For further information about using the descriptor area, see Descriptor Area on
page 4-7.
The next list summarizes the dynamic SQL statements that you use with an SQL/MX
descriptor area. For information about the syntax and use of these statements, see the
SQL/MX Reference Manual.
Descriptor Area
NonStop SQL/MP provides a descriptor area (SQLDA) that enables a dynamic SQL
application to exchange information with the database about input parameters and
output columns. You can declare the descriptor area by using the INCLUDE SQLDA
directive.
NonStop SQL/MX does not provide the SQLDA as does NonStop SQL/MP and does
not provide the INCLUDE SQLDA directive. However, NonStop SQL/MX does provide
an SQL descriptor area for dynamic SQL, which consists of multiple item descriptor
areas, together with a count of the number of those item descriptor areas.
In NonStop SQL/MX, you must allocate and deallocate input and output SQL
descriptor areas by using the ALLOCATE DESCRIPTOR and DEALLOCATE
DESCRIPTOR statements. After the parameters have been described (by using the
DESCRIBE statement as in NonStop SQL/MP), you can modify and retrieve
information from the descriptor areas only by using the SET DESCRIPTOR and GET
DESCRIPTOR statements, respectively.
If you have dynamic input parameters in a prepared SQL statement, you must code the
appropriate 3GL statements and use SET DESCRIPTOR to set the values in the
descriptor area. If you have more than one dynamic input parameter, you can identify
the values by their position in the prepared SQL statement. If you are using descriptor
areas for input parameters, you must use the CAST specification to specify the
appropriate data type.
In NonStop SQL/MX, you should give input parameters a defined data type provided in
the descriptor area by using the CAST specification. The CAST specification is not
needed for MXCI parameters or for parameters used in dynamic cursors in embedded
SQL programs.
For examples that use dynamic SQL statements, see the SQL/MX Reference Manual.
Error Handling
The major difference in error handling between NonStop SQL/MP and NonStop
SQL/MX relates to the SQL:1999 standard, as described next.
SQL_PARTITION_NOT_AVAIL -8239 * *
SQL_FILE_SYSTEM_ERROR -8300 -8551 -
SQL_NO_INDICATOR_VAR -8423 -8420 22002
SQL_LOST_OPEN_WARN 8204 8574 -
SQL_LOST_OPEN_ERROR -8204 -8574 -
* Not available. The current release of NonStop SQL/MX does not support the SQL/MP
CONTROL TABLE SKIP UNAVAILABLE PARTITION option.
WHENEVER Declarative
In NonStop SQL/MP, the WHENEVER declarative specifies an action to take when an
error, warning, or no-rows-found condition occurs. Further, NonStop SQL/MP supports
all three actions: CONTINUE, GO TO (or GOTO), and PERFORM (in COBOL) or
CALL (in C).
NonStop SQL/MX continues to support all three conditions, although SQL:1999
supports only SQLERROR and NOT FOUND.
In addition, NonStop SQL/MX continues to support all three actions, although
SQL:1999 supports only CONTINUE and GO TO. Without PERFORM and CALL, the
WHENEVER declarative is inadequate; the problem with supporting only CONTINUE
and GO TO is that a program must pass control to a named procedure. The
assumption is that an error is reported by the procedure, and the application halts
execution. However, in many situations, an application can recover from errors.
Therefore, your application should execute an error-handling procedure and pass
control back to the main program.
For information about handling errors, see Diagnostics Area, next.
In NonStop SQL/MP, the WHENEVER declarative requires a colon (:) before the target
location for the GO TO, PERFORM (in COBOL) or CALL (in C) actions. This restriction
is removed in NonStop SQL/MX.
Diagnostics Area
NonStop SQL/MP provides a communication area (SQLCA) that enables an
application program to check the status of SQL statement execution. You can declare
the communication area by using the INCLUDE SQLCA directive.
NonStop SQL/MX does not provide the SQL communication area or use the INCLUDE
SQLCA directive. Instead, NonStop SQL/MX follows the ANSI SQL:1999 standard by
automatically providing a diagnostics area that stores completion and exception
information.
At the beginning of the execution of an SQL statement, the diagnostics area is emptied
by the preprocessor. When the statement executes, NonStop SQL/MX places
completion and exception information in this area. You can access the information in
the diagnostics area by using the GET DIAGNOSTICS statement.
Suppose your application has executed an SQL statement and the WHENEVER
statement reports an error. To find out more about the results of the executed
statements, code your application to execute a procedure that uses GET
DIAGNOSTICS:
For example, in a C program, the code might look like this:
/* First, get the count of the number of exception conditions.
*/
EXEC SQL GET DIAGNOSTICS :hv_num = NUMBER,
:hv_cmdfcn = COMMAND_FUNCTION,
:hv_dynfcn = DYNAMIC_FUNCTION,
...;
/* Second, get the i-th condition and process it. */
for (i = 1; i <= hv_num; i++) {
EXEC SQL GET DIAGNOSTICS EXCEPTION :i
:hv_tabname = TABLE_NAME,
:hv_colname = COLUMN_NAME,
:hv_sqlstate = RETURNED_SQLSTATE
...;
... /* Process the SQL error information. */
}
Statistics Area
NonStop SQL/MP provides a performance and statistics area (SQLSA) that enables an
application to access this type of information about DELETE, INSERT, SELECT,
UPDATE, OPEN, FETCH, DESCRIBE, and PREPARE statements. NonStop SQL/MX
currently has no structure that corresponds to SQLSA and cannot provide information
on what type of statement was compiled or on the cost of a PREPARE statement.
Program Development
SQL/MP Compiler
Compiling programs using the SQL/MP compiler differs from using the SQL/MX
compiler. In NonStop SQL/MP, compiling a host language program consists of these
steps:
1. Create the host language source file with embedded SQL statements and
directives.
2. Run the C or COBOL compiler to compile the statements in the source file.
3. Run the Binder program if necessary to bind object files.
4. Run the SQL compiler (SQLCOMP).
The result is a valid SQL program file, registered in the catalog and ready for
execution. Graphically, this procedure appears similar to Figure 4-1.
Binder Process to
Combine the Host
Language Object File
Host Language
With Other Object Files
Compiler
Binder Process
Host
Language
Object File
Host Language Object
File With SQL Source
Statements
SQL
Compiler
SQL
Valid SQL Program File
Program File
Ready for Execution
SQL/MX Compiler
The SQL/MX program compilation process is different from that of NonStop SQL/MP.
After you have compiled your program, you have two files: a host language source file
and an SQL/MX module.
This high-level procedure compiles a program with NonStop SQL/MX and is shown in
Figure 4-2 on page 4-12:
1. Using an editor, create the embedded SQL application.
2. Run the SQL/MX host language (C or COBOL) preprocessor to:
• Parse the EXEC SQL statements and replace them with CLI calls.
• Create a module definition file describing the SQL statements. The module
definition file is a separate file instead of being embedded within the compiled
objects.
3. Run the SQL/MX compiler to create execution plans for the SQL statements and
store the plans in a module file.
4. Run the C or COBOL compiler to compile the statements in the source file.
5. Execute the program in the OSS environment, as described in the SQL/MX
Programming Guide for C and COBOL.
NonStop SQL/MX
Host Language
Preprocessor
SQL Module
Host Language Host Language
Source File Definition File
Statements (temporary text file) SQL Statements
(temporary text file)
The key difference in the SQL/MX compilation is the resulting two files: the SQL
module, which stores the query plan, and the host language program file.
For more information about the SQL/MX module, see the SQL/MX Programming Guide
for C and COBOL. For syntax for the MODULE directive, see the SQL/MX Reference
Manual.
Optimizer
The optimizer is the stage in the SQL compiler that optimizes the query and
determines the optimal query execution plan. Many design differences in NonStop
SQL/MX occur before optimization. During the normalization phase, these tasks are
performed:
• Subquery transformation into joins
• Constant folding (for example, b < 0 * c becomes b < 0)
• Predicates pushed down or pulled up
• Other unconditional transformations (for example, left joins transformed to inner
joins)
This table highlights the differences between the SQL/MP and SQL/MX optimizers:
Executor
The executor in NonStop SQL/MX has also been rewritten and takes advantage of
these features:
• Completely no-waited operations
• More work done in the DAM
• Multiple forms of parallelism
• Scalability through parallelism on multiple levels
This table highlights the differences between the SQL/MP executor and the SQL/MX
executor.
Nested Join
1 8
4 5
Scan A Scan B
2 7 Function call
Function call
for scan to 3 6 for scan to
DAM DAM
Join Tasks
Queues
Scan Scan
Building on the previous figure, the next figure shows the steps that the executor might
take to process this simplified query tree. The numbers in the figure relate to the
operations:
1. The join places a request in the down queue of the left scan.
2. The scan places a group of rows in its up queue, which the join retrieves.
3. The join places a request in the down queue of the right scan. At the same time,
the join can place a request in the down queue of the left scan.
4. The right scan places a group of rows in its up queue, which the join retrieves. If
active, the left scan also places a group of rows in its up queue, which the join
retrieves.
The initial request from the join to the left scan queue must occur before the other
operations can begin. After the initial request is processed, both the left and right scans
can be processing information through their queues simultaneously.
Join
1 2 3 4
Scan Scan
The task model makes it easy to perform all internal operations asynchronously so that
a single server thread can have multiple I/Os outstanding. This model also allows
parallelism for both shared memory and distributed memory architectures. In-memory
queues are used for communication, while exchange operators are used for distributed
memory.
Parallelism
In NonStop SQL/MP, parallelism works only on a table that is already partitioned and
only for queries that retrieve data from multiple partitions. NonStop SQL/MX considers
partitioned parallelism in all cases. In addition, NonStop SQL/MX uses pipelined and
independent parallelism.
NonStop SQL/MP does not recognize multilevel parallelism. In NonStop SQL/MP,
either the entire query tree runs in parallel or none of it runs in parallel. NonStop
SQL/MX supports multilevel parallelism, which allows each operator to have a different
level or degree of parallelism, including none.
NonStop SQL/MP uses only ESP parallelism and needs one ESP per base table
partition. The number of ESPs in NonStop SQL/MX is determined more by the number
of available CPUs than it is by the number of partitions in the tables. If a table has
more partitions than available CPUs, the optimizer can group the partitions so that
each ESP processes multiple partitions as if they were a single partition. Each ESP will
group adjacent partitions.
NonStop SQL/MX can merge sorted parallel streams with some restrictions. For
example, a parallel merge join with an ORDER BY clause might not require a final sort.
In SQL/MP, multiple streams must be sorted.
For a full explanation of parallelism in NonStop SQL/MX, see the SQL/MX Query
Guide.
Default Settings
In NonStop SQL/MP, you specify certain default settings through the CONTROL
directives. For example, the CONTROL EXECUTOR directive allows you to specify
whether you want parallel processing on or off. With the CONTROL TABLE directive,
you can specify that you want to use a certain join method or change the timeout
setting. With the CONTROL QUERY directive, you can adjust other default values.
In NonStop SQL/MX, the SYSTEM_DEFAULTS table is a user table that enables you
to specify default settings for options and other attributes when executing MXCI
commands and SQL queries that can be run through MXCI or within an application.
For some attributes, you can override a default value by specifying an option with the
statement or command. You might find it more efficient, however, to configure the
SQL/MX execution environment with default values. NonStop SQL/MX lets you change
the default settings of many more items than NonStop SQL/MP.
If you do not enter an option when entering a command or if you do not provide some
attribute associated with the execution of queries, NonStop SQL/MX chooses a default.
If you have specified system default settings for the execution environment, these
value are used. Otherwise, the SQL/MX default values are used.
In addition to configuring the execution environment with default values through the
defaults tables, in NonStop SQL/MX you can use the CONTROL TABLE and
CONTROL QUERY DEFAULT settings to change default values at run time. For more
information about these commands, see Section 3, DML Features and the SQL/MX
Reference Manual.
NonStop SQL/MX stores system defaults information in the SQL/MP user table named
DEFAULTS, which is registered in the system catalog. For a full listing of default values
that can be changed, see the SYSTEM_DEFAULTS Table entry in the SQL/MX
Reference Manual. See also the SQL/MX Query Guide.
HP NonStop SQL/MX Comparison Guide for SQL/MP Users—523735-003
5 -7
Optimizer and Executor EXPLAIN Features
This table lists some of the differences in default values between NonStop SQL/MP
and NonStop SQL/MX. If you want to mimic an SQL/MP system using NonStop
SQL/MX, you need to reset some default values to get the NonStop SQL/MP behavior.
EXPLAIN Features
Both NonStop SQL/MP and NonStop SQL/MX utilize EXPLAIN features to present
information about query execution plans. In SQL/MP, EXPLAIN is a directive or SQL
utility that describes the execution plan for queries.
In NonStop SQL/MX, you review query execution plans and query performance by
using the EXPLAIN function, DISPLAY_EXPLAIN command, and Visual Query Planner
application. The EXPLAIN function and DISPLAY_EXPLAIN command present query
execution plans in machine-readable format. The Visual Query Planner presents query
execution plans in a graphical user interface through MXCS. Detailed information
about each method is presented in the SQL/MX Query Guide.
Statistics
In NonStop SQL/MP, the UPDATE STATISTICS statement updates the statistics stored
in the catalog for the specified table. In NonStop SQL/MX, the UPDATE STATISTICS
statement updates the histogram statistics for a group of columns within a table.
NonStop SQL/MX provides a method for generating histograms that shows how data is
distributed for a column within a table. The purpose of generating these statistics is to
enable the optimizer to create more efficient data query execution plans.
When generating a histogram for a table, NonStop SQL/MX divides the range of
specified column values of the table into some number of intervals, distributing the
rows evenly within these intervals. It computes statistics associated with each interval
and uses the statistics to devise optimized plans.
For further information, see the UPDATE STATISTICS Statement and User Metadata
(UMD)—Histogram Tables entries in the SQL/MX Reference Manual. The SQL/MX
Query Guide contains a section on keeping statistics current and best practices to
follow with respect to statistics.
SQL Statements
You can now create, alter, and drop SQL/MX database objects similarly to how you
manipulate these objects in NonStop SQL/MP, with these exceptions:
• You cannot create collations for SQL/MX tables, so there is no CREATE
COLLATION statement. You create constraints at CREATE TABLE time or later
with a ALTER TABLE ADD CONSTRAINT statement, so there is no separate
CREATE CONSTRAINT statement. You drop constraints with the ALTER TABLE
DROP CONSTRAINT statement.
• You cannot alter catalogs, collations, programs or views.
• The generic DROP command has been replaced by specific DROP CATALOG,
DROP INDEX, DROP PROCEDURE, DROP SCHEMA, DROP SQL, DROP
SQLMP ALIAS, DROP TABLE, DROP TRIGGER, and DROP VIEW statements.
See the SQL/MX Reference Manual for information about statements and database
objects.
ANSI Names
Namespace for SQL/MX objects is organized in a hierarchical manner. Database
objects exist in schemas, which are themselves contained in catalogs. Catalogs are
collections of schemas. Schema names must be unique within a given catalog. Multiple
objects with the same name can exist provided that each belongs to a different
namespace. NonStop SQL/MX supports various types of namespaces. See “SQL/MX
Language Elements” in the SQL/MX Reference Manual for details about these
namespaces.
You reference SQL/MP database objects by using their Guardian physical names. To
allow for the use of ANSI logical names, NonStop SQL/MX creates a metadata table,
the OBJECTS table. This table is used to store object names. Mappings from logical
object names to physical Guardian locations are stored in the metadata table
MP_PARTITIONS.
Use the CREATE SQLMP ALIAS command within your application to create needed
mappings from logical to physical names. This command inserts a mapping as a row in
the OBJECTS table. SQL/MP aliases are true ANSI names that represent the
underlying Guardian physical names of SQL/MP objects, in which the catalog part
refers to an existing catalog and the schema part refers to an existing schema.
SQL/MX Catalogs
An SQL/MX catalog is a named logical object that contains descriptions of a set of
schemas. You can access SQL/MX objects with the three-part name of the actual
object.
A catalog can contain multiple schemas, each possibly owned by a different user. A
catalog cannot contain other catalogs. Any user on a node can create a catalog on that
node. Any user on a node can drop an empty catalog on that node. For more
information, see “SQL/MX Language Elements” in the SQL/MX Reference Manual.
NonStop SQL/MX uses ANSI-compliant CREATE and DROP statements to create and
drop catalogs and schemas. Note that catalog names beginning with
“NONSTOP_SQLMX_” are reserved for system metadata.
SQL/MP Catalogs
An SQL/MP catalog is a set of tables and indexes that describe SQL objects. Tables in
the set are called catalog tables and SQL creates them, along with their indexes, when
you execute a CREATE CATALOG statement. Each SQL/MP catalog (the set of
catalog tables and their indexes) resides on its own Guardian subvolume, and the
name of that subvolume is also the name of the catalog.
Each node on which SQL/MP is used has one special catalog called the system
catalog and might have many other catalogs. Each table, view, index, partition,
collation, or catalog table located on a node must be described in a catalog on the
same node. Normally, an SQL program is registered in a catalog, too. For more
information, see the SQL/MP Reference Manual.
NonStop SQL/MP allows you to create catalogs and to drop system catalogs.
Metadata
The system catalog is NONSTOP_SQLMX_nodename. SQL/MX metadata is
organized within these system schemas:
SYSTEM_SCHEMA System schema tables that list information such as
catalogs and schemas in the system.
DEFINITION_SCHEMA_ Definition schema tables that list information such as
VERSION_versnum columns in tables, constraints, partitions, views,
procedures and so on.
SYSTEM_DEFAULTS_ User-provided system defaults.
SCHEMA
MXCS_SCHEMA MXCS subsystem data source and governing
information.
SYSTEM_SQLJ_SCHEMA System schema that contains only the stored
procedure VALIDATEROUTINE, which is for internal
use.
SQL/MX’s metadata is on the same subvolume as the system catalog, which you
specify when you install NonStop SQL/MX.
SQL/MP metadata, also called the Data Dictionary, is organized by disk. It consists of
all the catalogs on a network and labels for each file on the volume. The label includes
the name or the object, the name of the catalog that describes the object, and other
information about the file.
SQL/MP metadata is the combination of system catalog metadata and user catalog
metadata. NonStop SQL/MP creates the system catalog when you issue the CREATE
SYSTEM CATALOG command, in whatever catalog you specify. The default is
$SYSTEM.SQL. Each catalog of user metadata resides on its own Guardian
subvolume.
Previous releases of NonStop SQL/MX use a different table scheme for metadata
where metadata resided in SQL/MP tables registered in the SQL/MP catalog. For
SQL/MX Release 2.0, metadata resides in SQL/MX metadata tables. The MIGRATE
utility is provided to move metadata from previous releases of NonStop SQL/MX to
current metadata tables. For more information about this utility, see the SQL/MX
Installation and Management Guide and the SQL/MX Reference Manual.
Tables
You create constraints on an SQL/MX table with the CREATE TABLE and ALTER
TABLE ADD CONSTRAINT statements. You create constraints on SQL/MP tables with
the CREATE CONSTRAINT statement.
Clustering Keys
You assign a clustering key for an SQL/MX table by using the STORE BY clause of the
CREATE TABLE statement. If you enter STORE BY PRIMARY KEY, NonStop SQL/MX
bases the clustering key on the primary key. The STORE BY clause determines the
order of rows in the physical file and affects how you can partition the file.
You assign a clustering key for an SQL/MP table by using the CLUSTERING KEY
clause of the CREATE TABLE statement, listing the columns that will be used for this
key. SQL/MP stores rows in ascending or descending order, as you specify. You
cannot control the order of rows in the physical file.
Table Attributes
NonStop SQL/MX allows you to set these table attributes: ALLOCATE,
AUDITCOMPRESS, BLOCKSIZE, CLEARONPURGE, EXTENT, and MAXEXTENTS.
NonStop SQL/MP allows you to set these table attributes: ALLOCATE, AUDIT,
AUDITCOMPRESS, BLOCKSIZE, BUFFERED, CLEARONPURGE, DCOMPRESS,
EXTENT, FORMAT, ICOMPRESS, LOCKLENGTH, MAXEXTENTS, NOPURGEUNTIL,
RECLENGTH, TABLECODE, and VERIFIEDWRITES.
File Types
You can access these type of SQL/MP files through NonStop SQL/MX:
• Key-sequenced tables with or without partitions
• Entry-sequenced tables that are not partitioned
You cannot access these type of SQL/MP files through NonStop SQL/MX:
• Entry-sequenced tables that are partitioned
• Relative tables
Constraints
You create constraints on SQL/MX tables with the CREATE TABLE statement, and you
can add or drop constraints with the ALTER TABLE statement. For more information,
see “SQL/MX Language Elements” in the SQL/MX Reference Manual.
To create constraints on an SQL/MP table, use the SQL/MP CREATE CONSTRAINT
statement when you create the table. To drop constraints on an SQL/MP table, use the
SQL/MP DROP statement.
Indexes
You can create indexes for SQL/MX files, with these differences from NonStop
SQL/MP:
• Index table attribute
NonStop SQL/MX allows you to set these index table attributes: ALLOCATE,
AUDITCOMPRESS, BLOCKSIZE, CLEARONPURGE, EXTENT, and
MAXEXTENTS.
NonStop SQL/MP allows you to set these index table attributes: ALLOCATE,
AUDITCOMPRESS, BLOCKSIZE, BUFFERED, CLEARONPURGE,
DCOMPRESS, EXTENT, FORMAT, ICOMPRESS, ISLACK, LOCKLENGTH,
MAXEXTENTS, NOPURGEUNTIL, SERIALWRITES, SLACK,TABLECODE, and
VERIFIEDWRITES.
• Index table access
NonStop SQL/MX does not support WITH SHARED ACCESS.
• Partition changes
NonStop SQL/MX allows you to define secondary partitions as range or hash
partitions.
• Populating indexes
If you are creating an index on a large SQL/MX table that is already populated, you
should use the NO POPULATE option, and then run the POPULATE INDEX utility
to load the index. Because CREATE INDEX executes in a single TMF transaction,
it could experience TMF limitations such as a transaction timeout if a large amount
of data is to be moved. See the SQL/MX Installation and Management Guide for
information about creating and populating indexes and the SQL/MX Reference
Manual for details about the CREATE INDEX statement and the POPULATE
INDEX utility.
• PARALLEL EXECUTION ON | OFF option
NonStop SQL/MX uses the optimizer to determine whether to perform parallel
index loading. It is not a specifiable attribute.
• INVALIDATE | NO INVALIDATE option
SQL./MX does not allow you to control whether or not changes to indexes cause
similarity checks and possible recompiles.
Partitions
NonStop SQL/MX allows you to locate as many partitions as you want on the same
disk. Like SQL/MX tables, partitions use ANSI logical names. You can specify
Guardian names for a partition.
NonStop SQL/MP allows no more than one partition of an object on each disk.
SQL/MP partitions have Guardian names.
You manage partitions differently in NonStop SQL/MX and NonStop SQL/MP. For
details, see Partition Management: The MODIFY Utility on page 7-2
Views
SQL/MX Views
The distinction between protection and shorthand views does not exist for SQL/MX
views. To create a view, you must have SELECT privileges for the objects underlying
the view.
NonStop SQL/MX supports UNION in a view definition.
For information about SQL/MX views, see “SQL/MX Language Elements” in the
SQL/MX Reference Manual.
SQL/MP Views
An SQL/MP view is either a protection view or a shorthand view. A protection view is
derived from a single table and can be read, updated, and secured. A shorthand view
is derived from one or more tables or other views and inherits the security of the
underlying tables. A shorthand view can be read but not updated.
To create a view, you must have authority to write to the catalog that receives the view
description and to the USAGES tables of catalogs describing the underlying tables and
views.
To create a protection view, you must also be a generalized owner of the underlying
table. Any partitions or indexes of the table underlying the protection view must be
accessible when you create the view. To specify read or write access for a protection
view, you must have authority to read or write to the underlying table and all associated
indexes (unless you are the super ID).
NonStop SQL/MX and NonStop SQL/MP handle security on views differently. In
NonStop SQL/MP, you need to have appropriate security on the underlying tables of
the view in order to update the view. In NonStop SQL/MX you need only to have
appropriate security on view itself. You do not need to have privileges on the
underlying table.
For information about SQL/MP views, see Views in the SQL/MP Reference Manual.
Object Security
NonStop SQL/MX uses GRANT and REVOKE statements that conform to the ANSI
SQL standard to control privileges for objects. It does not support a SECURE clause.
Security is controlled internally by the software and does not use the security vector.
NonStop SQL/MP uses the SECURE clause to specify a Guardian security string,
“RWEP” to secure objects. security is controlled by the Guardian security vector stored
in the label.
IMPORT Command
You can use SQL/MX’s IMPORT command to import data from a file (ASCII or binary)
into a NonStop SQL/MX table. IMPORT executes at the OSS or MXCI command
prompt. It is similar to but not equivalent to SQL/MP’s LOAD command. See “SQL/MX
Utilities” in the SQL/MX Reference Manual for details.
MXTOOL Utility
Earlier releases of NonStop SQL/MX supported only a limited set of tools with the
MXTOOL utility. NonStop SQL/MX Release 2 provides a tool, the MXTOOL utility, that
gives you additional options. The MXTOOl utility allows you verify the contents of an
SQL/MX object, fix parts of the metadata and label information, return information
about SQL/MX objects, and remove both damaged and undamaged objects from
metadata or labels in a uniform way.
The MXTOOL utility performs these operations:
FIXUP Similar to various SQL/MP operations
SHOWDDL Command
SQL/MX’s SHOWDDL command displays a DDL statement that would create a table,
view, or stored procedure as it exists in metadata, including the object’s dependent
objects. This output can be used to re-create the specified object, including its
dependent objects.
SHOWDDL is similar to SQL/MP’s INVOKE command, which produces a record
description that corresponds to a row in a specified table or view.
See “MXCI Commands” in the SQL/MX Reference Manual for more information.
SHOWLABEL Command
SQL/MX’s SHOWLABEL command displays file-label and resource-fork information for
SQL/MX tables, worktables, views, and indexes. The information includes the object
version, physical location, and other characteristics.
Every SQL object includes a logical file label to store the object’s file attributes and
information about its dependent objects. The resource fork is a new file that contains
structural descriptions of a table. When an SQL/MX object is created, two physical files
are instantiated: the data fork and the resource fork. The data fork is where the user
data resides. The resource fork contains structural information, such as the partition
map.
SHOWLABEL is similar to SQL/MP’s FILEINFO utility, which displays information
about the versions and physical characteristics of tables, indexes, views, collations,
Enscribe files, and OSS files.
For more information, see “MXCI Commands” in the SQL/MX Reference Manual.
V
VARCHAR data type 4-2
VARCHAR_WIDTH option 2-17
VERIFIEDWRITES file attribute 2-17
VERIFY command 7-2
Versioning 3-29
Versions 2-18
VERSIONS table 2-18
Views 6-6
VIEWS table 2-18
VOLUME command 2-18
W
WHENEVER declarative 4-9
WHENEVER directive 2-18
WHERE clause 2-18
WINDOW option 2-18
WITH SHARED ACCESS option 2-18
Special Characters
! command 2-18