Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: Chris Sosnin <k.sosnin@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH] box: add binary search for _session settings space
Date: Thu, 16 Jan 2020 21:27:13 +0100	[thread overview]
Message-ID: <2c25b764-dc7a-ce62-73ba-53554adfd263@tarantool.org> (raw)
In-Reply-To: <43C3FC7F-38CB-49EB-B52E-8762C391D5CA@tarantool.org>

Hi!

>> 2. We don't really need this function anywhere except session_settings.c.
>> Besides, even in that file it is needed only in session_settings_next_in_module().
>> So you can just patch the latter function.
> 
> I don’t think it’s a good idea, consider the following:
> 
> tarantool> box.space._session_settings:select('a', {iterator = 'GE’})
> 
> With the current version, we will find the first element which is GE with linear lookup,
> and the rest loops will consist of one iteration (overall it will always be the number of elements
> in the array). If we change session_settings_next_in_module() to use binary search, 
> however, it will highly increase the number of comparisons, because, even though we know
> that the next element is greater or equal, we are still looking for it in the array.
> 
> My initial patch takes advantage of the array being sorted for update and get methods,
> leaving the case from above untouched. Perhaps I could try to make the first lookup 
> with binary search, and the rest with linear. What do you think?

Hm, you are right. session_settings_next_in_module() perhaps is not the
best place.

Yes, I think all linear places should be fixed and become binary
search. For the iterators case you can patch
session_settings_index_create_iterator() so as it initializes
module_id and setting_id with a first matching module and setting
(or last, depending on the iterator type). Although not sure if it
is correct, because usually creation of an iterator does not
position the iterator. At least it does not happen in all our other
iterators.

Alternative solution - for forward iterator initialize module_id
with -1. In session_settings_iterator_next() check, that if module_id
is -1, then find a first setting with a binary search.
For backward iterator the same - init module_id with session_setting_type_MAX,
and use a binary search first time in session_settings_iterator_prev(),
when you see module_id == MAX.

Motivation is that even though 'update' and 'get' are the most
important places, and you fixed them, some users may still use :select()
even when they want to select just one tuple, with EQ iterator and a
full key. And it will be linear, because select() is always an iterator.

      reply	other threads:[~2020-01-16 20:27 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-10  7:46 Chris Sosnin
2020-01-15 20:24 ` Vladislav Shpilevoy
2020-01-16 13:13   ` Chris Sosnin
2020-01-16 20:27     ` Vladislav Shpilevoy [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2c25b764-dc7a-ce62-73ba-53554adfd263@tarantool.org \
    --to=v.shpilevoy@tarantool.org \
    --cc=k.sosnin@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH] box: add binary search for _session settings space' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox