title: Does Spark benefit from `sortBy` in persistent table?
body: <p>Spark v2.4 no Hive</p>
  
  <p>Spark benefit from <code>bucketBy</code> in a way that it knows the DataFrame has the correct partitioning. What about <code>sortBy</code>?</p>
  
  <pre><code>spark.range(100, numPartitions=1).write.bucketBy(3, 'id').sortBy('id').saveAsTable('df')
  
  # No need to `repartition`.
  spark.table('df').repartition(3, 'id').explain()
  # == Physical Plan ==
  # *(1) FileScan parquet default.df2[id#33620L] Batched: true, Format: Parquet, Location: InMemoryFileIndex[df], PartitionFilters: [], PushedFilters: [], ReadSchema: struct&lt;id:bigint&gt;, # SelectedBucketsCount: 3 out of 3
  
  # Still need to `sortWithinPartitions`.
  spark.table('df').sortWithinPartitions('id').explain()
  # == Physical Plan ==
  # *(1) Sort [id#33620L ASC NULLS FIRST], false, 0
  # +- *(1) FileScan parquet default.df2[id#33620L] Batched: true, Format: Parquet, Location: InMemoryFileIndex[df], PartitionFilters: [], PushedFilters: [], ReadSchema: struct&lt;id:bigint&gt;, SelectedBucketsCount: 3 out of 3
  </code></pre>
  
  <p>So additional <code>repartition</code> is omitted. However, <code>sortWithinPartitions</code> is not. Is <code>sortBy</code> useful? Can we use <code>sortBy</code> to speed up table joining at all?</p>