orientdb icon indicating copy to clipboard operation
orientdb copied to clipboard

Fetch plan support in SQL select statements

Open lvca opened this issue 13 years ago • 13 comments

fetch plan could be a new keyword of SQL SELECT syntax. In this way it could be used by JS scripts too.

lvca avatar Jun 27 '13 15:06 lvca

Hi Luca, Fetch plan can be already specified as toJSON() parameter. Could not it be used in js functions?

giastfader avatar Jun 28 '13 07:06 giastfader

I mean something like:

select from V fetchplan 'out:-1'

lvca avatar Jun 28 '13 17:06 lvca

Fetch plan does not work any more for select statements after that change in async mode. Imo.. async listener got fetchplan after execution

    ((OCommandRequestInternal) connection.database.command(command)).execute();

    // ASSIGNED THE PARSED FETCHPLAN
    listener.setFetchPlan(((OCommandRequestInternal) connection.database.command(command)).getFetchPlan());        

These two lines shouldn't be in oposite order? When I changed it everything got back to proper work. I think sync implementation still does not send prefetch payload, so fetch plan does not work.

kowalot avatar Jul 20 '13 09:07 kowalot

Could you send me a pull request if pass all the test cases?

ant clean test mvn clean install

lvca avatar Jul 21 '13 10:07 lvca

Luca, I have separate change for Prefetch in sync mode - binary portocol Problem is that, afaik, unlike async mode, PayloadStatus=0<NO MORE RECORDS/PAYLOADS> has never been sent after normal result ('l' or 'r') so far. After the change, it may break a compatibility for existing clients/drivers if they don't read full response (remaining PayloadStatus=0). How do you deal with such issues?

kowalot avatar Jul 21 '13 20:07 kowalot

What do you mean for PayloadStatus=0 ?

lvca avatar Jul 21 '13 23:07 lvca

Afaik, In sync mode, collection of records ('l') payload has been sent and that's all. In async mode, It is a chain of payloads, Record (payload-status=1), Record, Record, Prefetched (payload-status=2),Prefetched and finally No more records (Payload status==0). In async I know that when I receive that it's end of response. Unfortunately in sync mode there has not been the chain of payload so I don't know when to wait for Prefetch payload or end reading response if occurs. Therefore in my case it broke compatibility of my driver. I can change it in way that if there is no data in socket it means that it's end of response, but not sure about other clients if it's a problem or not.

kowalot avatar Jul 22 '13 08:07 kowalot

Updated also binary protocol page: https://github.com/orientechnologies/orientdb/wiki/Network-Binary-Protocol#wiki-COMMAND

lvca avatar Jul 25 '13 12:07 lvca

I will send separate pull request with change for sync statements.

kowalot avatar Jul 25 '13 12:07 kowalot

Pawel said in the Google Group: I've just started to change my code according to your new implementation of prefetching in sync statements.

  • Implemented prefetch payload is only one in whole protocol without payload-status, but async prefetch payload has payloadstatus (2).
  • Each command has overhead of 4 bytes like ALTER,CREATE,CREATE INDEX and so on, even if they don't use/support prefetching

Please reconsider to implement it with payload status (probably a new one, because current prefetch has one record so it's rather prefetch collection) and add this payload only if prefetch documents are present and finally end response with payloadstatus=NoRecords(0). In such approach you will have only 1 byte overhead in ALTER/CREATE/INDEX

lvca avatar Jul 25 '13 16:07 lvca

Good idea, let me do it...

lvca avatar Jul 25 '13 16:07 lvca

Done

lvca avatar Jul 25 '13 16:07 lvca

Works flawlessly in sync. Thanks!

kowalot avatar Jul 25 '13 16:07 kowalot