pingcap / django-tidb

TiDB dialect for Django
Apache License 2.0
30 stars 17 forks source link

feat: support AUTO_ID_CACHE #56

Closed wd0517 closed 1 year ago

wd0517 commented 1 year ago

Refer to https://github.com/pingcap/django-tidb/issues/52

This PR plans to support AUTO_ID_CACHE in Django by declaring it in the model's meta option.

Note: tidb_auto_id_cache only affects table creation.

For example:

class Test(models.Model):
    a = models.TextField()

    class Meta:
        tidb_auto_id_cache = 1

This PR also removed functions.py because we have already reverted DatabaseWrapper.vendor to mysql, so there is no need to patch the as_tidb function anymore.

zhangyangyu commented 1 year ago

Do we need the tidb prefix? I think it's TiDB unique and already under django-tidb scope?

zhangyangyu commented 1 year ago

Seems after v6.4.0 make it default doesn't hurt anything.

wd0517 commented 1 year ago

Do we need the tidb prefix? I think it's TiDB unique and already under django-tidb scope?

I think has tidb prefix can help application developers understand that this attribute belongs to tidb.

wd0517 commented 1 year ago

I have added a TIDB_DEFAULT_AUTO_ID_CACHE = 1 which can be modified in settings.py.

wd0517 commented 1 year ago

I revert the above change, because AUTO_ID_CACHE=1 have bad performance before TiDB v6.4.0, if we set a default auto_id_cache in django-tidb, it will make things become complex.