如何在服务器上已建立的数据库中添加索引?

如何将索引添加到已创建的数据库中?

我是MYSQL的新手,并且在Django中建立了一个没有任何索引的数据库,这确实非常慢。

我正在尝试添加索引。问题是我需要按外键过滤。即使表不是很大(产品= 1百万,另一个是10k),查询仍然非常缓慢(思考20-25秒)。

这是我的Django代码:

class ScreenTwo(Screen):
    def on_day_select(self,text): #Function assigns selected day from spinner to a variable
        global day
        day = str(text)
    def on_hours_select(self,text): #Function assigns selected 12-hour from spinner to a variable
        global hours
        hours = int(text)
    def on_minutes_select(self,text): #Function assigns selected minute from spinner to a variable
        global minutes
        minutes = int(text)
    def on_AmPm_select(self,text): #Function assigns selected a.m/p.m from spinner to a variable
        global AmPm
        AmPm = str(text)
    def hours_checking(self): #Function converts 12hr time to 24hr time
        global AmPm
        global hours
        global minutes
        global day
        try:
            if 1 <= hours <= 11 and AmPm == 'a.m':
                pass
            elif 1 <= hours <= 12 and AmPm == 'p.m':
                hours += 12
            elif hours == 12 and AmPm == 'a.m':
                hours = 0
        except:
            print('error')
        else:
            print(day,hours,minutes)
    pass

我应该在另一个表中的“ id”还是 product 表中的“另一个”列上建立索引吗?

我是否创建像这样的索引:

#large db (Product) filtered by foreign key (another__id)
Product.objects.filter(another__id='x')

由于这是在服务器上,我应该怎么做?

zx986410 回答:如何在服务器上已建立的数据库中添加索引?

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3132410.html

大家都在问