One of the central features of InterSystems IRIS™ is its multidimensional storage engine. This feature lets applications store data in compact, efficient, multidimensional sparse arrays. These arrays are referred to as globals.

This document describes:

What globals are and the operations you can perform on them.

The logical and physical structure of globals, including the use of globals in distributed database architecture.

Sparse  The subscripts used to address global nodes are highly compacted and need not have contiguous values.

Efficient  The operations on globals  inserting, updating, deleting, traversing, and retrieving  are all highly optimized for maximum performance and concurrency. There are additional commands for specialized operations (such as bulk inserts of data). There is a special set of globals designed for temporary data structures (such as for sorting records).

Reliable  The InterSystems IRIS database provides a number of mechanisms to ensure the reliability of data stored within globals, including both logical-level and physical-level journaling. Data stored within globals is backed up when a database backup operation is performed.

Distributed  InterSystems IRIS provides a number of ways to control the physical location of data stored within globals. You can define a physical database used to store a global, or distribute portions of a global across several databases. Using the distributed database features of InterSystems IRIS, you can share globals across a network of database and application server systems. In addition, by means of mirroring technology, data stored within globals on one system can be automatically replicated on another system.

Concurrent  Globals support concurrent access among multiple processes. Setting and retrieving values within individual nodes (array elements) is always atomic: no locking is required to guarantee reliable concurrent access. In addition, InterSystems IRIS supports a powerful set of locking operations that can be used to provide concurrency for more complex cases involving multiple nodes. When using object or SQL access, this concurrency is handled automatically.

Transactional  InterSystems IRIS provides commands that define transaction boundaries; you can start, commit, or rollback a transaction. In the event of a rollback, all modifications made to globals within the transaction are undone; the contents of the database are restored to their pre-transaction state. By using the various InterSystems IRIS locking operations in conjunction with transactions, you can perform traditional ACID transactions using globals. (An ACID transaction provides Atomicity, Consistency, Isolation, and Durability.) When using object or SQL access, transactions are handled automatically.

Note:

The globals described in this document should not be confused with another type of InterSystems IRIS array variable: process-private globals. Process-private globals are not persistent; they persist only for the duration of the process that created them. Process-private globals are also not concurrent; they can only be accessed by the process that created them. A process-private global can be easily distinguished from a global by its multi-character name prefix: either ^|| or ^|"^"|.

Examples

A simple example can demonstrate the ease and performance of globals. The following program example creates a 10,000node array (deleting it first if present) and stores it in the database. You can try this to get a sense of the performance of globals:

—Creating a Persistent Array—

Setstart=$ZH// get current timeKill^Test.GlobalFori=1:1:10000{Set^Test.Global(i)=i}Setelap=$ZH-start// get elapsed timeWrite"Time (seconds): ",elap

We can also see how long it takes to iterate over and read the values in the array (make sure to run the above example first to build the array):

—Reading a Persistent Array—

Setstart=$ZH// get current timeSettotal=0Setcount=0// get key and value for first nodeSeti=$Order(^Test.Global(""),1,data)While(i'=""){Setcount=count+1Settotal=total+data// get key and value for next nodeSeti=$Order(^Test.Global(i),1,data)}Setelap=$ZH-start// get elapsed timeWrite"Nodes: ",count,!Write"Total: ",total,!Write"Time (seconds): ",elap,!

Use in Applications

Within InterSystems IRIS applications, globals are used in many ways, including:

As the underlying storage mechanism shared by the object and SQL engines.

As the mechanism used to provide a variety of indices, including bitmap indices, for object and SQL data.

As a work space for performing certain operations that may not fit within process memory. For example, the SQL engine uses temporary globals for sorting data when there is no preexisting index available for this purpose.

For performing specialized operations on persistent objects or SQL tables that are difficult or inefficient to express in terms of object or SQL access. For example, you can define a method (or stored procedure or web method) to perform specialized analysis on data held in a table. By using methods, such an operation is completely encapsulated; the caller simply invokes the method.

To implement application-specific, customized storage structures. Many applications have the need to store data that is difficult to express relationally. Using globals you can define custom structures and make them available to outside clients via object methods.

For a variety of special purpose data structures used by the InterSystems IRIS system, such as configuration data, class definitions, error messages, and executable code.

Globals are not constrained by the confines of the relational model. They provide the freedom to develop customized structures optimized for specific applications. For many applications, judicious use of globals can be a secret weapon delivering performance that relational application developers can only dream about.

Whether your application makes direct use of globals or not, it is useful to understand their operation. Understanding globals and their capabilities will help you to design more efficient applications as well as provide help with determining the optimal deployment configuration for your applications.