M
M
Marat Dolotov2019-12-09 20:50:37
Sphinx
Marat Dolotov, 2019-12-09 20:50:37

How to create the illusion of deletion with rt_index?

There is one disk index disc_index and another realtime index rt_index. Their fields and field types are the same. I connected them like this under one commonIndex index:

index commonIndex
{
type = distributed
local = disc_index
local = rt_index
}

So, to add a new entry, I do:
INSERT INTO rt_index values (100,'text');
Everything is fine, when I select all entries: the
SELECT * FROM common_index ORDER BY id DESC
new entry is shown. If it is necessary to display a type of modified version of the record from disc_index, then I simply write a new record to the realtime index rt_index:
INSERT INTO rt_index values (55,'text was updated');

And then if you select from the common_index index,
SELECT * FROM common_index ORDER BY id DESC
then ID 55 is returned from the rt_index index and not from the desc_index, so we will see the updated version. And if you need to update again, then just update this entry from rt_index
UPDATE rt_index SET id=55, text='text was updated another time';

Everything is great, BUT when I got to the question of deleting a record, I realized that you can’t just delete it, so you need to come up with some kind of tricky way, so I just added a new deleted logical field and choose like this:
select * from common_index where deleted=0 order by id desc

From the beginning it even seemed to work. But then it turned out that it wasn't. It is not clear why, even when I updated the deleted=0 field
UPDATE rt_index SET deleted=0 WHERE id=55;
, I see in the console that in the rt_index index, the record ID 55 after deleted has the value 1, but for some reason, when you select all records
select * from common_index where deleted=0 order by id desc

the list gets from disc_index and not from rt_index. The question is how to solve such a problem?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question