Bug #45759 feature request: allow storage engines to be notified of impending index scan
Submitted: 25 Jun 2009 16:25 Modified: 3 Jul 2009 16:43
Reporter: Zardosht Kasheff (OCA) Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Storage Engines Severity:S4 (Feature request)
Version:5.1.35 OS:Any
Assigned to: CPU Architecture:Any
Tags: Contribution, INDEX, index scan

[25 Jun 2009 16:25] Zardosht Kasheff
Description:
Storage engines are sometimes notified of impending query operations. They are notified of range query operations by the functions read_range_first and read_range_next. They know of a full table scan by rnd_init.

Storage engines are NOT notified when a full index scan about to take place. This can be helpful to know. In such cases, storage engines can do smart things.

Having a handler function be called before an index scan is about to happen is very helpful.

Looking in the code, there seem to be two places where index scans are initiated: join_read_first and join_read_last.

It is here where we would like to see the calls added

How to repeat:
n/a

Suggested fix:
will contribute a patch
[25 Jun 2009 16:26] Zardosht Kasheff
patch to implement feature

Attachment: prepare_index_scan.txt (text/plain), 1.31 KiB.

[25 Jun 2009 16:27] Zardosht Kasheff
adding tag "contribution".
[25 Jun 2009 16:31] Valeriy Kravchuk
Thank you for the feature request and code contributed.
[30 Jun 2009 0:03] Zardosht Kasheff
Monty was kind enough to implement this feature, with test cases, in MariaDB. Here what he stated on the internals mailing list:

I have now pushed all your proposed changes + more to the current
MariaDB 5.1 tree. (changeset 2713)

You can get them by either getting the lastest MariaDB code from
launchpad or looking at the patch
https://lists.launchpad.net/maria-developers/msg00463.html
[3 Jul 2009 14:28] Sergei Golubchik
What about index_first() ?
[3 Jul 2009 14:34] Zardosht Kasheff
I personally like prepare_index_scan, because it lets storage engine developers know what is coming, whereas one can mistake index_init with index_first. However, a name is a name, so I do not have very strong feelings. I care more about the functionality getting in :)
[3 Jul 2009 15:05] Sergei Golubchik
I mean, there is handler::index_first() method - it's used to find the first/minimal entry in the index. Can you use it instead of introducing a new one ?

(true, it does not *always* mean an index scan, but often it does)
[3 Jul 2009 15:12] Zardosht Kasheff
Oops, sorry. I do not think it can be used, because I believe index_first is used for queries such as "select min(a) from foo use index(a);" In that case, it is not an index scan.
[3 Jul 2009 16:06] Sergei Golubchik
okay, thanks