#1 2025-05-05 14:12:40

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 461

creating index through mormot's orm with part of field's content

I have an Torm object and I am MariaDB as external database
When Torm.InitializeTable runs for this table, it checks and create the index if it does not exist.

The SQL that should be run for mysql is: CREATE INDEX IF NOT EXISTS NDXExNams_del_cat_nam ON exnams(del,cat,nam(30));

This can not be done through Mormot and I am getting the error: "TOrmPropInfoList.IndexByNameOrExcept(nam(30)): unkwnown field in TOrmExNams"

The db field nam is about 2048 bytes and it is not allowed to have all content in the index. With the above sql only the first 30 characters are used in the index.

The same query in Postgresql can be: CREATE INDEX IF NOT EXISTS "NDXExNams_del_cat_nam" ON exnams(del, cat, substring(nam, 1, 30));

Is it possible to bypass the check for the field names from mormot or give up and create them manually?

Thank you in advance

Offline

#2 2025-05-05 14:31:06

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 15,005
Website

Re: creating index through mormot's orm with part of field's content

What is the ExtFieldNames[] content in TRestStorageExternal.CreateSqlMultiIndex ?

Where does this nam(30) come from?

I am really confused.
For such complex indexes, the idea is to create the index by hand in pure SQL (bypassing the ORM), then disable the automatic creation of indexes with the proper TOrmInitializeTableOptions.

Offline

#3 2025-05-05 14:37:19

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 461

Re: creating index through mormot's orm with part of field's content

('del', 'cat', '')

Offline

#4 2025-05-05 14:48:21

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 15,005
Website

Re: creating index through mormot's orm with part of field's content

Yes, because you forced 'nam(30)' in your call, right?

This is incorrect and unsupported for sure.

I am not able to reproduce this here.

Offline

#5 2025-05-05 14:58:56

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 461

Re: creating index through mormot's orm with part of field's content

My stack during the error:
- r77204424 KERNELBASE RaiseException + 0x64 
- mormot.core.text.ESynException.RaiseUtf8('%:IndexByNameOrExcept(%):unknown field in %', (...)) 
- mormot.orm.base.TOrmPropInfoList.IndexByNameOrExcept('nam(30')) 
- mormot.orm.core.TOrmMapping.InternalToExternalDynArray(???, ('del', 'cat', "), $IEDOF870) 
- mormot.orm.sql.TRestStorageExternal.CreateSqlMultifindex(???, (...).False, 'NDXExNams_del_cat_nam') 
- mormot.orm.server.TRestOrmServer.CreateSqlMultifindex(TOrmExNams, (...).False, 'NDXExNams_del_cat_nam') 

I found out that defining nam(30) as field in CreateSqlMultiIndex does not work.
The question is if is going to be supported or not.
I have no problem to create manually such indexes if mormot can not support them.

Offline

#6 2025-05-05 17:05:46

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 15,005
Website

Re: creating index through mormot's orm with part of field's content

As I wrote above, it is not supported for sure.

Offline

#7 2025-05-05 17:25:55

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 461

Re: creating index through mormot's orm with part of field's content

It is ok, @ab.
Thank you a lot for the amazing mormot2.

Offline

Board footer

Powered by FluxBB