Partage de technologie

Résumé de l'utilisation des indices dans Spark

2024-07-12

한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina

Dans Spark SQL, les utilisateurs peuvent utiliser l'indice de jointure pour suggérer le type de jointure Spark à utiliser. Avant Spark 3.0, seuls les conseils de jointure tels que BROADCAST étaient pris en charge. À partir de Spark 3.0, trois astuces de jointure, MERGE, SHUFFLE_HASH et SHUFFLE_REPLICATE_NL, ont été ajoutées. La priorité est BROADCAST > MERGE > SHUFFLE_HASH > SHUFFLE_REPLICATE_NL. Si BROADCAST ou SHUFFLE_HASH est ajouté des deux côtés de la jointure, Spark choisira le côté à construire en fonction du joinType et de la taille des deux côtés.

  1. -- Join Hints for broadcast join
  2. SELECT /*+ BROADCAST(t1) */ * FROM t1 INNER JOIN t2 ON t1.key = t2.key;
  3. SELECT /*+ BROADCASTJOIN (t1) */ * FROM t1 left JOIN t2 ON t1.key = t2.key;
  4. SELECT /*+ MAPJOIN(t2) */ * FROM t1 right JOIN t2 ON t1.key = t2.key;
  5. -- Join Hints for shuffle sort merge join
  6. SELECT /*+ SHUFFLE_MERGE(t1) */ * FROM t1 INNER JOIN t2 ON t1.key = t2.key;
  7. SELECT /*+ MERGEJOIN(t2) */ * FROM t1 INNER JOIN t2 ON t1.key = t2.key;
  8. SELECT /*+ MERGE(t1) */ * FROM t1 INNER JOIN t2 ON t1.key = t2.key;
  9. -- Join Hints for shuffle hash join
  10. SELECT /*+ SHUFFLE_HASH(t1) */ * FROM t1 INNER JOIN t2 ON t1.key = t2.key;
  11. -- Join Hints for shuffle-and-replicate nested loop join
  12. SELECT /*+ SHUFFLE_REPLICATE_NL(t1) */ * FROM t1 INNER JOIN t2 ON t1.key = t2.key;
  13. -- When different join strategy hints are specified on both sides of a join, Spark
  14. -- prioritizes the BROADCAST hint over the MERGE hint over the SHUFFLE_HASH hint
  15. -- over the SHUFFLE_REPLICATE_NL hint.
  16. -- Spark will issue Warning in the following example
  17. -- org.apache.spark.sql.catalyst.analysis.HintErrorLogger: Hint (strategy=merge)
  18. -- is overridden by another hint and will not take effect.
  19. SELECT /*+ BROADCAST(t1), MERGE(t1, t2) */ * FROM t1 INNER JOIN t2 ON t1.key = t2.key;

Relation d'utilisation dans l'indice Spark : https://blog.51cto.com/u_15435003/5296344