Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

storage engine: how to identify PRIMARY keys?

1 view
Skip to first unread message

Christoph Rupp

unread,
May 10, 2016, 5:12:06 AM5/10/16
to
Hi,

in the ::create() method of my storage engine I want to create indices
for all columns where (*field)->m_indexed is true.

As far as I understand there are different types of indices:
- PRIMARY: always unique
- INDEX: usually not unique (can have duplicate keys)

but I have not been able to figure out whether a FIELD object is a
primary key or not.

I saw that the Schema description (TABLE->s) has more information
about the columns, but it seems they're already sorted by priority
(i.e. primary key is first), whereas the FIELD objects are not sorted.

Thanks
Christoph

--
MySQL Internals Mailing List
For list archives: http://lists.mysql.com/internals
To unsubscribe: http://lists.mysql.com/internals

Vlad Lesin

unread,
May 10, 2016, 12:58:00 PM5/10/16
to
If I understand your question correctly you need something like this:
table->s->primary_key - pk field number, equals to MAX_KEY if there is
no explicit pk.

On 10/05/16 12:11, Christoph Rupp wrote:
> Hi,
>
> in the ::create() method of my storage engine I want to create indices
> for all columns where (*field)->m_indexed is true.
>
> As far as I understand there are different types of indices:
> - PRIMARY: always unique
> - INDEX: usually not unique (can have duplicate keys)
>
> but I have not been able to figure out whether a FIELD object is a
> primary key or not.
>
> I saw that the Schema description (TABLE->s) has more information
> about the columns, but it seems they're already sorted by priority
> (i.e. primary key is first), whereas the FIELD objects are not sorted.
>
> Thanks
> Christoph
>


--
Best regards,
Vlad

Christoph Rupp

unread,
May 11, 2016, 5:12:09 AM5/11/16
to
table->s->primary_key is always 0. I.e. for the following statement i
would have expected it to be 1:

create table test1 (value integer, id integer primary key);

My current workaround (not yet tested extensively):

I search table->key_info for the primary key (table->key_info[i]->name
must be "PRIMARY"), then I can retrieve any additional information
like table type, name etc through table->key_info[i]->key_part->field.
(I need that information to set up my index tables.)

Sergei Golubchik

unread,
May 11, 2016, 5:31:39 AM5/11/16
to
Hi, Christoph!

On May 10, Christoph Rupp wrote:
>
> in the ::create() method of my storage engine I want to create indices
> for all columns where (*field)->m_indexed is true.
>
> As far as I understand there are different types of indices:
> - PRIMARY: always unique
> - INDEX: usually not unique (can have duplicate keys)
>
> but I have not been able to figure out whether a FIELD object is a
> primary key or not.

Field object is not *a* primary key, but it can be *a part* of it.

Do you want to know whether a field is a part of a primary key?

field->part_of_key.is_set(table->s->primary_key)

Regards,
Sergei
Chief Architect MariaDB
and secu...@mariadb.org

Christoph Rupp

unread,
May 11, 2016, 6:08:17 AM5/11/16
to
2016-05-11 11:31 GMT+02:00 Sergei Golubchik <se...@mariadb.org>:
> Field object is not *a* primary key, but it can be *a part* of it.

Thanks, Sergei, i'll keep this in mind. So far my tests (and my
storage engine) assume that an index is only for one field. Sooner or
later I will have to deal with the key parts, though.
0 new messages