Chapter 5. Querying the Database

Table of Contents

Overview
A First Proximity Query
Exploring Containers and Subgraphs
Grouping Elements in a Query
Comparing Items in a Query
Matching Complex Subgraphs with Subqueries
Adding Links to Data with Queries
Executing a Query from the Proximity Database Browser
Executing a Query from the Command Line
Querying Containers
Tips and Reminders

Overview

Proximity uses QGraph [Blau, Immerman, and Jensen, 2002], a visual query language, for defining queries. This chapter provides information on QGraph’s features and walks through the process of creating several example queries. See the Proximity QGraph Guide for a full description of the QGraph language as implemented in Proximity.

A QGraph query is a labeled graph of vertices and edges. The query vertices correspond to objects in the database and the query edges correspond to links in the database. QGraph lets you easily describe a specific configuration of objects and links, conditions (required attribute values), and global constraints (restrictions across objects or links). To match a query, a database subgraph must have the correct structure and satisfy all the conditions and constraints.

The result of executing a QGraph query is a collection of matching subgraphs called a container. When you execute a query, the container holding the matching subgraphs is added as a persistent item in the Proximity database. Proximity creates an empty container when the query returns no matching subgraphs.

QGraph also provides extensive data update functionality; however, only a portion of this functionality has been implemented in Proximity to date. Proximity implements the ability to add links to the database through the use of QGraph queries.

Proximity represents queries in an XML format. Although you can create queries by writing this XML representation in a text editor, Proximity provides a Query Editor that lets you create queries interactively using a natural graphical representation. The exercises in this chapter use the Query Editor to create queries of increasing complexity, illustrating the range of QGraph’s functionality as implemented in Proximity. Details on the query XML file format are included in the Proximity QGraph Guide .

Proximity provides many ways to execute queries. This tutorial describes how to execute queries

  • from the Query Editor

  • from the Proximity Database Browser

  • from the command line using Proximity shell scripts

You can also call methods that execute queries from within Proximity Python scripts or Java programs.

All of the queries used in this chapter are available in $PROX_HOME/doc/user/tutorial/examples. You can follow the exercises in this chapter to create the queries interactively or execute the example queries provided with the Proximity distribution.

Objectives

The exercises in this chapter demonstrate how to

  • create queries using the Query Editor

  • add links to the data by executing queries

  • execute queries from the Query Editor, Proximity Database Browser, and command line

  • execute a query against the contents of a container

  • examine query results (containers and subgraphs)

  • create the database entities used in later tutorial exercises

Each exercise in this chapter introduces new QGraph features. A complete explanation of the QGraph query language is available in the Proximity QGraph Guide . The “Tips and Reminders” section at the end of this chapter provides a summary of rules for well-formed QGraph queries.