Example #1
0
        def create_index(conn: LoggingDatabaseConnection) -> None:
            conn.rollback()

            # we have to set autocommit, because postgres refuses to
            # CREATE INDEX CONCURRENTLY without it.
            conn.set_session(autocommit=True)

            try:
                c = conn.cursor()

                # if we skipped the conversion to GIST, we may already/still
                # have an event_search_fts_idx; unfortunately postgres 9.4
                # doesn't support CREATE INDEX IF EXISTS so we just catch the
                # exception and ignore it.
                import psycopg2

                try:
                    c.execute("CREATE INDEX CONCURRENTLY event_search_fts_idx"
                              " ON event_search USING GIN (vector)")
                except psycopg2.ProgrammingError as e:
                    logger.warning(
                        "Ignoring error %r when trying to switch from GIST to GIN",
                        e)

                # we should now be able to delete the GIST index.
                c.execute("DROP INDEX IF EXISTS event_search_fts_idx_gist")
            finally:
                conn.set_session(autocommit=False)
Example #2
0
            def create_index(conn: LoggingDatabaseConnection) -> None:
                conn.rollback()
                conn.set_session(autocommit=True)
                c = conn.cursor()

                # We create with NULLS FIRST so that when we search *backwards*
                # we get the ones with non null origin_server_ts *first*
                c.execute(
                    "CREATE INDEX CONCURRENTLY event_search_room_order ON event_search("
                    "room_id, origin_server_ts NULLS FIRST, stream_ordering NULLS FIRST)"
                )
                c.execute(
                    "CREATE INDEX CONCURRENTLY event_search_order ON event_search("
                    "origin_server_ts NULLS FIRST, stream_ordering NULLS FIRST)"
                )
                conn.set_session(autocommit=False)
Example #3
0
 def reindex_txn(conn: LoggingDatabaseConnection) -> None:
     conn.rollback()
     if isinstance(self.database_engine, PostgresEngine):
         # postgres insists on autocommit for the index
         conn.set_session(autocommit=True)
         try:
             txn = conn.cursor()
             txn.execute(
                 "CREATE INDEX CONCURRENTLY state_groups_state_type_idx"
                 " ON state_groups_state(state_group, type, state_key)")
             txn.execute("DROP INDEX IF EXISTS state_groups_state_id")
         finally:
             conn.set_session(autocommit=False)
     else:
         txn = conn.cursor()
         txn.execute(
             "CREATE INDEX state_groups_state_type_idx"
             " ON state_groups_state(state_group, type, state_key)")
         txn.execute("DROP INDEX IF EXISTS state_groups_state_id")