[MDEV-7757] Functional index pointing to tables Created: 2015-03-11  Updated: 2017-06-01

Status: Open
Project: MariaDB Server
Component/s: None
Fix Version/s: None

Type: Task Priority: Minor
Reporter: VAROQUI Stephane Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None


 Description   

This feature enable to leverage storage engine features at the SQL Layer.

Spatial index for any storage :

 ALTER TABLE t1_innodb ADD FUNCTIONAL INTERNAL INDEX idx1(c1) UNIQUE PIVOT(primary)  SPATIAL USING MyISAM

Clustered index for any storage:

 ALTER TABLE t1_innodb ADD FUNCTIONAL INTERNAL INDEX idx1(c1) UNIQUE PIVOT(primary) CLUSTERED=YES USING TokuDB

  • This create a new table idx1 (PK,c1).
  • This table have storage engine defined with USING keyword
  • This table have a spatial index or a clustered index on c1
  • This table is auto updated when define as INTERNAL and is not updated with keyword EXTERNAL
  • This table is a 1 to 1 relation on the primary key of the indexed table keyword UNIQUE PIVOT(primary)

Parser rewrite query and inject subquery for QP using t1_innodb and filters on column c1

like :

 SELECT * FROM  t1_innodb where MBR_CONTAINS(GEOM_FROMTEXT(blabal) ,c1)

rewrite to :

 SELECT * FROM  t1_innodb  JOIN (SELECT idx1.c1  FROM  idx1 WHERE GEOM_FROMTEXT(blabal) ,c1))  fct_index1  ON  fctindex1.pk=t1_innodb.pk  WHERE MBR_CONTAINS(GEOM_FROMTEXT(blabal) ,c1)

Performance improvements using external table materialization

 ALTER TABLE t1_innodb ADD FUNCTIONAL EXTERNAL INDEX idx1(t2.c2, t3.c3) NON UNIQUE PIVOT (fctT1.c1=t1_innodb.c1)

  • This index point to an already exiting table idx1 (c1,c2,c3).
  • This table is not updated by MariaDB but via triggers, scheduler, sphinx_se
  • This table have same columns name and value found in other tables EXTERNAL INDEX idx1(t2.c2, t3.c3)
  • This table is joinable on such columns PIVOT (idx1.c1=t1_innodb.c1)
  • This table is a 1 ton n relation defined with keyword NON UNIQUE
  • This table is having an index on c2,c3

 SELECT * FROM  t1_innodb JOIN t2 USING(id) JOIN t3 USING(id) WHERE t2.c1=4 AND t3.c2> 10

Rewrite to

 SELECT* FROM  t1_innodb JOIN t2 USING(id) JOIN t3 USING(id) JOIN (SELECT DISTINCT t1.column  FROM  t1 WHERE WHERE t2.c1=4 AND t3.c2> 10 )   fct_index1  ON  fctindex1.c1=t1_innodb.c1 WHERE t2.c1=4 AND t3.c2> 10 


Generated at Thu Feb 08 07:22:02 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.