- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 postgres 9.6。我将 JSONB 数据存储在一列中,我会提高一个查询的性能。在我的 json 数据中,我有 name
列,它是文本。我正在使用以下查询查询此数据。
SELECT "id", "body", "created_at", "updated_at"
FROM "read_models"
WHERE ((body ->> 'name') ILIKE '%asd%')
LIMIT 40 OFFSET 0;
下面是这个查询的分析结果:
Limit (cost=0.00..33.58 rows=40 width=72) (actual
time=112.428..4071.757 rows=11 loops=1)
|
| -> Seq Scan on read_models
(cost=0.00..2636.90 rows=3141 width=72) (actual time=112.416..4071.646
rows=11 loops=1) |
| Filter: ((body ->> 'name'::text) ~~* '%asd%'::text)
|
| Rows Removed by Filter: 78516
|
| Planning time: 1.658 ms
|
| Execution time: 4071.847 ms
我为此属性创建了以下索引:
CREATE EXTENSION pg_trgm;
CREATE INDEX idx_name ON read_models USING gin ((body ->> 'name') gin_trgm_ops);
我创建了不同的索引类型,但结果始终相同。查询时间和没有任何索引一样。当我查询该数据时,我看到 PG 没有使用这个索引。我看到很多关于如何在 postgres 中索引文本数据的信息,但我不明白为什么它在我的情况下不起作用。感谢您的帮助。
最佳答案
问题是你的 where 条件不是 SARGABLE
What makes a SQL statement sargable?
您可以为 LIKE 'ABC%'
使用索引,但不能为 LIKE '%ABC%'
检查那些提示,即使对于 MySQL,大多数人也适用于 PostgresMySQL 索引 TIPS
关于postgresql - 在 ILIKE postgres 查询上创建 GIN 索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47539068/
我有很多路线,从 gin.Default() 开始使用 Gin (默认情况下为所有路由启用日志记录和恢复)。但是有一条路由(即 /health )每 5 秒被 ping 一次。在不更改大部分代码的情况
gin 是目前 Go 里面使用最广泛的框架之一了,弄清楚 gin 框架的原理,有助于我们更好的使用 gin。这个系列 gin 源码阅读会逐步讲明白 gin 的原理,欢迎关注后续文章。 gin
我从 gin 文档中了解到,您可以将 json 绑定(bind)到类似 的结构 type Login struct { User string `form:"user" json:"u
我正在使用 API,GET 和 POST 工作正常,除非我尝试通过其 ID 获取选择记录(例如/articles/2)。文章存在,当通过/articles 路径检索所有记录时,我得到了正确的响应。这是
我找不到在 UNIX 中正确执行此代码的方法: package main import ( "time" "github.com/gin-gonic/gin" "net/http" ) t
我尝试使用作为 Golang 框架的 Gin。 https://github.com/gin-gonic/gin 我从官方github上复制了示例代码。 就像这样。 package main impo
下面访问gin-gonic服务器时,HTTP客户端应该收到code 500,却收到code 200。 package main import ( "github.com/gin-contrib
我使用 Guice/Gin 设计了一个新项目,因此我可以使我们的代码更加模块化和可交换,尤其是在测试时。 但是,我无法弄清楚如何在实践中完成这项工作。我的印象是我可以在我的测试中创建一个新的 Gin/
我正在尝试在 golang:alpine docker 镜像上运行一个非常简单的 go/gin 程序。这无法运行/构建。 运行容器: docker run -it --rm golang:1.10.1
本文介绍如何通过 rk-boot 快速搭建静态文件下载 Web 服务。什么是 静态文件下载 Web UI?通过配置文件,快速搭建可下载文件的 Web 服务。 请访问如下地址获取完整教程: r
这是我的一个例子 - public class GinDemoPresenter implements Presenter { private View view; @Inject
我正在尝试使用一种干净的方法,使用传递给我的类的父上下文来优雅地停止我的gin服务器。 这是我当前的代码 有没有更清洁的方法可以做到这一点?感觉像很多样板代码和不必要的例如使用无限循环完成如此简单的任
我有以下代码 public class AppGinModule extends AbstractGinModule{ @Override protected void configu
我正在使用OPTIONS方法获得204,但是似乎没有碰到终点 只需构建一个简单的文件上传端点,如下所示: package main import ( "cloud.google.com/go
在对其数据执行验证后,我试图用它的数据恢复上下文。我需要数据在下一个函数中根据需要继续移动。 我是 golang 的新手,下面的代码是我所能做的。非常感谢任何帮助和更好的方法。 提前致谢。 验证中间件
有一个使用gin-gonic框架以golang编写的服务。 我只想将application/json支持为mime类型,并且如果它始终以UTF-8格式运行,那就太好了。如果服务的业务逻辑将获得不同编码
我试图在我的 Handler 上进行一些处理后传递一些变量功能。我该怎么办 redirect到一个新页面并将一些 json 变量传递给这个新模板? // main package func main(
我运行关于文件上传的 gin 示例,这个 repo 来自 https://github.com/gin-gonic/examples/tree/5898505356e9064c49abb075eae8
我收到以下错误消息: controllers/user.go:4:2: cannot find package "(underscore)/home/ubuntu/goapi/src/github.c
我需要在中间件函数中操作响应数据。假设我有产品处理程序和客户处理程序。产品处理程序返回产品列表,客户返回客户列表。在中间件函数中,我想将这些响应转换为 ApiResponse 结构。 type Api
我是一名优秀的程序员,十分优秀!