Postgres中有效的反向前缀搜索
假设一张100K加拿大邮政代码前缀具有人口尺寸:
区域代码 | 人口 |
---|---|
H2 | 10,000,000 |
H2Z | 100,000 |
H2K | 50,000 |
H2Z 1G9 | 500 |
给定完整的邮政编码,例如“ H2Z 1G9”,我需要返回每个行的区域代码,输入。由于某种原因,我需要做很多事情,因此我需要有效的索引。
我应该怎么做?
Assume a table of 100K Canadian postal code prefixes with population sizes:
Region code | Population |
---|---|
H2 | 10,000,000 |
H2Z | 100,000 |
H2K | 50,000 |
H2Z 1G9 | 500 |
Given a full length postal code, e.g. "H2Z 1G9" I need to return every row whose region code is a prefix of the input. For some reason I need to do this a lot, so I need effective indexing.
How should I go about this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用这样的函数:
You could use a function like this:
这样的工作会有效吗?您可以检查
说明分析
以确保其使用表上的PK:Would something like this work efficiently? You can check
explain analyze
to ensure it uses the PK on your table: