From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Date: Thu, 18 Jul 2019 12:50:29 +0300 From: Konstantin Osipov Subject: Re: [tarantool-patches] [PATCH v3 4/4] box: introduce functional indexes in memtx Message-ID: <20190718095029.GD21191@atlas> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: To: tarantool-patches@freelists.org Cc: vdavydov.dev@gmail.com, Kirill Shcherbatov List-ID: * Kirill Shcherbatov [19/07/17 09:39]: > Closes #1260 > > @TarantoolBot document > Title: introduce functional indexes in memtx > Now you can define a functional index using registered persistent > function as key extractor. > > There is some restrictions for function and key definition for > functional index: > - referenced extractor function must be persistent, deterministic > and return scalar type or array. > - key parts describe the referenced routine's returned key > (when the routine returned value type is array in meaning of > multikey index key): all parts must be sequential and the > first part's fieldno must be 1. > - key parts can't use JSON paths. > - you are not allowed to access tuple fields by names in functional > index extractor > > Functional index can't be primary. > You are not allowed to change functional index extractor function > while there are some functional indexes depends of it. > > Example: > s = box.schema.space.create('withdata') > s:format({{name = 'name', type = 'string'}, > {name = 'address', type = 'string'}}) > pk = s:create_index('name', {parts = {1, 'string'}}) > lua_code = [[function(tuple) > local address = string.split(tuple[2]) > local ret = {} > for _, v in pairs(address) do > table.insert(ret, {utf8.upper(v)}) > end > return unpack(ret) > end]] > box.schema.func.create('addr_extractor', {body = lua_code, > is_deterministic = true, is_sandboxed = true}) > idx = s:create_index('addr', {unique = false, functional_fid = > box.func.addr_extractor.id, is_multikey = true, > parts = {{1, 'string'}}}) > s:insert({"James", "SIS Building Lambeth London UK"}) > s:insert({"Sherlock", "221B Baker St Marylebone London NW1 6XE UK"}) > idx:select('UK') > --- > - - ['James', 'SIS Building Lambeth London UK'] > - ['Sherlock', '221B Baker St Marylebone London NW1 6XE UK'] this is a huge patch with only 3 tiny prerequisites. Are you sure it's not possible to split it into pieces? -- Konstantin Osipov, Moscow, Russia