|
| 1 | +import testgres |
| 2 | +import os |
| 3 | + |
| 4 | +VECTOR_QUERY = "SELECT * FROM small_world WHERE b = FALSE order by v <-> '{1,0,0}' LIMIT 3;" |
| 5 | + |
| 6 | +with testgres.get_new_node() as primary: |
| 7 | + |
| 8 | + # run inidb |
| 9 | + primary.init() |
| 10 | + |
| 11 | + primary.append_conf('enable_seqscan = off') |
| 12 | + |
| 13 | + primary.start() |
| 14 | + |
| 15 | + primary.execute('CREATE EXTENSION lantern') |
| 16 | + # testgres safe_psql does not support specifying cwd, so we have to change the cwd of the current |
| 17 | + # script to make sure relative paths in the target sql file work in testgres |
| 18 | + os.chdir('../test/sql') |
| 19 | + primary.safe_psql(filename='hnsw_delete.sql') |
| 20 | + # create a backup |
| 21 | + with primary.backup() as backup: |
| 22 | + |
| 23 | + # create and start a new replica |
| 24 | + replica = backup.spawn_replica('replica').start() |
| 25 | + |
| 26 | + # catch up with master node |
| 27 | + replica.catchup() |
| 28 | + |
| 29 | + # make sure we are using the index |
| 30 | + assert 'Index Scan using small_world_v_idx on small_world' in str(primary.safe_psql(f"EXPLAIN {VECTOR_QUERY}")) |
| 31 | + assert 'Index Scan using small_world_v_idx on small_world' in str(replica.safe_psql(f"EXPLAIN {VECTOR_QUERY}")) |
| 32 | + |
| 33 | + res = replica.execute(VECTOR_QUERY) |
| 34 | + assert res[0][2] == [1.0, 0.0, 0.0] |
| 35 | + # take only boolean columns |
| 36 | + assert [i[1] for i in res] == [False] |
| 37 | + |
| 38 | + # Now, let's delete data on primary and see how it propagates to replica |
| 39 | + primary.execute("INSERT INTO small_world (id, b, v) VALUES (42, FALSE, '{42,42,42}'), (43, FALSE, '{42,42,42}'), (44, FALSE, '{42,42,42}');") |
| 40 | + |
| 41 | + res = replica.execute(VECTOR_QUERY) |
| 42 | + # changes have not propagated yet |
| 43 | + assert res[0][2] == [1.0, 0.0, 0.0] |
| 44 | + assert [i[1] for i in res] == [False] |
| 45 | + replica.catchup() |
| 46 | + res = replica.execute(VECTOR_QUERY) |
| 47 | + assert res[0][2] == [1.0, 0.0, 0.0] |
| 48 | + assert [i[1] for i in res] == [False, False, False], 'failed %s' % res |
| 49 | + |
| 50 | +print("WAL tests completed successfully!") |
| 51 | + |
0 commit comments