Module 15 · Lesson 10 of 14Detailed study · about 30 min

Search Optimization for selective lookups

Search Optimization maintains additional search access paths so eligible selective queries can locate candidate data without broadly scanning a table.

Your learning goal

Match equality, text, VARIANT and GEOGRAPHY predicates to the appropriate search method and evaluate maintenance before enabling a paid service.

Understand the idea

A concrete example

An operations analyst repeatedly searches a very large order table for one order ID. Date clustering may not help that access pattern. Compare the lookup’s scanned partitions and bytes before considering an additional access path.

Key ideas in simple English
ConceptWhat it means
Point lookupFind a small set of rows using a key such as ORDER_ID.
Search access pathMaintained information that helps locate candidate storage.
Search methodThe kind of predicate supported by a configured access path.

Remember: Configure only justified methods and columns. Wait for readiness, measure the repeated workload and include build, maintenance and storage costs.

Explain it step by step · full theory

Learning goals and prerequisites

Match equality, text, VARIANT and GEOGRAPHY predicates to the appropriate search method and evaluate maintenance before enabling a paid service.

Use the M15_LAB setup from lesson 1. Know SELECT, joins, aggregates and window functions from Modules 03–04. Follow the supplied examples with an authorized warehouse and an isolated learning role. Keep the same data and account context when comparing runs.

Choose the right problem

An operations analyst repeatedly searches a very large order table for one order ID. Date clustering may not help that access pattern. Compare the lookup’s scanned partitions and bytes before considering an additional access path.

A full-quarter sum intentionally reads many rows and is a different workload. Adding search optimization to every column increases maintenance without proving value.

Match method to predicate

EQUALITY supports appropriate equality and IN lookups. SUBSTRING targets supported substring and regular-expression predicates; short search fragments may provide little benefit. FULL_TEXT supports eligible SEARCH text queries. These methods are not interchangeable.

For semi-structured orders, target an eligible VARIANT path and supported comparison type. For geographic delivery locations, GEO applies to supported GEOGRAPHY predicates such as ST_DWITHIN against a constant point; do not assume GEOMETRY receives the same support.

Enable narrowly and wait for readiness

Explicit Search Optimization requires Enterprise Edition or higher, table OWNERSHIP and ADD SEARCH OPTIMIZATION on its schema. Readers use ordinary SELECT access. Building and maintaining paths consumes credits and storage, and completion is asynchronous.

Estimate costs first, inspect SHOW TABLES progress, allow the path to build, then compare the same selective lookup with persisted results disabled. A tiny fixture will explain syntax without establishing a business case.

Review the evidence

The optimizer decides whether to use an eligible path. A broad predicate, incomplete build or unsupported expression can explain why a query does not benefit. Compare actual scan and execution evidence plus maintenance history before keeping the service.

Without the required edition or privileges, run the SELECT examples and reason about selective candidate locations. No account upgrade is needed to understand the decision.

Common mistakes and next action

Search access paths are most useful when an eligible predicate narrows the candidate data substantially.

Configure only justified methods and columns. Wait for readiness, measure the repeated workload and include build, maintenance and storage costs.

Words used in this lesson
Point lookup
Find a small set of rows using a key such as ORDER_ID.
Search access path
Maintained information that helps locate candidate storage.
Search method
The kind of predicate supported by a configured access path.

See how it works

Choose a step to explore the idea at your own pace.

Open the interactive explanation
Interactive explainer1 / 3

Search Optimization for selective lookups

ORDER_ID = 103
Many candidates
Measure scan

Baseline lookup

One ID on a large conceptual table may overlap many ordinary ranges.

Automatic playback is off for reduced motion. Select any step or use Previous and Next. Illustrations explain behavior; they are not live measurements.

Read the complete diagram explanation
  1. Baseline lookup

    One ID on a large conceptual table may overlap many ordinary ranges.

    ORDER_ID = 103 → Many candidates → Measure scan

  2. Build access path

    Background service maintains supported value-to-candidate information. This is a conceptual map.

    Selected columns → Build + storage → Maintenance

  3. Read selectively

    An eligible selective lookup can use fewer candidates; broad queries may not.

    ID location → Candidate data → Verify result

Try the SQL or command

Read → predict → run in your learning environment → compare. You can also learn by reading without an account.

New to SQL? Where to run it and how to read it

