MM-41191: Apply upload_sessions incorrect index fix (#19383)

https://mattermost.atlassian.net/browse/MM-41191

```release-note
NONE
```

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Agniva De Sarker
2022-01-26 13:18:09 +05:30
коммит произвёл GitHub
родитель 7026818f80
Коммит d8fc23c86b
5 изменённых файлов: 170 добавлений и 0 удалений

Просмотреть файл

@@ -148,6 +148,8 @@
// mysql/000073_upgrade_plugin_key_value_store_v6.3.up.sql
// mysql/000074_upgrade_users_v6.3.down.sql
// mysql/000074_upgrade_users_v6.3.up.sql
// mysql/000075_alter_upload_sessions_index.down.sql
// mysql/000075_alter_upload_sessions_index.up.sql
// postgres/000001_create_teams.down.sql
// postgres/000001_create_teams.up.sql
// postgres/000002_create_team_members.down.sql
@@ -296,6 +298,8 @@
// postgres/000073_upgrade_plugin_key_value_store_v6.3.up.sql
// postgres/000074_upgrade_users_v6.3.down.sql
// postgres/000074_upgrade_users_v6.3.up.sql
// postgres/000075_alter_upload_sessions_index.down.sql
// postgres/000075_alter_upload_sessions_index.up.sql
package migrations
import (
@@ -3332,6 +3336,46 @@ func mysql000074_upgrade_users_v63UpSql() (*asset, error) {
return a, nil
}
var _mysql000075_alter_upload_sessions_indexDownSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x94\x92\xbd\x8e\x9d\x30\x10\x85\x7b\x3f\xc5\x74\x80\x14\xa5\x48\x91\x06\x6d\xe1\x8b\x87\x5d\x4b\xc4\xbe\x32\x46\xd9\x54\x96\x03\x5e\xad\x25\x7e\x36\x18\xa2\x9b\xb7\x8f\x30\xe8\xfe\x14\x29\xd2\x7f\x73\xce\x99\x33\x53\x28\xa4\x1a\xe1\xac\x64\x81\xac\x51\x08\xb4\x5f\xdc\xcc\xc7\xce\x5d\xd2\x8c\x9c\xf0\x99\x0b\x02\x00\xc0\xb0\xa8\xa8\x42\x68\xa7\x7e\x1d\x46\x61\x07\x07\xbf\xed\xdc\xbe\xdb\x39\xfd\xf2\x35\x83\xce\xbd\xd9\xb5\x5f\x20\x49\x72\x12\xf9\x1a\x2b\x2c\x34\xf0\x52\x34\x55\x95\x3e\x2b\xd9\x9c\x4d\x21\x45\x41\x75\xba\x4b\x98\x71\xd3\x90\x8a\xa1\x82\xd3\x0f\x08\xee\x97\xf1\xa3\xf1\x9b\x71\xf6\x09\x92\x24\x03\x2e\xb4\xbc\xf3\x8b\xb2\xa5\x92\xdf\xc0\x8f\x6f\xd3\x3c\xd8\xc5\x4f\xa3\x09\xed\xbb\x1b\xec\xe7\xb0\xd8\xc5\x87\xc5\xb7\x21\x62\xdf\x5f\x50\x21\x2c\xf6\x67\xef\x0e\x02\x9e\x80\x51\x4d\x4f\xb4\xc6\x34\x8b\x0c\x15\xec\x20\x62\x92\x27\x48\x9a\x8f\x7e\xb2\x5d\xed\x42\xf0\xd3\x18\x92\x2b\x15\x43\x5d\x29\xdf\x5d\xcc\x1a\xc9\x70\x90\x66\x0d\x6e\x36\xbe\xdb\x27\xe2\xae\xdb\x4a\xb7\xb1\xa3\x13\x5e\xde\xd7\xb7\x19\x06\x37\xf3\x2e\x01\xfd\x82\x7b\xcb\xb1\x69\x25\xcf\xc0\x05\xc3\x57\xf8\xb7\x15\x48\x01\x8f\x71\xf3\xab\xc0\x71\xd2\xff\x97\x48\xf5\x9f\x0f\x97\xed\x42\x28\x18\xf0\x32\x27\x28\x58\x4e\x48\x41\xab\xea\xe1\x33\x72\x42\x62\xce\xdb\xdf\xf0\x12\xf0\x95\xd7\xba\xbe\xe3\xf2\xbf\x01\x00\x00\xff\xff\x6f\xdd\x44\xb4\x5e\x02\x00\x00")
func mysql000075_alter_upload_sessions_indexDownSqlBytes() ([]byte, error) {
return bindataRead(
_mysql000075_alter_upload_sessions_indexDownSql,
"mysql/000075_alter_upload_sessions_index.down.sql",
)
}
func mysql000075_alter_upload_sessions_indexDownSql() (*asset, error) {
bytes, err := mysql000075_alter_upload_sessions_indexDownSqlBytes()
if err != nil {
return nil, err
}
info := bindataFileInfo{name: "mysql/000075_alter_upload_sessions_index.down.sql", size: 0, mode: os.FileMode(0), modTime: time.Unix(0, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
var _mysql000075_alter_upload_sessions_indexUpSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x94\x92\x3d\x8f\xdc\x20\x10\x86\x7b\x7e\xc5\x74\xd8\x52\x94\x22\x45\x1a\x6b\x0b\xd6\x8c\xef\x90\x1c\x58\x61\xac\x5c\x2a\x44\x6c\x4e\x87\xe4\x8f\x8b\xb1\xa3\xcb\xbf\x8f\x16\x5b\x7b\x7b\x45\x8a\xf4\x0f\xcf\xbc\xf3\x32\xa5\x46\x66\x10\x2e\x5a\x95\xc8\x5b\x8d\xc0\x86\xd5\x2f\x62\xea\xfd\x5b\x96\x93\x33\x3e\x08\x49\x00\x00\x38\x96\x35\xd3\x08\xdd\x3c\x6c\xe3\x24\xdd\xe8\xe1\xb7\x5b\xba\x17\xb7\x64\x5f\xbe\xe6\xd0\xfb\x67\xb7\x0d\x2b\x50\x5a\x90\xc4\x37\x58\x63\x69\x40\x54\xb2\xad\xeb\xec\x41\xab\xf6\x62\x4b\x25\x4b\x66\xb2\x5d\x61\xa7\xab\x43\x69\x8e\x1a\xce\x3f\x20\xfa\x5f\x36\x4c\x36\x5c\x07\xe7\x9f\x80\xd2\x1c\x84\x34\xea\x6e\x5e\xd2\x56\x5a\x7d\x83\x30\x3d\xcf\xcb\xe8\xd6\x30\x4f\x36\x76\x2f\x7e\x74\x9f\xe3\xea\xd6\x10\xd7\xd0\xc5\x84\x7d\x7f\x44\x8d\xb0\xba\x9f\x83\x3f\x08\x38\x01\x67\x86\x9d\x59\x83\x59\x9e\x18\x26\xf9\x41\xa4\x24\x27\xa0\xed\xeb\x30\xbb\xbe\xf1\x31\x86\x79\x8a\xf4\x46\xa5\x50\x37\x2a\xf4\x6f\x76\x4b\x64\x3c\x48\xbb\x45\xbf\xd8\xd0\xef\x2f\xd2\xae\xd7\x95\xde\x9f\x1d\x9d\x88\xea\xbe\xbe\x13\x50\xf3\xe7\xd5\x53\x30\x8f\xb8\x77\x9c\x7a\xd6\xea\x02\x42\x72\x7c\x82\x7f\x0f\x02\x25\xe1\x63\xd8\xe2\x26\x38\x3e\xf4\xff\x15\x59\x1b\xfd\x22\xfa\x7c\x57\xa1\xe4\x20\xaa\x82\xa0\xe4\x05\x21\x25\xab\xeb\x0f\x97\x51\x10\x92\x92\xbe\xdf\x8d\xa8\x00\x9f\x44\x63\x9a\x3b\xae\xf8\x1b\x00\x00\xff\xff\xd9\x83\xa3\x00\x5e\x02\x00\x00")
func mysql000075_alter_upload_sessions_indexUpSqlBytes() ([]byte, error) {
return bindataRead(
_mysql000075_alter_upload_sessions_indexUpSql,
"mysql/000075_alter_upload_sessions_index.up.sql",
)
}
func mysql000075_alter_upload_sessions_indexUpSql() (*asset, error) {
bytes, err := mysql000075_alter_upload_sessions_indexUpSqlBytes()
if err != nil {
return nil, err
}
info := bindataFileInfo{name: "mysql/000075_alter_upload_sessions_index.up.sql", size: 0, mode: os.FileMode(0), modTime: time.Unix(0, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
var _postgres000001_create_teamsDownSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x94\x90\xc1\x6a\x04\x21\x10\x44\xef\x7e\x45\x1f\x93\x6f\xf0\x34\xd9\x35\x30\x30\x19\xc3\xac\x81\xbd\x89\x68\x93\x34\x38\x2a\xea\x26\xf9\xfc\x30\xe3\x92\x1c\x72\x58\xf7\xd8\xd4\xab\xa2\xab\x0e\x8b\x18\x94\x80\x71\x3e\x8a\x33\x8c\xcf\x30\x4b\x05\xe2\x3c\x9e\xd4\x09\xc8\x7d\xeb\x8a\x66\x2d\x3a\x98\x15\x41\xce\xb0\x5f\xf0\xb0\x9d\x8f\x9c\xb1\x61\x52\x62\x01\x35\x3c\x4d\xe2\x2a\x1d\x17\xf9\x0a\x07\x39\xbd\xbd\xcc\x5b\xd8\x35\xc8\x78\x1f\xbf\x62\xc2\x40\xe1\x93\x2a\xf2\x6e\xa3\x37\xa5\x6e\x3a\xd9\x18\x2e\xc9\x99\x7b\xbc\x0e\x8b\xcd\x94\x2a\xc5\xd0\x6f\x7a\xcf\xf1\x92\x6c\x0c\xa5\x66\x43\x01\x1d\x67\x6c\x07\x7f\xe7\xf9\x37\x4d\xab\xa4\xc9\xf1\x5b\x64\x2b\xa0\x4d\xbd\x49\xda\x8c\x9d\xa4\x43\x8f\x7d\x64\xb1\x1f\xb8\xb6\x3f\x1b\xda\xc6\xf8\x43\x77\x8c\xb3\x9f\x00\x00\x00\xff\xff\x9c\xf4\x8f\xc0\x10\x02\x00\x00")
func postgres000001_create_teamsDownSqlBytes() ([]byte, error) {
@@ -6292,6 +6336,46 @@ func postgres000074_upgrade_users_v63UpSql() (*asset, error) {
return a, nil
}
var _postgres000075_alter_upload_sessions_indexDownSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x84\x92\xd1\x8a\xab\x30\x10\x86\xef\x7d\x8a\xb9\x10\xa2\x20\x7d\x80\x5a\x0b\x1e\x4d\xcf\x11\x4a\x3c\xb4\x5e\x74\xaf\x24\xdb\xcc\xba\x61\x35\x96\x24\xb2\xf6\xed\x17\xe3\xe2\x5a\x96\x65\xbd\x31\x33\xf3\x7f\x3f\xf3\x87\xe4\x25\xf8\xbe\xb7\xdb\xf1\xd6\xa2\xae\xa5\x12\x38\xee\xf7\x5e\x4e\xb3\x63\x7a\xa2\x1e\x00\xc0\xb5\x6f\x87\x4e\xd5\x8a\x77\x08\x16\x47\x1b\x7b\x7f\xe8\xdf\x82\xb9\x99\xc1\x16\xaf\x16\xb8\xd6\xfc\x5e\xdb\xbe\x36\x56\x4b\xd5\x04\x73\xcd\x9b\x26\xe0\x1b\x6e\xed\x84\x86\x11\x90\x08\x48\x08\xdc\x3c\x38\x16\xac\x2a\xd7\x0d\x67\xfb\xa2\xfb\xce\x1d\xa6\xef\xd6\xcc\x6b\x81\x1c\xa3\x75\x93\x5b\xab\xe5\xf3\x60\x11\xb8\x6b\xbf\xbf\xa2\xc6\x45\x20\xc7\x8d\xa3\x34\xb6\x52\x24\x44\x8a\xb1\x1e\x6e\x6d\xcf\x85\x41\x63\x64\xaf\x4c\x3d\x98\x29\xb0\x20\xdb\xad\xc6\xe6\xda\x72\x63\x16\x98\x2b\x01\x6e\x73\x47\x43\xf2\xe9\xe6\xaa\xef\x22\x35\x74\x90\x40\xca\x9e\x82\x59\xf6\x86\xf7\x30\xf6\x9c\xae\x38\x40\x56\xa6\x47\x7a\xce\x28\x04\xab\x94\x11\x10\x12\x42\xe2\xee\x33\x20\xd3\x26\x52\x90\x10\xaa\x7f\x94\x2d\xfe\xf9\xa9\xfc\x0f\x05\xcb\xe9\x65\xb2\xa1\x97\xe2\x5c\x9d\xe1\xe7\x1c\xf1\x02\x66\x27\x9a\x56\xf4\x0b\x65\x65\xf5\x3b\x0e\xbd\x82\xc7\x49\x60\xef\x37\x0c\x67\x5b\xca\x72\x28\x0e\xb1\x37\xfd\x57\x2f\x05\x7c\x3f\xfe\x08\x00\x00\xff\xff\x42\xb5\x73\x71\x41\x02\x00\x00")
func postgres000075_alter_upload_sessions_indexDownSqlBytes() ([]byte, error) {
return bindataRead(
_postgres000075_alter_upload_sessions_indexDownSql,
"postgres/000075_alter_upload_sessions_index.down.sql",
)
}
func postgres000075_alter_upload_sessions_indexDownSql() (*asset, error) {
bytes, err := postgres000075_alter_upload_sessions_indexDownSqlBytes()
if err != nil {
return nil, err
}
info := bindataFileInfo{name: "postgres/000075_alter_upload_sessions_index.down.sql", size: 0, mode: os.FileMode(0), modTime: time.Unix(0, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
var _postgres000075_alter_upload_sessions_indexUpSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x84\x92\xd1\x8a\xab\x30\x10\x86\xef\x7d\x8a\xb9\x10\xa2\x20\x7d\x80\x5a\x0b\x1e\x4d\xcf\x11\x4a\x3c\xb4\x5e\x74\xaf\x24\xdb\xcc\xba\x61\x35\x96\x24\xb2\xf6\xed\x17\xe3\xe2\x5a\x96\x65\xbd\x31\x33\xf3\x7f\x3f\xf3\x87\xe4\x25\xf8\xbe\xb7\xdb\xf1\xd6\xa2\xae\xa5\x12\x38\xee\xf7\x5e\x4e\xb3\x63\x7a\xa2\x1e\x00\xc0\xb5\x6f\x87\x4e\xd5\x8a\x77\x08\x16\x47\x1b\x7b\x7f\xe8\xdf\x82\xb9\x99\xc1\x16\xaf\x16\xb8\xd6\xfc\x5e\xdb\xbe\x36\x56\x4b\xd5\x04\x73\xcd\x9b\x26\xe0\x1b\x6e\xed\x84\x86\x11\x90\x08\x48\x08\xdc\x3c\x38\x16\xac\x2a\xd7\x0d\x67\xfb\xa2\xfb\xce\x1d\xa6\xef\xd6\xcc\x6b\x81\x1c\xa3\x75\x93\x5b\xab\xe5\xf3\x60\x11\xb8\x6b\xbf\xbf\xa2\xc6\x45\x20\xc7\x8d\xa3\x34\xb6\x52\x24\x44\x8a\xb1\x1e\x6e\x6d\xcf\x85\x41\x63\x64\xaf\x4c\x3d\x98\x29\xb0\x20\xdb\xad\xc6\xe6\xda\x72\x63\x16\x98\x2b\x01\x6e\x73\x47\x43\xf2\xe9\xe6\xaa\xef\x22\x35\x74\x90\x40\xca\x9e\x82\x59\xf6\x86\xf7\x30\xf6\x9c\xae\x38\x40\x56\xa6\x47\x7a\xce\x28\x04\xab\x94\x11\x10\x12\x42\xe2\xee\x33\x20\xf6\x7e\x43\x12\x42\xf5\x8f\xb2\xc5\x3d\x3f\x95\xff\xa1\x60\x39\xbd\x4c\x26\xf4\x52\x9c\xab\x33\xfc\x9c\x22\x5e\xc0\xec\x44\xd3\x8a\x7e\xa1\xac\xac\x7e\xc7\xa1\x57\xf0\x38\x09\xa6\x89\x14\xe1\x6c\x4c\x59\x0e\xc5\x21\xf6\xa6\xff\xea\xa5\x80\xef\xc7\x1f\x01\x00\x00\xff\xff\xb6\x25\x0e\x4c\x41\x02\x00\x00")
func postgres000075_alter_upload_sessions_indexUpSqlBytes() ([]byte, error) {
return bindataRead(
_postgres000075_alter_upload_sessions_indexUpSql,
"postgres/000075_alter_upload_sessions_index.up.sql",
)
}
func postgres000075_alter_upload_sessions_indexUpSql() (*asset, error) {
bytes, err := postgres000075_alter_upload_sessions_indexUpSqlBytes()
if err != nil {
return nil, err
}
info := bindataFileInfo{name: "postgres/000075_alter_upload_sessions_index.up.sql", size: 0, mode: os.FileMode(0), modTime: time.Unix(0, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
// Asset loads and returns the asset for the given name.
// It returns an error if the asset could not be found or
// could not be loaded.
@@ -6492,6 +6576,8 @@ var _bindata = map[string]func() (*asset, error){
"mysql/000073_upgrade_plugin_key_value_store_v6.3.up.sql": mysql000073_upgrade_plugin_key_value_store_v63UpSql,
"mysql/000074_upgrade_users_v6.3.down.sql": mysql000074_upgrade_users_v63DownSql,
"mysql/000074_upgrade_users_v6.3.up.sql": mysql000074_upgrade_users_v63UpSql,
"mysql/000075_alter_upload_sessions_index.down.sql": mysql000075_alter_upload_sessions_indexDownSql,
"mysql/000075_alter_upload_sessions_index.up.sql": mysql000075_alter_upload_sessions_indexUpSql,
"postgres/000001_create_teams.down.sql": postgres000001_create_teamsDownSql,
"postgres/000001_create_teams.up.sql": postgres000001_create_teamsUpSql,
"postgres/000002_create_team_members.down.sql": postgres000002_create_team_membersDownSql,
@@ -6640,6 +6726,8 @@ var _bindata = map[string]func() (*asset, error){
"postgres/000073_upgrade_plugin_key_value_store_v6.3.up.sql": postgres000073_upgrade_plugin_key_value_store_v63UpSql,
"postgres/000074_upgrade_users_v6.3.down.sql": postgres000074_upgrade_users_v63DownSql,
"postgres/000074_upgrade_users_v6.3.up.sql": postgres000074_upgrade_users_v63UpSql,
"postgres/000075_alter_upload_sessions_index.down.sql": postgres000075_alter_upload_sessions_indexDownSql,
"postgres/000075_alter_upload_sessions_index.up.sql": postgres000075_alter_upload_sessions_indexUpSql,
}
// AssetDir returns the file names below a certain
@@ -6832,6 +6920,8 @@ var _bintree = &bintree{nil, map[string]*bintree{
"000073_upgrade_plugin_key_value_store_v6.3.up.sql": &bintree{mysql000073_upgrade_plugin_key_value_store_v63UpSql, map[string]*bintree{}},
"000074_upgrade_users_v6.3.down.sql": &bintree{mysql000074_upgrade_users_v63DownSql, map[string]*bintree{}},
"000074_upgrade_users_v6.3.up.sql": &bintree{mysql000074_upgrade_users_v63UpSql, map[string]*bintree{}},
"000075_alter_upload_sessions_index.down.sql": &bintree{mysql000075_alter_upload_sessions_indexDownSql, map[string]*bintree{}},
"000075_alter_upload_sessions_index.up.sql": &bintree{mysql000075_alter_upload_sessions_indexUpSql, map[string]*bintree{}},
}},
"postgres": &bintree{nil, map[string]*bintree{
"000001_create_teams.down.sql": &bintree{postgres000001_create_teamsDownSql, map[string]*bintree{}},
@@ -6982,6 +7072,8 @@ var _bintree = &bintree{nil, map[string]*bintree{
"000073_upgrade_plugin_key_value_store_v6.3.up.sql": &bintree{postgres000073_upgrade_plugin_key_value_store_v63UpSql, map[string]*bintree{}},
"000074_upgrade_users_v6.3.down.sql": &bintree{postgres000074_upgrade_users_v63DownSql, map[string]*bintree{}},
"000074_upgrade_users_v6.3.up.sql": &bintree{postgres000074_upgrade_users_v63UpSql, map[string]*bintree{}},
"000075_alter_upload_sessions_index.down.sql": &bintree{postgres000075_alter_upload_sessions_indexDownSql, map[string]*bintree{}},
"000075_alter_upload_sessions_index.up.sql": &bintree{postgres000075_alter_upload_sessions_indexUpSql, map[string]*bintree{}},
}},
}}

Просмотреть файл

@@ -0,0 +1,20 @@
CREATE PROCEDURE AlterIndex()
BEGIN
DECLARE columnName varchar(26) default '';
SELECT IFNULL(GROUP_CONCAT(column_name ORDER BY seq_in_index), '') INTO columnName
FROM information_schema.statistics
WHERE table_schema = DATABASE()
AND table_name = 'UploadSessions'
AND index_name = 'idx_uploadsessions_user_id'
GROUP BY index_name;
IF columnName = 'UserId' THEN
DROP INDEX idx_uploadsessions_user_id ON UploadSessions;
CREATE INDEX idx_uploadsessions_user_id ON UploadSessions(Type);
END IF;
END;
CALL AlterIndex();
DROP PROCEDURE IF EXISTS AlterIndex;

Просмотреть файл

@@ -0,0 +1,20 @@
CREATE PROCEDURE AlterIndex()
BEGIN
DECLARE columnName varchar(26) default '';
SELECT IFNULL(GROUP_CONCAT(column_name ORDER BY seq_in_index), '') INTO columnName
FROM information_schema.statistics
WHERE table_schema = DATABASE()
AND table_name = 'UploadSessions'
AND index_name = 'idx_uploadsessions_user_id'
GROUP BY index_name;
IF columnName = 'Type' THEN
DROP INDEX idx_uploadsessions_user_id ON UploadSessions;
CREATE INDEX idx_uploadsessions_user_id ON UploadSessions(UserId);
END IF;
END;
CALL AlterIndex();
DROP PROCEDURE IF EXISTS AlterIndex;

Просмотреть файл

@@ -0,0 +1,19 @@
DO $$
<<alter_index>>
DECLARE
column_name text;
BEGIN
select array_to_string(array_agg(a.attname), ', ') as column_name INTO column_name
from
pg_index ix,
pg_attribute a
where
ix.indexrelid='idx_uploadsessions_user_id'::regclass
and a.attrelid = ix.indrelid
and a.attnum = ANY(ix.indkey);
IF COALESCE (column_name, '') = text('userid') THEN
DROP INDEX IF EXISTS idx_uploadsessions_user_id;
CREATE INDEX IF NOT EXISTS idx_uploadsessions_user_id on uploadsessions(type);
END IF;
END alter_index $$;

Просмотреть файл

@@ -0,0 +1,19 @@
DO $$
<<alter_index>>
DECLARE
column_name text;
BEGIN
select array_to_string(array_agg(a.attname), ', ') as column_name INTO column_name
from
pg_index ix,
pg_attribute a
where
ix.indexrelid='idx_uploadsessions_user_id'::regclass
and a.attrelid = ix.indrelid
and a.attnum = ANY(ix.indkey);
IF COALESCE (column_name, '') = text('type') THEN
DROP INDEX IF EXISTS idx_uploadsessions_user_id;
CREATE INDEX IF NOT EXISTS idx_uploadsessions_user_id on uploadsessions(userid);
END IF;
END alter_index $$;