当前位置:网站首页>Bi-sql index

Bi-sql index

2022-06-25 01:15:00 Powerbi white tea

INDEX

INDEX, Indexes . Index is one of the advanced skills in data warehouse , And a lot of HR What I like to ask in an interview .

Indexes can be used to sort data , And use this to speed up search and sorting .

This and SUBSTITUTEWITHINDEX function It's kind of like . White tea said before when describing this function , This function belongs to one of the higher order functions , The appearance rate is not very high , Only specific scenarios can be used .

This and SQL Medium INDEX It's kind of similar , It is usually used to add index columns to the original dimension columns , To facilitate the calculation of dimensions at certain times , The original text information can be converted into numerical values that can participate in the calculation .

And in the SQL in ,INDEX The performance is more pure .

Basic grammar

CREATE INDEX  The index name 
ON  The name of the table  ( Name 1, Name 2...)
-- We can set the index according to a dimension , It can be multiple 

matters needing attention

  • INDEX It can speed up the query , But it will increase the maintenance work .
    for example : Attention should be paid to the addition, deletion and modification of INDEX Dynamic update of .

  • INDEX Will increase storage space .

  • Some data are not suitable for indexing , For example, the provinces of our country , Not much data .

  • Data that is often used as the basis for sorting , Suitable for indexing .

Interview scene :
Database index is invalid , What are the possible reasons ?
answer :
It may be when the data changes , No maintenance updates to the index .

Using examples

Case data :

In the database of white tea machine , There is a name “TEST” The database of , There is a name “ Product list ” Case data for .

Example 1:

According to the trade name , Add a new column INDEX.

CREATE INDEX Product_INDEX
ON  Product list  ( Name of commodity )

give the result as follows :

Example 2:

According to the trade name , Add a new column INDEX, Duplicate entries are not allowed in the index .

CREATE UNIQUE INDEX Product_DIS_INDEX
ON  Product list  ( Name of commodity )

give the result as follows :

Example 3:

According to the trade name , Add a new column INDEX, Duplicate entries are not allowed in the index , And it needs to be in descending order according to the product name .

CREATE UNIQUE INDEX Product_DESC_INDEX
ON  Product list  ( Name of commodity  DESC)

give the result as follows :

Example 4:

According to the commodity name and commodity classification , Add a new column INDEX, Duplicate entries are not allowed in the index .

CREATE UNIQUE INDEX GroupSort
ON  Product list  ( Name of commodity ,  Classification of goods )

give the result as follows :

This is white tea , One PowerBI Beginners .

原网站

版权声明
本文为[Powerbi white tea]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202210542593810.html