Performance Tuning: Create index for boolean column

后端 未结 4 759
予麋鹿
予麋鹿 2020-12-28 13:25

I have written a daemon processor which will fetch rows from one database and insert them into another for synchronizing. It will fetch rows based on a boolean

相关标签:
4条回答
  • 2020-12-28 14:12

    An index will certainly help but rather than polling which can impose load and concurrency issues if your database is heavily used it might be worth considering a notification method such as amqp or trigger/database queue based approach instead like Slony or Skytools Londiste. I have used both Slony and Londiste for trigger based replication and have found both excellent. My preference is for Londiste as it is much simpler to set up and manage (and if you have a simple use case stick to the older 2. branch).

    0 讨论(0)
  • 2020-12-28 14:13

    A table with records and a boolean field should be the way to do it.

    Here is something which I believe might help you...

    Bitmap Index

    Alternative of Bitmap Index in PostgreSQL

    0 讨论(0)
  • 2020-12-28 14:14

    I suggest that you do not index the table (the boolean is a low cardinality field), but partition it instead on the boolean value.

    See: http://www.postgresql.org/docs/9.1/static/ddl-partitioning.html

    0 讨论(0)
  • 2020-12-28 14:16

    For a query like this a partial index would serve you best.

    CREATE INDEX ON tbl (id) WHERE sync_done = FALSE;
    

    However, for a use case like this, other synchronization methods may be preferable to begin with:

    • Have a look at LISTEN / NOTIFY.
    • Or use a trigger in combination with dblink.
    • Or one of the many available replication methods.
      Streaming Replication was added with Postgres 9.0 and has become increasingly popular.
    0 讨论(0)
提交回复
热议问题