Uploaded image for project: 'Hive'
  1. Hive
  2. HIVE-26184

COLLECT_SET with GROUP BY is very slow when some keys are highly skewed

    XMLWordPrintableJSON

Details

    Description

      I observed some reducers spend 98% of CPU time in invoking `java.util.HashMap#clear`.

      Looking the detail, I found COLLECT_SET reuses a LinkedHashSet and its `clear` can be quite heavy when a relation has a small number of highly skewed keys.

       

      To reproduce the issue, first, we will create rows with a skewed key.

      INSERT INTO test_collect_set
      SELECT '00000000-0000-0000-0000-000000000000' AS key, CAST(UUID() AS VARCHAR) AS value
      FROM table_with_many_rows
      LIMIT 100000;

      Then, we will create many non-skewed rows.

      INSERT INTO test_collect_set
      SELECT UUID() AS key, UUID() AS value
      FROM table_with_many_rows
      LIMIT 5000000;

      We can observe the issue when we aggregate values by `key`.

      SELECT key, COLLECT_SET(value) FROM group_by_skew GROUP BY key

      Attachments

        Issue Links

          Activity

            People

              okumin Shohei Okumiya
              okumin Shohei Okumiya
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 1.5h
                  1.5h