awesomePower
V2EX  ›  数据库

mysql 如何针对位运算条件字段进行索引

  •  
  •   awesomePower · Aug 12, 2024 · 2102 views
    This topic created in 672 days ago, the information mentioned may be changed or developed.

    如果一个字段需要进行灵活的位运算当成查询条件,怎么对这个字段索引。mysql 不行的话,其他数据库能做到吗

    5 replies    2024-08-13 07:49:10 +08:00
    encounter2017
        1
    encounter2017  
       Aug 12, 2024
    pg 支持部分索引,比如:

    CREATE INDEX access_log_client_ip_ix ON access_log (client_ip)
    WHERE NOT (client_ip > inet '192.168.100.0' AND
    client_ip < inet '192.168.100.255');
    9dP06m83vIV00l72
        2
    9dP06m83vIV00l72  
       Aug 12, 2024
    需要带上 STORED 参数才能索引,虚拟计算的貌似不支持。
    sujin190
        3
    sujin190  
       Aug 12, 2024
    如果你真是按位查找,从索引设计来说位个数不能很多的话索引效果几乎没有吧,bitmap 这种的话那也没有场景需要存多行吧,否则如果如楼上所说类似 ip 这种转换为大于小于查找就好了啊,索引不是万能的
    rekulas
        4
    rekulas  
       Aug 12, 2024
    最好说说你的原生需求
    xuanbg
        5
    xuanbg  
       Aug 13, 2024
    要反过来才行。不是拿字段的值运算后匹配条件,而是条件运算后匹配字段的值,这样就能走索引了。和什么运算方式无关。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3280 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 56ms · UTC 12:11 · PVG 20:11 · LAX 05:11 · JFK 08:11
    ♥ Do have faith in what you're doing.