Creating join indexes

In addition to the column indexes, Sybase IQ allows you to define join indexes. Join indexes are Sybase IQ internal structures that optimize joins of related tables. In Performance and Tuning Guide you will learn more about join relationships between tables. In this chapter, tutorial instructions will supply join information for you to use in creating join indexes.

Join indexes are created on sets of columns rather than individual columns. A join index represents a full outer join of two or more tables. The query engine may use this full outer join as a starting point for queries that include left outer, right outer, and inner joins. You can create a join index for any set of columns that your users commonly join to resolve queries. For guidelines about creating join indexes, see the System Administration Guide: Volume 1 and Joining Tablesin Performance and Tuning Guide.

You should note three important rules about creating join indexes:

The following tasks show how to create join indexes. Refer to “The demo database” to see which columns are in each table in this example.

NoteSome additional tasks are required for multiplex databases. Please see Using Sybase IQ Multiplex instead of this chapter if you need to create join indexes in a multiplex.

The first join index, so_soi_jdx, will join the sales_order and sales_order_items tables. To create it, follow these steps:

StepsCreating a join index for SalesOrders and SalesOrderItems

  1. In Folders view, right-click Join Indexes, point to New, choose Join Index.

  2. In the Name and Table dialog, type so_soi_jdx for the name.

  3. In the Join Type dropdown list, select Natural, because you are joining equivalent columns with the same name (id) from two tables. For more details, see Performance and Tuning Guide.

    NoteWhen joining with the NATURAL keyword, take care that only the columns to be joined have the same name. (For example id = id.) Watch out for common column names like date and description.

  4. Choose SalesOrders for the left table.

  5. Choose SalesOrderItems for the right table.

  6. Click Next. Sybase IQ locates the join columns.

  7. In the Comment space, type the following to describe the join index, Join index for SalesOrders and SalesOrderItems.

  8. Click Finish.

The so_soi_jdx join index appears in the Join Indexes folder.

StepsCreating a join index for department and employee

Now create a join between Departments and Employees, using equivalent values in columns from two tables. Follow these steps to create this joined index, which we will call dept_emp_jdx:

  1. In Folders view, right-click Join Indexes, point to New, choose Join Index.

  2. Type the name of your new join index, dept_emp_jdx, in the Name box.

  3. In the Join Type dropdown box, select ON. The ON clause is required in order to join equivalent columns with the same name (dept_id) from two tables.

  4. Choose Departments for the left table.

  5. Choose Employees for the right table.

  6. Click Next.

  7. In the Choose Index Columns dialog, select the desired Left Table column, DepartmentID and the Right Table column DepartmentID.

  8. Click Add. After you add the two columns, they appear in the Join Index Columns box as GROUP0.Departments.DepartmentID=GROUP0.employees.DepartmentID. (You may have to scroll to read the entire join.)

  9. Click Next.

  10. On the Add Comment screen, type the following to describes the join index, Join index for Departments and Employees. Click Finish.

  11. The dept_emp_jdx join index appears in the Join Indexes folder.

For detailed information about planning and creating join indexes, see System Administration Guide: Volume 1.