Skip to content

Data Models in InterSystems IRIS


Explore globals, multi-model data access, and various data storage approaches in InterSystems IRIS®.

QuickStart

InterSystems IRIS stores data in persistent, multidimensional arrays called global variables, which is generally shortened to globals. Globals are hierarchical and sparse, and do not require a predefined schema.

The same data stored in globals can be accessed through multiple models, including relational tables, objects, key-value structures, and documents. They are called globals because they are persistent and can be accessed across processes, throughout the system.

Globals can be visualized as a tree diagram, where each node of the tree has a key, or subscript, and may have value.

Tree diagram of a global showing subscripts and values

Globals are sparse: storage is allocated only for nodes that contain data or have defined descendants. Subscripts do not need to be contiguous, and undefined nodes consume no storage.

For example, in the diagram above, the Subscript2 node does not have a value, and only exists because the node at Subscript 3 is defined as ^GlobalName("Subscript1", "Subscript2", "Subscript3") = Value. An empty node, like that at Subscript2 does not cost any resources.

InterSystems IRIS is optimized for efficient access to global data, including high-volume transactional workloads.

Datatypes

Global subscripts and values can contain several types of data. For example, sequential integer subscripts can represent a numbered array, while values can contain strings, numbers, or encoded lists.

Global structure showing numbered array nodes and list values

Accessing Globals Directly

In ObjectScript, global references begin with a caret (^), which differentiates a variable from a standard variable.

To access a specific global node, provide its subscript or sequence of subscripts in parentheses.

// Set the root node
set ^Demo = 1
// Node 1
set ^Demo(1) = "Hello"
// Node 1,2
set ^Demo(1, 2) = 45
// Node 1,2,'foo'
set ^Demo(1, 2, "foo") = $LISTBUILD("A", "B", "C", 1)
// Node 4
set ^Demo(4) = "World!"

We can use the same method to access the values:

write ^Demo
// Output: 1

write ^Demo(1, 2, "foo")
// Output: $lb("A","B","C",1)    Note $lb() is short for $ListBuild and refers to a list object

To display the referenced global and its descendants, use the ZWRITE command:

zwrite ^Demo
/* output:
^Demo=1
^Demo(1)="Hello"
^Demo(1,2)=45
^Demo(1,2,"foo")=$lb("A","B","C",1)
^Demo(4)="World!"
*/

Accessing Globals with an Object Model

As the Class Programming Quickstart shows in detail, we can define persistent classes whose instances are stored in the database. In these cases, InterSystems IRIS stores the persistent data in globals.

Class Sample.Pets Extends %Persistent
{
    // Name of Pet
    Property Name As %String;
    // Type of Animal
    Property Type As %String;
    // Age of Pet
    Property Age As %Integer;
}

We can use this to create a new Pet object as follows:

set newpet = ##class(Sample.Pets).%New()
set newpet.Name = "Whiskers"
set newpet.Type = "Cat"
set newpet.Age = 3
do newpet.%Save()

When the object is saved, the persistent property values will be stored in the database as globals. This global will, by default, share the name of the class with a 'D' character appended. For the above Sample.Pets example, the data should be found in the global ^Sample.PetsD.

zwrite ^Sample.PetsD
/*output:
^Sample.PetsD=1
^Sample.PetsD(1)=$lb("","Whiskers","Cat",3)
*/

The class storage definition determines the structure of the generated global. In this example, the record with ID 1 is stored beneath ^Sample.PetsD(1). Applications should use the class and SQL interfaces rather than relying on the generated storage layout.

The list begins with an empty element, this value is reserved for the name of a subclass.

To access a specific value, we can use .%OpenId():

set pet = ##class(Sample.Pets).%OpenId(1)
zwrite pet
/*output:
+----------------- general information ---------------
|      oref value: 2
|      class name: Sample.Pets
|           %%OID: $lb("1","sample.Pets")
| reference count: 2
+----------------- attribute values ------------------
|       %Concurrency = 1  <Set>
|                Age = 3
|               Name = "Whiskers"
|               Type = "Cat"
+-----------------------------------------------------
*/

Accessing Globals with SQL (Relational model)

Persistent classes can project data stored in globals as relational tables. These can be queried, created or modified using SQL.

To see the data we created above, we can use:

Select ID, Name, Type, Age 
FROM Sample.Pets

which would output the following table:

IDNameTypeAge
1WhiskersCat3

You can also insert rows using SQL. Run each INSERT statement separately in interfaces that accept only one statement at a time.

INSERT INTO Sample.Pets (Name, Type, Age) VALUES ('Fido', 'Dog', 5)

INSERT INTO Sample.Pets (Name, Type, Age) VALUES ('Bugs', 'Rabbit', 95)

As we are accessing the same persistent class, these values appear in the same underlying ^Sample.PetsD global. We can see these values with:

zwrite ^Sample.PetsD
/* output:
^Sample.PetsD=3
^Sample.PetsD(1)=$lb("","Whiskers","Cat",3)
^Sample.PetsD(2)=$lb("","Fido","Dog",5)
^Sample.PetsD(3)=$lb("","Bugs","Rabbit",95)
*/

We can therefore visualize the following table:

IDNameTypeAge
1WhiskersCat3
2FidoDog5
3BugsRabbit95

as the global shown here:

Global sample.PetsD showing Whiskers, Fido and Bugs as list nodes

Using the globals explorer page

We can see globals using the Globals page of the Management Portal. This page can be found from the homepage in the System Explorer tab. The exact URL will vary depending on your server, web-server port and namespace, but for a default local installation, the URL may resemble the following: http://localhost:52773/csp/sys/exp/%25CSP.UI.Portal.GlobalList.zen?$NAMESPACE=USER. We can filter the globals by name, using * as a wildcard:

Management portal Globals Explorer page filtering globals by name

Clicking on View will display the data stored in the global:

Globals Explorer displaying the data stored in the sample.PetsD global

For a detailed explanation of globals, see: Video: What Are Globals? | Youtube


Documentation

Go to Documentation page: Introduction to Globals


Application Examples

Community Built Project
a simple demo of InterSystems IRIS multi-model data management via REST API
Community Built Project
Advanced Globals Viewer for InterSystems IRIS
InterSystems Learning
This sample shows how to access data using object, relational, and native data models from an ObjectScript application.
InterSystems Learning
This repository provides the sample class definition and data that you will need to work through the demo in Exploring Multiple Data Models with Globals learning exercise.


Tutorials & Articles

Launch Interactive Tutorial: Data Models of InterSystems IRIS
In this hands-on, interactive tutorial, you’ll get a practical introduction to InterSystems IRIS data modeling concepts — all directly in your browser, with no local setup required.

Article: Data models in InterSystems IRIS

Article: InterSystems IRIS Data Models Explained: Hierarchical, Key-Value, Object, Document, Relational, and Columnar


 
 

Where to Go From Here

Congratulations! You've completed this quickstart.

x
Currently deployed:
PR change was detected!
was replaced by
Please refresh the page to see the changes!