Execute Encoded Plan through N1QL

Example query:

PREPARE users_per_country FROM SELECT u.iso_country, COUNT(1) AS user_count. FROM users AS u WHERE u.doc_type = 'user' GROUP BY u.iso_country ORDER BY COUNT(1) DESC, u.iso_country ASC'

Part of the response includes encoded_plan. According to the documentation the encoded plan can be used if the prepared statement name does not exist.

This will execute the prepared statement by name

EXECUTE 'users_per_country'

But what if that prepared statement is not available and just the encoded plan is? How do you specify the encoded plan as part of your N1QL statement?

You can only use the encoded_plan in the REST API request, and this has to be alongside the prepared name. As an example,

curl “http://:8093/query/service” -H “content-type: application/json” -d ‘{“prepared”: “users_per_country”, “encoded_plan”: “…”}’

On a node where users_per_country does not exist, this will be created from the encoded plan.
Currently there is no way to use the encoded plan as directly as part of a N1QL statement.