Exposed icon indicating copy to clipboard operation
Exposed copied to clipboard

Provide a way to define primary and secondary XML Indexes

Open ashishs opened this issue 3 years ago • 3 comments

Exposed currently has no way to define xml indexes in MS SQL Server.

E.g:

CREATE PRIMARY XML INDEX [primary_xml_index_name] ON [table_name]([xml_column_1])

CREATE XML INDEX secondary_xml_index_name ON [table_name]([xml_column_1]) USING XML INDEX [primary_xml_index_name] FOR VALUE

Secondary xml indexes can be on PATH, VALUE, or PROPERTY Documentation at XML Indexes

Note: a probable fix is to allow a listOf < DdlAware > objects to be added ad-hoc to a Table and have run after the table is created. The Index class is defined as a data class which prohibits subclassing.

ashishs avatar Nov 07 '22 12:11 ashishs

Hi @ashishs This seems a very DB-specific feature to me. My suggestion would be to implement this using a prepared statement instead.

AlexeySoshin avatar Nov 14 '22 12:11 AlexeySoshin

@AlexeySoshin Even if this is created using a prepared statement, ther create missing columns method of the SchemaUtils breaks this. This happens in the code where indexes are checked. So creating the schema from code is not possible if XML indexes are used.

ashishs avatar Nov 15 '22 15:11 ashishs

@ashishs Regarding primary xml indexes, as a start, could you please confirm if creating it by leveraging indexType works?

val tester = object : Table("tester") {
    val id = integer("id")
    val primaryXml = xml("primary_xml_column") // assumes a custom column type
    
    override val primaryKey = PrimaryKey(id)
    
    init {
        index("primary_xml_index", false, primaryXml, indexType = "PRIMARY XML")
    }
}
// generates SQL
CREATE TABLE tester (id INT PRIMARY KEY, primary_xml_column XML NOT NULL)
CREATE PRIMARY XML INDEX primary_xml_index ON tester (primary_xml_column)

If this doesn't work for you, please consider providing the exception you're getting, as well as how the xml column type is declared and registered for use, so we can take a further look.

bog-walk avatar Jun 19 '23 10:06 bog-walk