查询匹配的字符串标签 [英] Query matching string tags

查看:109
本文介绍了查询匹配的字符串标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们假设我在SQL中有数百万行,使用PostgreSQL进行查询。
每行都包含字符串 ~~~& AA = ~~~
在所有行中,我需要获取包含CONTAINS AA = 的行。

Let's assume that I have millions of rows in SQL, using PostgreSQL to query. Each row contains the string ~~~&AA=~~~ or not. And out of all rows, I need to get the rows that CONTAINS AA=.

然后

我尝试了以下操作,但速度非常慢。

I tried the following but it is extremely slow.

SELECT my_column
FROM table
WHERE my_column 
    LIKE '%AA=%' 

我应该使用什么?

推荐答案

您需要找出一种方法来建立索引或使用其他类似搜索引擎的内容。

You need to figure out a way to make an index or use something else like a search engine.

首先请查看为什么 LIKE在postgresl中可能会变慢,以及如何使我更快地使用index-luke 。基本上可以归结为使用特殊索引函数或考虑使用 Postgresql全文搜索支持

First have a look at why LIKE can be slow in postgresl and how to make i faster at use-the-index-luke. Basically it boils down to either using special index functions or consider using Postgresql Fulltext Search Support.

也不清楚您的问题是否每隔一行实际上都包含内容 ~~~& AA = ~~~ ,为什么不仅仅 my_column ='~~~& AA = ~~~'?如果是这种情况,您可以轻松地为 ~~~& AA = ~~~ 创建部分索引,因为Postgresql支持部分索引。

Also it wasn't clear from your question if every other row actually contains the contents ~~~&AA=~~~ then why not just WHERE my_column = '~~~&AA=~~~'? If that is the case you can easily create a partial index for ~~~&AA=~~~ as Postgresql supports partial indexes.

这篇关于查询匹配的字符串标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