The cross-type operators are members of the family, but are not associated with any single class within the family. To do this, the operator classes for each of the types must be grouped into the same operator family. In cases where several data types have similar behaviors, it is frequently useful to define cross-data-type operators and allow these to work with indexes. The following query shows all defined operator classes:Īn operator class is actually just a subset of a larger structure called an operator family. If you do use the C locale, you do not need the xxx_pattern_ops operator classes, because an index with the default operator class is usable for pattern-matching queries in the C locale. (Ordinary equality comparisons can use these operator classes, however.) It is possible to create multiple indexes on the same column with different operator classes. Such queries cannot use the xxx_pattern_ops operator classes. Note that you should also create an index with the default operator class if you want queries involving ordinary, or >= comparisons to use an index. As an example, you might index a varchar column like this:ĬREATE INDEX test_index ON test_table (col varchar_pattern_ops) This makes these operator classes suitable for use by queries involving pattern matching expressions ( LIKE or POSIX regular expressions) when the database does not use the standard “ C” locale. The difference from the default operator classes is that the values are compared strictly character by character rather than according to the locale-specific collation rules. The operator classes text_pattern_ops, varchar_pattern_ops, and bpchar_pattern_ops support B-tree indexes on the types text, varchar, and char respectively. There are also some built-in operator classes besides the default ones: The operator class determines the basic sort ordering (which can then be modified by adding sort options COLLATE, ASC/ DESC and/or NULLS FIRST/ NULLS LAST). We could do this by defining two operator classes for the data type and then selecting the proper class when making an index. For example, we might want to sort a complex-number data type either by absolute value or by real part. The main reason for having operator classes is that for some data types, there could be more than one meaningful index behavior. In practice the default operator class for the column's data type is usually sufficient. For example, a B-tree index on the type int4 would use the int4_ops class this operator class includes comparison functions for values of type int4. The operator class identifies the operators to be used by the index for that column. 11.10. Operator Classes and Operator FamiliesĪn index definition can specify an operator class for each column of an index.ĬREATE INDEX name ON table ( column opclass )
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |