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.
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.
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.
where rs_address_column1 & bitmask [and rs_address_column2 & bitmask] [and other_search_conditions]
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.
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.
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.
See Replication Server Reference Manual > Replication Server Commands for more information about creating bitmap subscriptions using create subscription and create replication definition.
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.