MySQL Forums
Forum List  »  Performance

Re: index not being pick up
Posted by: Øystein Grøvlen
Date: January 22, 2018 03:00AM

Raf Mahn Wrote:
-------------------------------------------------------
> If I change the index to be (reference, scope_id),
> it will pick up index. Though, since scope_id is
> our column to make the table multi-tenancy, we
> wanted to keep it on the left as I'm hoping to be
> able to use the scope_id for other queries instead
> of needing to create more indexes in the future.

Note that sticking with the original index, also means that no index could be used when @scope_override_enabled is set.

> Seems like creating multiple views is way to go.

An alternative to using a view, could be to use a stored procedure and build the query string dynamically:

delimiter //
CREATE PROCEDURE vw (IN pred VARCHAR(255))
BEGIN
DECLARE str VARCHAR(255) DEFAULT 'SELECT * FROM property WHERE (';
IF NOT scopeOverrideEnabled() THEN
SET str = CONCAT(str, 'scope_id = getScopeId()) AND (');
END IF;
SET @query = CONCAT(str, pred, ')');
PREPARE stmt FROM @query;
EXECUTE stmt;
DROP PREPARE stmt;
END //
delimiter ;

You can then pass in the specific predicate like this:

call vw("reference = '200ADELAIDE'");

Øystein Grøvlen,
Senior Principal Software Engineer,
MySQL Group, Oracle,
Trondheim, Norway

Options: ReplyQuote


Subject
Views
Written By
Posted
895
r r
January 15, 2018 11:57PM
328
January 16, 2018 12:19AM
303
January 16, 2018 04:39PM
309
January 16, 2018 07:49PM
341
January 17, 2018 12:26AM
331
January 17, 2018 01:07AM
545
January 17, 2018 01:19AM
372
January 17, 2018 12:41PM
316
January 19, 2018 07:26AM
349
January 21, 2018 04:31PM
317
January 21, 2018 05:41PM
Re: index not being pick up
387
January 22, 2018 03:00AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.