A query is a question written in SQL. Snowflake runs it and returns a result table. This website shows examples; it does not connect to your account.

  1. No account yet? Read and predict the output first. Follow the account and Snowsight lesson when you are ready.
  2. For SQL practice, use a learning account in Snowsight and select an authorized role and warehouse. A role determines permissions; a warehouse supplies processing power. Follow the example’s database/schema setup when it refers to stored objects.
  3. Read the entire example, including comments beginning with --. Run the selected statement or labeled block in the stated order. Examples labeled Python, shell or HTTP belong in that client, not in a SQL editor.
  4. Compare values and row counts with the explained result. If an example deliberately causes an error, follow its rollback and cleanup steps before continuing.
SELECT / FROM
Choose the values to return / identify their input.
VALUES / COLUMN1
VALUES supplies tiny example rows. COLUMN1 means their first column, COLUMN2 their second.
AS / WITH
AS gives a result a readable name. WITH names a temporary query step within one statement.
NULL / ::
NULL means missing or unknown. The :: notation converts a value to a named data type.
Session
One connection and its settings. Keep related transaction steps in the same session.
Database.schema.table
A full address for stored data. It is separate from the warehouse that processes queries.

Need the L2_OBJECTS_LAB setup? Open the first database-object lesson →

Help with common practice errors
  • No active warehouse: select a warehouse your role can use. Do not assume you need to create a new one.
  • Object missing or not authorized: check the full name, required setup and active role. Ask the account owner for access if needed.
  • Object already exists: setup may already have run. Read the current state or choose a fresh lab name consistently; do not add OR REPLACE blindly.
  • Different result: check whether an earlier INSERT or UPDATE changed the data. VALUES examples provide their own fresh input for each statement.

Before running this lesson

Manual examples for L2_OBJECTS_LAB.M15_LAB. Select an authorized warehouse and a role with database/schema access and permission to create the lab objects. Setup runs once with fresh names. Optional paid services require their stated privileges and edition. SQL and performance timings have not been executed or measured for this lesson.

Create optional lookup inputs

SQL · example
CREATE TABLE ORDER_SEARCH AS SELECT * FROM ORDERS;
ALTER TABLE ORDER_SEARCH ADD COLUMN DETAILS VARIANT;
ALTER TABLE ORDER_SEARCH ADD COLUMN NOTE VARCHAR;
ALTER TABLE ORDER_SEARCH ADD COLUMN LOCATION GEOGRAPHY;
UPDATE ORDER_SEARCH SET DETAILS=OBJECT_CONSTRUCT('channel','web'),
 NOTE='express delivery',LOCATION=TO_GEOGRAPHY('POINT(0 0)');
SELECT ORDER_ID FROM ORDER_SEARCH WHERE ORDER_ID=103;
SELECT ORDER_ID FROM ORDER_SEARCH WHERE DETAILS:channel::STRING='web';
SELECT ORDER_ID FROM ORDER_SEARCH WHERE NOTE ILIKE '%express%';
SELECT ORDER_ID FROM ORDER_SEARCH
WHERE ST_DWITHIN(LOCATION,TO_GEOGRAPHY('POINT(0 0)'),1000);

What to expect and why

Equality returns 103. The other three predicates return all six IDs on this teaching fixture, so they are intentionally poor selectivity examples. A production benefit needs a much smaller matching fraction.

Optional paid-service configuration

SQL · example
-- Review privileges and cost estimates before uncommenting.
-- SELECT SYSTEM$ESTIMATE_SEARCH_OPTIMIZATION_COSTS(
--  'L2_OBJECTS_LAB.M15_LAB.ORDER_SEARCH');
-- ALTER TABLE ORDER_SEARCH ADD SEARCH OPTIMIZATION
--  ON EQUALITY(ORDER_ID,DETAILS:channel),SUBSTRING(NOTE),GEO(LOCATION);
SHOW TABLES LIKE 'ORDER_SEARCH' IN SCHEMA L2_OBJECTS_LAB.M15_LAB;
-- After the experiment, remove only the lab configuration:
-- ALTER TABLE ORDER_SEARCH DROP SEARCH OPTIMIZATION;

What to expect and why

The estimate is not a bill. SHOW TABLES exposes search optimization configuration/progress. Enabling table-wide defaults alone does not enable every specialized method.

Check your understanding

Choose an answer, then check your reasoning. This is practice, not a scored test.

Will a predicate matching nearly every row be the strongest lookup optimization case?

Try it yourself

Compare order-ID lookup, a common status value and a rare delivery-region predicate. Choose one investigation first.

Compare your reasoning

Configure only justified methods and columns. Wait for readiness, measure the repeated workload and include build, maintenance and storage costs.

Key takeaway

Configure only justified methods and columns. Wait for readiness, measure the repeated workload and include build, maintenance and storage costs.

Connect this lesson to the learning path

Official sources and curriculum

Module 15 · See module scope

By Rohit Ray · Independent educational lesson · Explore this visual lab