Download Creating User-Defined Routines and User-Defined Data

Transcript
Reasons for Extending btree_ops
To order the data type in this way, write the relational-operator functions so
that they implement this new order. For the strings Mc and Mac to be equal,
you must define the relational-operator functions that:
■
Accept the opaque data type, ScottishName, in the parameter list
■
Contain code that equates Mc and Mac
The following steps use the steps described in “Extensions of the btree_ops
Operator Class” on page 11-10 to extend the btree_ops operator class.
To support the ScottishName data type
1.
Prepare and register the strategy functions that handle the
ScottishName data type: lessthan(), lessthanorequal(), equal(),
greaterthan(), and greaterthanorequal().
For more information, refer to Chapter 4, “Developing a UserDefined Routine.”
2.
Prepare and register the external function for the compare() support
function that handles the ScottishName data type.
You can now create a B-tree index on a ScottishName column:
CREATE TABLE scot_cust
(
cust_id integer,
cust_name ScottishName
...
);
CREATE INDEX cname_ix
ON scot_cust (cust_name);
The optimizer can now choose whether to use the cname_ix index to evaluate
the following query:
SELECT * FROM scot_cust
WHERE cust_name = 'McDonald'::ScottishName
11-14
Creating User-Defined Routines and User-Defined Data Types