executing-plans
executing-plans
Use when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available
mongodb-qe-size-estimationEstimates the storage and memory impact of encrypting fields in collections with Queryable Encryption (QE) enabled. Do NOT use for collections that use Client-Side Field Level Encryption (CSFLE) instead of QE.
Independent GitHub snapshot · Automated classification · Original documentation governs
Validate the user's inputs, whether manual or via an encryption schema, against the following:
An encrypted field may be "unindexed" meaning it has no query types enabled. Fields of BSON type object or array only support unindexed encryption, though other BSON types can also be unindexed. Otherwise, allowed query types based on a field's BSON type are:
A string field may have both "prefix" and "suffix" enabled, in which case "queries" may be an array of two objects. This is the only valid case where one field is indexed for multiple query types.
No other BSON type + query type combinations are permitted.
Don't accept "preview" query types such as "suffixPreview". These are from earlier Public Preview releases of those query types, so the sizing formulas for their GA versions don't apply.
If the user's input violates any of the preceding rules, reject it. If a user doesn't specify BSON type, only check that each field either has no query types enabled, exactly one valid query type, or exactly two (prefix and suffix). Enumerate validation failures, list allowed combinations, and don't proceed until the user provides valid input.
Create an empty qe-sizing-calculations.md file in the OS temp directory ($TMPDIR, or /tmp if unset). If a qe-sizing-calculations.md file already exists at that location, inform the user and ask for confirmation to delete it and create a new one for the new set of calculations.
State: "This skill calculates the maximum storage impact of enabling Queryable Encryption on a collection. Values are saved to the file if you want to verify the calculations or see per-field numbers. Note that prefix, suffix, and substring queries on encrypted fields require MongoDB 9.0, and aren't supported in earlier versions.
All values are worst-case. You may see a smaller impact on storage or memory in practice.
Do you want to provide field information manually, or use an encryption schema file?"
If the user opts for an encryption schema, request it as either pasted content or a file path, and expect JSON format. Validate the schema against this skill's "Validation" section. If the schema is valid but includes fields with "range" queries enabled, inform the user that no calculations are available for those fields, so their impact is estimated as 0.
Ask the user how many documents in the collection have encrypted fields. If they don't know, a safe default is the total number of documents in the collection. Save this value to qe-sizing-calculations.md as:
N:
Save this value to qe-sizing-calculations.md as:
numUnindexed:
Save this value to qe-sizing-calculations.md as:
numIndexed:
Save the sum of numUnindexed and numIndexed to qe-sizing-calculations.md as:
numEntries:
Write a section heading to qe-sizing-calculations.md:
== FIELD VALUES ===============================================================
As you get information, write it to qe-sizing-calculations.md in the following format, omitting any lines that don't apply. For unindexed fields, this means omitting the Query Type.
<the name provided by the user, or the dot notation "path" value if taken from the encryption schema> Query Type: <equality, range, prefix, suffix, substring, or "prefix and suffix"> mlen: <include if Query Type is substring. Integer from 2-50, inclusive> lb: <include if Query Type is "prefix", "suffix", or "substring". Integer 1+ for prefix and suffix queries, or 2+ for substring queries> ub: <include if Query Type is "prefix", "suffix", or "substring". Integer 1+ for prefix and suffix queries, or 2-6 for substring queries> lb_prefix: <include if Query Type is "prefix and suffix". Integer 1+> ub_prefix: <include if Query Type is "prefix and suffix". Integer 1+> lb_suffix: <include if Query Type is "prefix and suffix". Integer 1+> ub_suffix: <include if Query Type is "prefix and suffix". Integer 1+> v: <omit if Query Type is range, otherwise include. Integer representing the average byte length of the unencrypted values for the field>
If the user provided an encryption schema, do this once:
If the user didn't provide an encryption schema, do this per field:
Do this per field:
Check the list below, and ask the user for the values that aren't already populated. Write all values to the qe-sizing-calculations.md file.
mlen: (LLM Note: only include if no schema provided, and Query Type is substring) Max Length, the maximum allowable length of the string. lb: (LLM Note: only include if no schema provided, and Query Type is "prefix", "suffix", or "substring") Lower Bound, the minimum searchable characters. ub: (LLM Note: only include if no schema provided, and Query Type is "prefix", "suffix", or "substring") Upper Bound, the maximum searchable characters. lb_prefix: (LLM Note: only include if no schema provided, and Query Type is "prefix and suffix") Lower Bound for prefix queries, the minimum searchable characters. ub_prefix: (LLM Note: only include if no schema provided, and Query Type is "prefix and suffix") Upper Bound for prefix queries, the maximum searchable characters. lb_suffix: (LLM Note: only include if no schema provided, and Query Type is "prefix and suffix") Lower Bound for suffix queries, the minimum searchable characters. ub_suffix: (LLM Note: only include if no schema provided, and Query Type is "prefix and suffix") Upper Bound for suffix queries, the maximum searchable characters. v: (LLM Note: skip if Query Type is range since we have no calculation for those, otherwise needed once per field). Average byte length of the unencrypted values for the field. If the user provides character length, accept it as equivalent.
Validate values against the formatting snippet at the start of this step. Validate that lb ≤ ub ≤ mlen (if present). Validate that lb_prefix ≤ ub_prefix and lb_suffix ≤ ub_suffix (if present). If a value falls outside allowable bounds, reject it and inform the user. Do not proceed without a valid value.
If mlen < v, warn the user that the full field value isn't queryable, but accept it as valid.
Repeat until you have populated the full number of entries, numEntries, in qe-sizing-calculations.md.
This step populates calculation information to file, including intermediate steps.
For every entry in qe-sizing-calculations.md:
For fields with no Query Type:
T: 0 Document Storage (bytes): <run the calculation: 71 + ceil((v+6)/16) * 16>
For fields with a Query Type of "equality":
T: 1 Document Storage (bytes): <run the calculation: 1.2 * (255 * T + 122 + ceil((v + 6) / 16) * 16)>
For fields with a Query Type of "range", there is currently no formula, so record an entry with values of 0:
T: 0 Document Storage (bytes): 0
For fields with a Query Type of "prefix" or "suffix":
T formula: T = 1 + (ub - lb + 1) T calculation: <The T formula template with all placeholders populated by the field's values, but not calculated> T: <run the calculation in "T calculation" and write the result here> Document Storage (bytes): <run the calculation: 1.2 * (255 * T + 122 + ceil((v + 6) / 16) * 16)>
For fields with a Query Type of "prefix and suffix":
T formula: T = 1 + (ub_prefix - lb_prefix + 1) + (ub_suffix - lb_suffix + 1) T calculation: <The T formula template with all placeholders populated by the field's values, but not calculated> T: <run the calculation in "T calculation" and write the result here> Document Storage (bytes): <run the calculation: 1.2 * (255 * T + 122 + ceil((v + 6) / 16) * 16)>
For fields with a Query Type of "substring":
T formula: T = 1 + (ub - lb + 1) * (2 * mlen + 2 - ub - lb) / 2 T calculation: <The T formula template with all placeholders populated by the field's values, but not calculated> T: <run the calculation in "T calculation" and write the result here> Document Storage (bytes): <run the calculation: 1.2 * (255 * T + 122 + ceil((v + 6) / 16) * 16)>
These values are collection-level and calculated as totals across all entries.
At the end of the qe-sizing-calculations.md file, silently write the following lines:
== COLLECTION-LEVEL TOTALS ==================================================== N: <copy the N value from the top of the file down to this section, for easier reading> T_Total: Index Storage (bytes): <run the calculation: 1.2 * (67 * T_Total + 640)> Total Disk Storage (bytes): <run the calculation: N * (Index Storage + (the sum of all Document Storage values))> Memory (bytes): <run the calculation: N * (52 * T_Total + 17)>
Output the following, and include the units:
Total Disk Storage Impact: <the Total Disk Storage value from qe-sizing-calculations.md, converted to decimal GB (1000³ bytes) > Required Memory: <the Memory value from qe-sizing-calculations.md, converted to binary GiB (1024³ bytes)> Fields by Impact (descending): <sort all fields in qe-sizing-calculations.md by T, descending, then list them as: Name (<either the Query Type, or unindexed>): T>
If the encryption schema or manual inputs included fields with range queries enabled, list those fields and remind the user that their impact wasn't calculated.
Present advice. Don't provide any advice the user has explicitly rejected, such as suggesting different query types if they insist a field needs to allow substring queries. Only raise problems, don't mention something if it passes all checks. If you suggest changing values to a specific number, populate the Step 6 T formula template for that query type with the suggested values, calculate it with available mathematical tools, and quote only that result.
Also inform the user of the path to the qe-sizing-calculations.md file, and ask if they want to review the data, or delete the temporary file. Remind them that the temporary file contains the names of encrypted fields and their average plaintext lengths, and should be deleted once finished.