pgsql jsonb字段Gin索引失效案例

創建測試表
CREATE TABLE "monitor"."biz_orders" (
  "id" int8 NOT NULL DEFAULT nextval('"monitor"."biz_orders_ID_seq"'::regclass),
  "info" jsonb NOT NULL,
  "test_1" varchar(255) COLLATE "pg_catalog"."default",
  CONSTRAINT "biz_orders_pkey" PRIMARY KEY ("id")
)
;

ALTER TABLE "monitor"."biz_orders" 
  OWNER TO "xdeas_dev";

CREATE INDEX "jsonb_index" ON "monitor"."biz_orders" USING gin (
  "info" "pg_catalog"."jsonb_ops"
);

生成模擬數據
insert into biz_orders(info,test_1) select  '{"name": "ssss", "items": {"qty": 18, "product": "455"}}' ,null  from generate_series(1,10111) as i;

創建索引
CREATE INDEX jsonb_index ON monitor.biz_orders USING gin ( info );

方式一(生效):
EXPLAIN ANALYZE SELECT
    * 
FROM
    monitor.biz_orders 
WHERE
    info @> '{"name": "李四","items": {"qty": 18}}';

方式二(失效)
EXPLAIN ANALYZE SELECT
    * 
FROM
    monitor.biz_orders 
WHERE
    info ->> 'name' = '李四'::TEXT;

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章