创建sqlite索引时COLLATE关键字的作用是什么?

时间:2022-06-01 17:07:02

According to the sqlite3 documentation,

根据sqlite3文档,

The COLLATE clause following each column name defines a collating sequence used for text entries in that column. The default collating sequence is the collating sequence defined for that column in the CREATE TABLE statement. Or if no collating sequence is otherwise defined, the built-in BINARY collating sequence is used.

每个列名后面的COLLATE子句定义用于该列中文本条目的整理顺序。默认整理顺序是在CREATE TABLE语句中为该列定义的整理顺序。或者,如果未定义整理顺序,则使用内置BINARY整理顺序。

What does a collating sequence do, and what is a BINARY collating sequence?

整理顺序有什么作用,什么是BINARY整理顺序?

2 个解决方案

#1


5  

It is the way that the sql engine orders data internally. Binary Collation does what it suggests, it does a binary comparison. Generally its the fastest collation though I have never quantified it, as it checks bit patterns, which means it is case and accent insensitive.

这是sql引擎在内部订购数据的方式。 Binary Collat​​ion按照它的建议行事,进行二元比较。通常它是最快的排序规则,虽然我从来没有量化它,因为它检查位模式,这意味着它是大小写和重音不敏感。

#2


1  

Binary collation compares your string byte by byte, as in an unicode table. For example: A,B,a,b. A case sensitive order would be: a,A,b,B.

二进制排序规则比较您的字符串逐字节,就像在unicode表中一样。例如:A,B,a,b。区分大小写的顺序是:a,A,b,B。

The advantage of binary collation is its speed, as string comparison is very simple/fast. In general case, indexes with binary might not produce expected results for sort, however for exact matches they can be useful.

二进制整理的优点是速度快,因为字符串比较非常简单/快速。在一般情况下,具有二进制的索引可能不会产生排序的预期结果,但是对于完全匹配,它们可能是有用的。

COLLATE NOCASE also affects case sensitive queries.

COLLATE NOCASE也会影响区分大小写的查询。

If you have a column with these values: 'aa', 'aA'

如果您有一个包含以下值的列:'aa','aA'

select * from table where col = 'aa'

If you have created your column with COLLATE NOCASE it will return both 'aa' and 'aA'. Otherwise, if you didn't specify it, it will return only 'aa'.

如果您使用COLLATE NOCASE创建了列,它将返回'aa'和'aA'。否则,如果您没有指定它,它将只返回'aa'。

You can also specify it in a query (this is slower then if you had created your column with COLLATE NOCASE)

您也可以在查询中指定它(如果您使用COLLATE NOCASE创建了列,则速度会慢一些)

select * from table where col = 'aa' COLLATE NOCASE

#1


5  

It is the way that the sql engine orders data internally. Binary Collation does what it suggests, it does a binary comparison. Generally its the fastest collation though I have never quantified it, as it checks bit patterns, which means it is case and accent insensitive.

这是sql引擎在内部订购数据的方式。 Binary Collat​​ion按照它的建议行事,进行二元比较。通常它是最快的排序规则,虽然我从来没有量化它,因为它检查位模式,这意味着它是大小写和重音不敏感。

#2


1  

Binary collation compares your string byte by byte, as in an unicode table. For example: A,B,a,b. A case sensitive order would be: a,A,b,B.

二进制排序规则比较您的字符串逐字节,就像在unicode表中一样。例如:A,B,a,b。区分大小写的顺序是:a,A,b,B。

The advantage of binary collation is its speed, as string comparison is very simple/fast. In general case, indexes with binary might not produce expected results for sort, however for exact matches they can be useful.

二进制整理的优点是速度快,因为字符串比较非常简单/快速。在一般情况下,具有二进制的索引可能不会产生排序的预期结果,但是对于完全匹配,它们可能是有用的。

COLLATE NOCASE also affects case sensitive queries.

COLLATE NOCASE也会影响区分大小写的查询。

If you have a column with these values: 'aa', 'aA'

如果您有一个包含以下值的列:'aa','aA'

select * from table where col = 'aa'

If you have created your column with COLLATE NOCASE it will return both 'aa' and 'aA'. Otherwise, if you didn't specify it, it will return only 'aa'.

如果您使用COLLATE NOCASE创建了列,它将返回'aa'和'aA'。否则,如果您没有指定它,它将只返回'aa'。

You can also specify it in a query (this is slower then if you had created your column with COLLATE NOCASE)

您也可以在查询中指定它(如果您使用COLLATE NOCASE创建了列,则速度会慢一些)

select * from table where col = 'aa' COLLATE NOCASE