Bitmap subscriptions

Bitmap subscriptions allow you to create subscriptions that replicate rows based on bitmap comparisons. When you create a replication definition for a table, specify the datatype of your bitmap columns as rs_address. This special datatype tells Replication Server to treat these int columns as bitmaps.

The create subscription and define subscription commands support a bitmap comparison operator (&) in the where clause for rs_address columns or parameters.

In the Adaptive Server table, you use an int column to hold a bitmap, since Adaptive Server allows bitwise operators on integer values. An int column has 32 bits. You can have multiple rs_address columns in a replication definition if your application requires more than 32 bits.

When you create a subscription, specify bitmap comparisons by comparing each rs_address column to a bitmask using the & operator. Each subscription can have one comparison per rs_address column.

Bitmap subscription example

For example, consider an application that uses an rs_address column named book_type to record the categories of books customers are interested in reading. The book categories are mapped into the lower 8 bits of a bitmap column, as shown in Table 11-4:

Table 11-4: Example bitmap comparison

Bit number

Book category

0

Science fiction

1

Mystery

2

Business

3

Cooking

4

Popular computing

5

Computer science

6

Psychology

7

Reference

If a bit is set, the customer has expressed interest in books of the corresponding category. The bits are numbered from least significant to most significant. For example, if the customer is interested in mystery, cooking, computer science, and psychology books, the least significant 8 bits are 01101010 and the 32-bit integer value is 106. The book_type column in the customer’s row contains the value 106.

To create a subscription for customers who are interested in specified book categories, form a bitmask of the desired categories and compare it, using the & operator, to the book_type column in the where clause of the create subscription or define subscription command. The & operator performs a bitwise AND operation. If the result is non-zero, the row matches the subscription.

For rs_address columns only, the bitmap comparison operator & is supported in the where clause, as follows:

where rs_address_column1 & bitmask
[and rs_address_column2 & bitmask]
[and other_search_conditions]

For example, to create a subscription for all customers who are interested in mystery or business books, the lower 8 bits of the mask are 00000110. Converted to a 32-bit integer value, the bitmask is 6. For atomic or nonatomic materialization, you can create the subscription as follows:

create subscription mystery_or_business
for customers
with replicate at BRANCH_22.BOOK_DB
where book_type & 6

You can use a similar approach in the define subscription command, used for bulk materialization. For subscriptions to function replication definitions, which require the no-materialization method or bulk materialization, specify parameter names instead of column names.

See “Using the where clause” for more information.

In addition to 32-bit integer values, you can also compare rs_address columns to 32-bit hexadecimal numbers in the where clause. If you use hexadecimal numbers, pad each number with zeros, as necessary, to create an 8-digit hexadecimal value.

WARNING! Hexadecimal values are treated as binary strings by both Adaptive Server and Replication Server. Binary strings are converted to integers by copying bytes. The resulting bit pattern may represent different integer values on different platforms. For example, 0x0000100 represents 65,536 on platforms that consider byte 0 most significant, and represents 256 on platforms that consider byte 0 least significant. Because of these byte-ordering differences, bitmap subscriptions involving hexadecimal numbers might not work if a replication system involves different platforms. Be very cautious about comparing rs_address columns to hexadecimal numbers in the where clause of a subscription.

Replication Server does not replicate a row if the only changed columns are rs_address columns, unless the changed bits indicate that the row should be inserted or deleted at the replicate database. Because of this filtering, rs_address columns in replicate databases may not be identical to the corresponding columns at the primary database. This is an optimization for applications that use rs_address columns to specify the destination replicate databases.

Refer to Chapter 3, “Replication Server Commands,” in the Replication Server Reference Manual for more information about creating bitmap subscriptions using create subscription and create replication definition commands.

Refer to the Adaptive Server Enterprise Reference Manual and the Open Client and Open Server Common Libraries Reference Manual for more information about conversions between datatypes.