[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-09-05 (世界標準時間)。"],[],[],null,["# Numeric search indexes\n\n| **Note:** This feature is available with the Spanner Enterprise edition and Enterprise Plus edition. For more information, see the [Spanner editions overview](/spanner/docs/editions-overview).\n\n\u003cbr /\u003e\n\nIn addition to indexing text, the\n[search index](/spanner/docs/full-text-search/search-indexes) provides an\nefficient way to index numbers. It's primarily used to augment\n[full-text search](/spanner/docs/full-text-search) queries with\nconditions on numeric fields. This page describes indexing numbers for equality\nand inequality queries, and indexing an array of numbers.\n\nTokenize numbers\n----------------\n\nNumber tokenizers are used to generate a set of tokens that are used to\naccelerate numeric comparison searches.\n\nUse the\n[`TOKENIZE_NUMBER`](/spanner/docs/reference/standard-sql/search_functions#tokenize_number)\nfunction to create a numeric index. `TOKENIZE_NUMBER` supports `INT64`,\n`FLOAT32`, `FLOAT64` or `ARRAY` of these types.\n\nFor PostgreSQL, use the\n[`spanner.tokenize_number`](/spanner/docs/reference/postgresql/functions-and-operators#search_functions)\nfunction to create a numeric index. `spanner.tokenize_number` only supports\nthe `bigint` type.\n\nIndex numbers for equality and inequality queries\n-------------------------------------------------\n\nSpanner supports indexing numbers for *equality* and *inequality* .\nEquality searches match a number. Range and inequality searches match a number\nwithin a specific range. You set this value in the\n[`TOKENIZE_NUMBER`](/spanner/docs/reference/standard-sql/search_functions#tokenize_number)\n`comparison_type` parameter:\n\n- **Equality** : `comparison_type=\u003e\"equality\"`\n- **Inequality and equality** : `comparison_type=\u003e\"all\"`\n\nIn both cases, the original number (either integer or floating point) undergoes\na process of tokenization, which is conceptually similar to full-text\ntokenization. It produces a set of tokens that the query can then use to locate\ndocuments matching the number condition.\n\nEquality indexing only produces one token, which represents the number. This\nmode is recommended if queries only have conditions in the form of `field = @p`\nin the `WHERE` clause.\n\nInequality and equality indexing can accelerate a wider range of conditions in\nthe `WHERE` clause of the query. This includes `field \u003c @p`, `field \u003c= @p`,\n`field \u003e @p`, `field \u003e= @p`, `field BETWEEN @p1 and @p2` and `field \u003c\u003e @p` in\naddition to equality conditions. To implement this type of indexing,\nSpanner produces tokens in the underlying search index.\nSpanner can produce many tokens for each indexed number,\ndepending upon tuning parameters. The number of tokens depends on the parameters\nthat are set for `TOKENIZE_NUMBER`, such as `algorithm`, `min`, `max` and\n`granularity`. It's therefore important to evaluate the tuning parameters\ncarefully to ensure an appropriate balance between disk storage and lookup time.\n\n### Array tokenization\n\n| **Note:** The examples in this section are intended for GoogleSQL-dialect databases. PostgreSQL doesn't support numeric array acceleration with search indexes.\n\nIn addition to scalar values,\n[`TOKENIZE_NUMBER`](/spanner/docs/reference/standard-sql/search_functions#tokenize_number)\nsupports tokenization of an array of numbers.\n\nWhen `TOKENIZE_NUMBER` is used with the `ARRAY` column, you must\nspecify `comparison_type=\u003e\"equality\"`. Range queries aren't supported with an\narray of numbers. \n\n CREATE TABLE Albums (\n AlbumId STRING(MAX) NOT NULL,\n Ratings ARRAY\u003cINT64\u003e,\n Ratings_Tokens TOKENLIST\n AS (TOKENIZE_NUMBER(Ratings, comparison_type=\u003e\"equality\")) HIDDEN\n ) PRIMARY KEY(AlbumId);\n\n CREATE SEARCH INDEX AlbumsIndex ON Albums(Ratings_Tokens);\n\nThe following query finds all albums that have a rating of\n1 or 2: \n\n SELECT AlbumId\n FROM Albums\n WHERE ARRAY_INCLUDES_ANY(Ratings, [1, 2])\n\nThe following query finds all albums that were rated as 1 and as 5: \n\n SELECT AlbumId\n FROM Albums\n WHERE ARRAY_INCLUDES_ALL(Ratings, [1, 5])\n\nWhat's next\n-----------\n\n- Learn about [tokenization and Spanner tokenizers](/spanner/docs/full-text-search/tokenization).\n- Learn about [search indexes](/spanner/docs/full-text-search/search-indexes).\n- Learn about [index partitioning](/spanner/docs/full-text-search/partition-search-index)."]]