Skip to content

Index is not chosen automatically in queries containing joins #19636

@s-sabitova

Description

@s-sabitova

Queries:

CREATE TABLE `optsample0/table1` (
  id Text NOT NULL,
  t2_id Text,
  attr1 Text,
  attr2 Text,
  PRIMARY KEY(id),
  INDEX ix_table1_t2_id GLOBAL ON (t2_id) COVER(attr1, attr2)
);

CREATE TABLE `optsample0/table2` (
  id Text NOT NULL,
  attr3 Text,
  attr4 Text,
  PRIMARY KEY(id),
  INDEX ix_table2_attr3 GLOBAL ON (attr3)
);

SELECT t1.id AS t1_id, t2_id, attr1, attr2, attr3, attr4
FROM `optsample0/table2` AS t2
INNER JOIN `optsample0/table1` AS t1 ON t2.id = t1.t2_id
WHERE t2.attr3 = 'value'u;

Expected result:

  • select from table2 is done using ix_table2_attr3
  • select from table1 is done using ix_table1_t2_id

Actual result:

  • select from table2 is done using ix_table2_attr3 (OK)
  • select from table1 is done using fullscan of table1 (NOT OK)
  • when ix_table1_t2_id is explicitly specified in the request, the index is used (OK)

It's expected that ix_table1_t2_id would be chosen automatically by optimiser.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions