<commit_before><?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
-->
<!DOCTYPE concept PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
<concept id="hints">

  <title>Optimizer Hints</title>

  <titlealts audience="PDF">

    <navtitle>Optimizer Hints</navtitle>

  </titlealts>

  <prolog>
    <metadata>
      <data name="Category" value="Impala"/>
      <data name="Category" value="SQL"/>
      <data name="Category" value="Querying"/>
      <data name="Category" value="Performance"/>
      <data name="Category" value="Troubleshooting"/>
      <data name="Category" value="Developers"/>
      <data name="Category" value="Data Analysts"/>
    </metadata>
  </prolog>

  <conbody>

    <p>
      <indexterm audience="hidden">hints</indexterm>
      The Impala SQL supports query hints, for fine-tuning the inner workings of queries.
      Specify hints as a temporary workaround for expensive queries, where missing statistics or
      other factors cause inefficient performance.
    </p>

    <p>
      Hints are most often used for the resource-intensive Impala queries, such as:
    </p>

    <ul>
      <li>
        Join queries involving large tables, where intermediate result sets are transmitted
        across the network to evaluate the join conditions.
      </li>

      <li>
        Inserting into partitioned Parquet tables, where many memory buffers could be allocated
        on each host to hold intermediate results for each partition.
      </li>
    </ul>

    <p conref="../shared/impala_common.xml#common/syntax_blurb"/>

    <p rev="2.0.0">
      In <keyword keyref="impala20_full"/> and higher, you can specify the hints inside comments
      that use either the <codeph>/* */</codeph> or <codeph>--</codeph> notation. Specify a
      <codeph>+</codeph> symbol immediately before the hint name. Recently added hints are only
      available using the <codeph>/* */</codeph> and <codeph>--</codeph> notation. For clarity,
      the <codeph>/* */</codeph> and <codeph>--</codeph> styles are used in the syntax and
      examples throughout this section. With the <codeph>/* */</codeph> or <codeph>--</codeph>
      notation for hints, specify a <codeph>+</codeph> symbol immediately before the first hint
      name. Multiple hints can be specified separated by commas, for example <codeph>/*
      +clustered,shuffle */</codeph>
    </p>

<codeblock rev="2.0.0">SELECT STRAIGHT_JOIN <varname>select_list</varname> FROM
<varname>join_left_hand_table</varname>
  JOIN /* +BROADCAST|SHUFFLE */
<varname>join_right_hand_table</varname>
<varname>remainder_of_query</varname>;

SELECT <varname>select_list</varname> FROM
<varname>join_left_hand_table</varname>
  JOIN -- +BROADCAST|SHUFFLE
<varname>join_right_hand_table</varname>
<varname>remainder_of_query</varname>;

INSERT <varname>insert_clauses</varname>
  /* +SHUFFLE|NOSHUFFLE */
  SELECT <varname>remainder_of_query</varname>;

INSERT <varname>insert_clauses</varname>
  -- +SHUFFLE|NOSHUFFLE
  SELECT <varname>remainder_of_query</varname>;

<ph rev="2.12.0 IMPALA-4168">
INSERT /* +SHUFFLE|NOSHUFFLE */
  <varname>insert_clauses</varname>
  SELECT <varname>remainder_of_query</varname>;</ph>

<ph rev="2.12.0 IMPALA-4168">
INSERT -- +SHUFFLE|NOSHUFFLE
  <varname>insert_clauses</varname>
  SELECT <varname>remainder_of_query</varname>;</ph>

<ph rev="2.12.0 IMPALA-4168">
UPSERT /* +SHUFFLE|NOSHUFFLE */
  <varname>upsert_clauses</varname>
  SELECT <varname>remainder_of_query</varname>;</ph>

<ph rev="2.12.0 IMPALA-4168">
UPSERT -- +SHUFFLE|NOSHUFFLE
  <varname>upsert_clauses</varname>
  SELECT <varname>remainder_of_query</varname>;</ph>

<ph rev="IMPALA-2924">SELECT <varname>select_list</varname> FROM
<varname>table_ref</varname>
  /* +{SCHEDULE_CACHE_LOCAL | SCHEDULE_DISK_LOCAL | SCHEDULE_REMOTE}
    [,RANDOM_REPLICA] */
<varname>remainder_of_query</varname>;</ph>

<ph rev="IMPALA-2522 2.8.0">INSERT <varname>insert_clauses</varname>
  -- +CLUSTERED
  SELECT <varname>remainder_of_query</varname>;

INSERT <varname>insert_clauses</varname>
  /* +CLUSTERED */
  SELECT <varname>remainder_of_query</varname>;</ph>

<ph rev="2.12.0 IMPALA-4168">INSERT -- +CLUSTERED
  <varname>insert_clauses</varname>
  SELECT <varname>remainder_of_query</varname>;

INSERT /* +CLUSTERED */
  <varname>insert_clauses</varname>
  SELECT <varname>remainder_of_query</varname>;

UPSERT -- +CLUSTERED
  <varname>upsert_clauses</varname>
  SELECT <varname>remainder_of_query</varname>;

UPSERT /* +CLUSTERED */
  <varname>upsert_clauses</varname>
  SELECT <varname>remainder_of_query</varname>;</ph>

CREATE /* +SHUFFLE|NOSHUFFLE */
  <varname>table_clauses</varname>
  AS SELECT <varname>remainder_of_query</varname>;

CREATE -- +SHUFFLE|NOSHUFFLE
  <varname>table_clauses</varname>
  AS SELECT <varname>remainder_of_query</varname>;

CREATE /* +CLUSTER|NOCLUSTER */
  <varname>table_clauses</varname>
  AS SELECT <varname>remainder_of_query</varname>;

CREATE -- +CLUSTER|NOCLUSTER
  <varname>table_clauses</varname>
  AS SELECT <varname>remainder_of_query</varname>;<commit_msg>IMPALA-7198: [DOCS] Corrected misspelled hints<commit_after><?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
-->
<!DOCTYPE concept PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
<concept id="hints">

  <title>Optimizer Hints</title>

  <titlealts audience="PDF">

    <navtitle>Optimizer Hints</navtitle>

  </titlealts>

  <prolog>
    <metadata>
      <data name="Category" value="Impala"/>
      <data name="Category" value="SQL"/>
      <data name="Category" value="Querying"/>
      <data name="Category" value="Performance"/>
      <data name="Category" value="Troubleshooting"/>
      <data name="Category" value="Developers"/>
      <data name="Category" value="Data Analysts"/>
    </metadata>
  </prolog>

  <conbody>

    <p>
      <indexterm audience="hidden">hints</indexterm>
      The Impala SQL supports query hints, for fine-tuning the inner workings of queries.
      Specify hints as a temporary workaround for expensive queries, where missing statistics or
      other factors cause inefficient performance.
    </p>

    <p>
      Hints are most often used for the resource-intensive Impala queries, such as:
    </p>

    <ul>
      <li>
        Join queries involving large tables, where intermediate result sets are transmitted
        across the network to evaluate the join conditions.
      </li>

      <li>
        Inserting into partitioned Parquet tables, where many memory buffers could be allocated
        on each host to hold intermediate results for each partition.
      </li>
    </ul>

    <p conref="../shared/impala_common.xml#common/syntax_blurb"/>

    <p rev="2.0.0">
      In <keyword keyref="impala20_full"/> and higher, you can specify the hints inside comments
      that use either the <codeph>/* */</codeph> or <codeph>--</codeph> notation. Specify a
      <codeph>+</codeph> symbol immediately before the hint name. Recently added hints are only
      available using the <codeph>/* */</codeph> and <codeph>--</codeph> notation. For clarity,
      the <codeph>/* */</codeph> and <codeph>--</codeph> styles are used in the syntax and
      examples throughout this section. With the <codeph>/* */</codeph> or <codeph>--</codeph>
      notation for hints, specify a <codeph>+</codeph> symbol immediately before the first hint
      name. Multiple hints can be specified separated by commas, for example <codeph>/*
      +clustered,shuffle */</codeph>
    </p>

<codeblock rev="2.0.0">SELECT STRAIGHT_JOIN <varname>select_list</varname> FROM
<varname>join_left_hand_table</varname>
  JOIN /* +BROADCAST|SHUFFLE */
<varname>join_right_hand_table</varname>
<varname>remainder_of_query</varname>;

SELECT <varname>select_list</varname> FROM
<varname>join_left_hand_table</varname>
  JOIN -- +BROADCAST|SHUFFLE
<varname>join_right_hand_table</varname>
<varname>remainder_of_query</varname>;

INSERT <varname>insert_clauses</varname>
  /* +SHUFFLE|NOSHUFFLE */
  SELECT <varname>remainder_of_query</varname>;

INSERT <varname>insert_clauses</varname>
  -- +SHUFFLE|NOSHUFFLE
  SELECT <varname>remainder_of_query</varname>;

<ph rev="2.12.0 IMPALA-4168">
INSERT /* +SHUFFLE|NOSHUFFLE */
  <varname>insert_clauses</varname>
  SELECT <varname>remainder_of_query</varname>;</ph>

<ph rev="2.12.0 IMPALA-4168">
INSERT -- +SHUFFLE|NOSHUFFLE
  <varname>insert_clauses</varname>
  SELECT <varname>remainder_of_query</varname>;</ph>

<ph rev="2.12.0 IMPALA-4168">
UPSERT /* +SHUFFLE|NOSHUFFLE */
  <varname>upsert_clauses</varname>
  SELECT <varname>remainder_of_query</varname>;</ph>

<ph rev="2.12.0 IMPALA-4168">
UPSERT -- +SHUFFLE|NOSHUFFLE
  <varname>upsert_clauses</varname>
  SELECT <varname>remainder_of_query</varname>;</ph>

<ph rev="IMPALA-2924">SELECT <varname>select_list</varname> FROM
<varname>table_ref</varname>
  /* +{SCHEDULE_CACHE_LOCAL | SCHEDULE_DISK_LOCAL | SCHEDULE_REMOTE}
    [,RANDOM_REPLICA] */
<varname>remainder_of_query</varname>;</ph>

<ph rev="IMPALA-2522 2.8.0">INSERT <varname>insert_clauses</varname>
  -- +CLUSTERED
  SELECT <varname>remainder_of_query</varname>;

INSERT <varname>insert_clauses</varname>
  /* +CLUSTERED */
  SELECT <varname>remainder_of_query</varname>;</ph>

<ph rev="2.12.0 IMPALA-4168">INSERT -- +CLUSTERED
  <varname>insert_clauses</varname>
  SELECT <varname>remainder_of_query</varname>;

INSERT /* +CLUSTERED */
  <varname>insert_clauses</varname>
  SELECT <varname>remainder_of_query</varname>;

UPSERT -- +CLUSTERED
  <varname>upsert_clauses</varname>
  SELECT <varname>remainder_of_query</varname>;

UPSERT /* +CLUSTERED */
  <varname>upsert_clauses</varname>
  SELECT <varname>remainder_of_query</varname>;</ph>

CREATE /* +SHUFFLE|NOSHUFFLE */
  <varname>table_clauses</varname>
  AS SELECT <varname>remainder_of_query</varname>;

CREATE -- +SHUFFLE|NOSHUFFLE
  <varname>table_clauses</varname>
  AS SELECT <varname>remainder_of_query</varname>;

CREATE /* +CLUSTERED|NOCLUSTERED */
  <varname>table_clauses</varname>
  AS SELECT <varname>remainder_of_query</varname>;

CREATE -- +CLUSTERED|NOCLUSTERED
  <varname>table_clauses</varname>
  AS SELECT <varname>remainder_of_query</varname>;
{'fraction_non_alphanumeric': 0.12818532818532818, 'fraction_numerical': 0.011668811668811669, 'mean_word_length': 4.41635687732342, 'pattern_counts': {'":': 0, '<': 325, '<?xml version=': 2, '>': 325, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5741273', 'n_tokens_mistral': 4161, 'n_tokens_neox': 3954, 'n_words': 963}