| 但是,可以同时使用这些索引吗?  PostgreSQL为多个索引提供bitmapAnd及bitmapOr接口。它们可以组合多个索引,减少需要扫描的数据库数量。 Heap, one square = one page:  +---------------------------------------------+  |c____u_____X___u___X_________u___cXcc______u_|  +---------------------------------------------+  Rows marked c match customers pkey condition.  Rows marked u match username condition.  Rows marked X match both conditions.  Bitmap scan from customers_pkey:  +---------------------------------------------+  |100000000001000000010000000000000111100000000| bitmap 1  +---------------------------------------------+  One bit per heap page, in the same order as the heap  Bits 1 when condition matches, 0 if not  Bitmap scan from ix_cust_username:  +---------------------------------------------+  |000001000001000100010000000001000010000000010| bitmap 2  +---------------------------------------------+  Once the bitmaps are created a bitwise AND is performed on them:  +---------------------------------------------+  |100000000001000000010000000000000111100000000| bitmap 1  |000001000001000100010000000001000010000000010| bitmap 2   &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&  |000000000001000000010000000000000010000000000| Combined bitmap  +-----------+-------+--------------+----------+   | | |   v v v  Used to scan the heap only for matching pages:  +---------------------------------------------+  |___________X_______X______________X__________|  +---------------------------------------------+  The bitmap heap scan then seeks to the start of each page and reads the page:  +---------------------------------------------+  |___________X_______X______________X__________|  +---------------------------------------------+  seek------->^seek-->^seek--------->^   | | |   ------------------------   only these pages read 
 (编辑:南平站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |