[odb-users] Index Pragmas DO NOT support index on expressions

Boris Kolpackov boris at codesynthesis.com
Fri Feb 17 01:40:36 EST 2023


Reilly He <reillyhekazusa at gmail.com> writes:

> I found it really hard to create this index in the context of ODB index
> pragmas. I looked through the manual:
> https://www.codesynthesis.com/products/odb/doc/manual.xhtml#14.7
> And I did not find any solution.

No, I don't think there is way to achieve this via the pragma currently.


> So if ODB does not support creating indexes on an expression, I can do that
> on my own using SQLite CREATE INDEX pragma.

Yes, this is probably the only way, currently.


> But, this is not included in the ODB migration, which leaves a very
> unstable point in our project. Since if somebody in the future changes the
> schema in the Post table, this part might fail.

Yes, that's a valid concern. However, even if we were to add support
for this in the pragma, it will be just as a raw column name (or column
expression). Something along these lines:

class Post
{
  int id;

  #pragma db index("id_i") column("abs(id)")
};

So there is still a possibility of, say, renaming the id member but
forgetting to update the index definition. Though having the two
next to each other definitely reduces this likelihood compared to
creating the index manually.

If you would like, we can add this support to the index pragma.



More information about the odb-users mailing list