Database Case Insensitive Index?(数据库不区分大小写索引?)
问题描述
我有一个查询,我正在搜索一个字符串:
I have a query where I am searching against a string:
SELECT county FROM city WHERE UPPER(name) = 'SAN FRANCISCO';
现在,这可以正常工作,但不能很好地扩展,我需要对其进行优化.我已经找到了一个选项生成的视图,或类似的东西,但我希望使用索引的更简单的解决方案.
Now, this works fine, but it doesn't scale well, and I need to optimize it. I have found an option along the lines of creating a generated view, or something like that, but I was hoping for a simpler solution using an index.
我们正在使用 DB2,我真的很想使用 索引中的表达式,但这个选项似乎只在 z/OS 上可用,但是我们正在运行 Linux.我还是尝试了表达式索引:
We are using DB2, and I really want to use an expression in an index, but this option seems to only be available on z/OS, however we are running Linux. I tried the expression index anyways:
CREATE INDEX city_upper_name_idx
ON city UPPER(name) ALLOW REVERSE SCANS;
当然,它会在 UPPER(name) 上窒息.
But of course, it chokes on the UPPER(name).
是否有另一种方法可以以这种方式创建索引或类似的东西,这样我就不必重组现有查询以使用新生成的视图,或更改现有列或任何其他此类侵入性更改?
Is there another way I can create an index or something similar in this manner such that I don't have to restructure my existing queries to use a new generated view, or alter my existing columns, or any other such intrusive change?
我愿意听取其他数据库的解决方案...它可能会延续到 DB2...
I'm open to hearing solutions for other databases... it might carry over to DB2...
推荐答案
您可以添加一个索引列,其中包含城市名称的数字哈希键.(允许重复).
You could add an indexed column holding a numerical hash key of the city name. (With duplicates allowed).
然后你可以做一个多子句 where :
Then you could do a multi-clause where :
hash = [compute hash key for 'SAN FRANCISCO']
SELECT county
FROM city
WHERE cityHash = hash
AND UPPER(name) = 'SAN FRANCISCO' ;
或者,查看您的数据库手册并查看用于创建表索引的选项.可能会有帮助.
Alternatively, go through your db manual and look at the options for creating table indexes. There might be something helpful.
这篇关于数据库不区分大小写索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:数据库不区分大小写索引?
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- SQL 临时表问题 2022-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 更改自动增量起始编号? 2021-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01