Mysql 为表编制索引以进行高级搜索

Mysql 为表编制索引以进行高级搜索,mysql,indexing,database-design,Mysql,Indexing,Database Design,假设我有一个表格shapes表格,其中列如下 create table shapes ( id int, region_id int, clusted_id int, color varcahr(60), edges int, x int, y int, z int, orientation int, created_at date, updated_at date, visible tinyint ... ); 我需要创建一个“高级搜索”功能来查询

假设我有一个表格
shapes
表格,其中列如下

create table shapes (
  id int,
  region_id int,
  clusted_id int,
  color varcahr(60),
  edges int,
  x int, y int, z int,
  orientation int,
  created_at date,
  updated_at date,
  visible tinyint
  ...
);
我需要创建一个“高级搜索”功能来查询这个超过2M行的表。用户可以根据所有可用列的混合匹配进行查询。差不多

select * from shapes where created_at between ? and ? and x+y < ? and region_id in (?, ?, ?) ...
从创建的形状中选择*?和和x+y<?以及(?,?)中的区域id。。。
where子句中可以出现字段,也可以不出现字段。这就是“高级”搜索。此外,没有任何内容是全文。假设所有内容都是int、date、boolean或enum

  • 假设形状均匀地分布在所有列的所有可能值中,为该表编制索引的最佳做法是什么
  • 是否必须将表中字段的所有子集索引在一起
  • 是否有其他外部服务可以帮助提高绩效?像弹性搜索
谢谢大家!

没有“好”的解决方案

观察他们真正在搜索什么。然后制作一些索引,每个索引大约有2列。制作复合索引时,请从使用
=
测试的内容开始。根据用户填写的表单字段构造查询。不要麻烦索引不可搜索的表达式,例如
x+y<?

更多: