-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support ADD_TIFLASH_ON_DEMAND option
Signed-off-by: JaySon-Huang <tshent@qq.com>
- Loading branch information
1 parent
3e99f50
commit 67bf470
Showing
3 changed files
with
122 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
from .vector_type import VectorType | ||
from .adaptor import VectorAdaptor | ||
from .index import VectorIndex | ||
|
||
__all__ = ["VectorType", "VectorAdaptor"] | ||
__all__ = ["VectorType", "VectorAdaptor", "VectorIndex"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from typing import Optional, Any | ||
|
||
import sqlalchemy | ||
|
||
from sqlalchemy.ext.compiler import compiles | ||
from sqlalchemy.schema import Index | ||
|
||
class VectorIndex(Index): | ||
def __init__( | ||
self, | ||
name: Optional[str], | ||
*expressions, # _DDLColumnArgument | ||
_table: Optional[Any] = None, | ||
**dialect_kw: Any, | ||
): | ||
super().__init__(name, *expressions, unique=False, _table=_table, **dialect_kw) | ||
self.dialect_options["mysql"]["prefix"] = "VECTOR" | ||
# add tiflash automatically when creating vector index | ||
self.dialect_options["mysql"]["add_tiflash_on_demand"] = True | ||
|
||
# VectorIndex.argument_for("mysql", "add_tiflash_on_demand", None) | ||
|
||
@compiles(sqlalchemy.schema.CreateIndex) | ||
def compile_create_vector_index(create_index_elem: sqlalchemy.sql.ddl.CreateIndex, compiler: sqlalchemy.sql.compiler.DDLCompiler, **kw): | ||
text = compiler.visit_create_index(create_index_elem, **kw) | ||
index_elem = create_index_elem.element | ||
if index_elem.dialect_options.get("mysql", {}).get("add_tiflash_on_demand"): | ||
text += " ADD_TIFLASH_ON_DEMAND" | ||
return text |