Skip to content

Relationships#

A relationship says how a fact table is joined with another: the invoices with their lines, the customers with their invoices, the products with the lines. With relationships, a user combines in the same cube metrics and dimensions of several tables without knowing how they are joined, and the universes of a table reach those that depend on it. They are designed in the editor's Relationships tab, in a diagram or in a list.

Before you start#

  • You need Metadata administration.
  • Both tables have to be fact tables of the connection. Auxiliary tables are not related here: they are linked from each dimension.

What defines a relationship#

Part What it is
Master table The one on the “one” side: a customer, an invoice.
Detail table The one on the “many” side, or the other one in a one-to-one relationship: the customer's invoices, the invoice's lines.
Relationship type “One row of “Facturas” with several of “Líneas”” (one to many) or “One row of “…” with one of “…”” (one to one).
Join type Inner: only the rows of the two tables that are joined. Outer: all the rows of the master, whether or not they have rows in the detail. The outer join only applies when traversing the relationship from the master to the detail; in the opposite direction it is joined as inner.
Joined columns One or more pairs of columns joined by equality (NUM_FACTURA = NUM_FACTURA). If the catalog gives different types to the two columns of a pair, it warns; an integer and a decimal number are joined without problem.
Description Optional, up to 75 characters.
Preferred To decide between several equally short paths (below).

How they are used in queries#

  • To join tables. A query starts from the table of the first metric and joins the other tables it needs by the shortest path of relationships. If there is no path, the query cannot be made and says so.
  • Between equally short paths, the one that goes through more preferred relationships is used. If they still tie, the first one, and “Show SQL” warns of it. Two relationships between the same two tables are two paths: the dialog warns of it when creating the second (“There is already a relationship between these tables: there will be two paths and the preferred one decides.”).
  • To propagate universes. A universe of a master table also limits the rows of its detail tables (the customers' universes reach their invoices and, through them, their lines). The same happens between two tables with a one-to-one relationship.
  • To avoid repeating records. If a segmentation sets a condition on a detail table of the query (the customers with some line of screws, in a customer cube), that table is not joined: the condition goes in a subquery, so that each customer counts once.

That is why cardinality matters: a relationship marked “one to one” that is actually “one to many” repeats rows and over-counts. Check the figures with a test cube after creating or changing relationships.

The diagram#

The tab opens in Diagram. Each fact table is a box with its columns, and each relationship a line with its label. Relationships with problems (a column that is no longer in the catalog, different types) carry the Review mark, and preferred ones, Preferred.

The relationship diagram of the demonstration with Clientes, Facturas, Líneas, Productos and IncidenciasThe relationship diagram of the demonstration with Clientes, Facturas, Líneas, Productos and Incidencias
The relationship diagram of the demonstration with Clientes, Facturas, Líneas, Productos and Incidencias
Tool What it does
Search table Takes you to a table of the diagram and chooses it.
Add tables to the diagram… Adds fact tables that are not shown. Relationships appear with their tables.
Remove from the diagram Removes the chosen table from the diagram, without touching its relationships.
Collapse and Expand Shows only the header of the chosen table, or all its columns.
Only those related to the chosen one Leaves in view the chosen table and those related to it.
Arrange automatically Rearranges the tables.
View › Show all columns Shows all the columns, not only those that join.
View › Show the physical name Labels the tables with their database name instead of the alias.
View › 10 px snap grid Aligns the tables when moving them.
Zoom in, Zoom out, Fit to view and Minimap Zoom and a small map of the diagram.

With the diagram:

  • Drag a column of a table onto a column of another to create a relationship: New relationship opens with the pair already set.
  • Click a relationship's label to open its properties.
  • Drag the tables to place them. The layout is saved by itself, for all the connection's administrators. If someone else changes it at the same time, a strip says so with Reload.
  • With the keyboard, the arrows go to the neighboring table or relationship, Alt with the arrows moves the table, Enter on a table opens the list filtered by it and Enter on a relationship opens it. The list does the same as the diagram with the keyboard.

With more than 150 tables in view, the diagram is slow and offers Search table, View the … tables anyway or View the list.

The list#

List shows the relationships in a table, with a filter by Table:

Column What it says
Master and Detail The two tables.
Type One to many or One to one.
Join Inner or Outer.
Columns The pairs of columns.
Description The description, if it has one.
Preferred Preferred or No.
Status Successful, New (created in this session), Unchecked (the columns of its tables are not known yet) or Review, with the problem.

The ⋯ menu of each row has Properties…, How are they joined?, View in the diagram, Who uses it? and Delete….

Create a relationship#

  1. Click New relationship… (or drag a column onto another in the diagram).
  2. Choose the Master table and the Detail table. The arrows button swaps them.
  3. Choose the Relationship type and the Join type.
  4. In Joined columns, choose each pair: a column of the master and another of the detail. With Add a pair of columns more are added.
  5. Type the Description, if you want, and check Preferred if it is the path queries should use.
  6. Click Create relationship.

To change it, open it from the diagram or the list, change what you need in Relationship properties and click Save changes. If the change affects documents, the impact is shown first.

The Relationship properties dialog of Facturas → Incidencias, one to many, outer, by NUM_FACTURAThe Relationship properties dialog of Facturas → Incidencias, one to many, outer, by NUM_FACTURA
The Relationship properties dialog of Facturas → Incidencias, one to many, outer, by NUM_FACTURA

In the demonstration, Facturas → Incidencias is a relationship defined by hand, Outer, because there is no foreign key between them in the database.

Propose from the foreign keys#

Propose from the foreign keys… lists the database's foreign keys between fact tables that do not have a relationship yet, with the sentence of each one. Check those you want and click Create 7 relationships (or however many). They are created with an inner join; afterwards they are changed in their properties.

If there are none, the dialog says so: those in the catalog are already relationships, or they do not join fact tables. If the database has changed, refresh the catalog first. In the demonstration 7 are proposed; the foreign key of VENDEDORES.JEFE to the table itself is not proposed.

How are they joined?#

How are they joined? opens a side panel to check how ECenter joins two fact tables:

  1. Choose the From table and the To table.
  2. The panel looks for the equally short relationship paths between them and asks the database for the plan of each one, without running it.
  3. Each Path states its relationships (with the Preferred mark on those that are), the join a query would write (with Copy), what the database estimates (The database plan) and, if it is the one queries use today, Used today.
  4. On one that is not used, Prefer this path marks its relationships as preferred, after showing which documents change path.

Use it when a figure does not add up, before adding a relationship that creates another path and to see whether a join has a reasonable plan in the database.

Delete a relationship#

Choose the relationship and click Delete… (or Del on its label or in the list). ECenter first shows what changes: the documents that can no longer join their tables and the universes that stop propagating. In the demonstration, deleting Facturas → Líneas would make the lines stop inheriting the invoices' zone universes.

See also#