@@ -0,0 +1,2960 @@
+/*%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *     http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage io.trino.plugin.mysql;%0A%0Aimport com.google.common.collect.ImmutableList;%0Aimport com.google.common.collect.ImmutableMap;%0Aimport io.trino.plugin.jdbc.BaseAutomaticJoinPushdownTest;%0Aimport io.trino.testing.MaterializedRow;%0Aimport io.trino.testing.QueryRunner;%0Aimport org.jdbi.v3.core.Handle;%0Aimport org.jdbi.v3.core.Jdbi;%0Aimport org.testng.SkipException;%0A%0Aimport static io.trino.plugin.mysql.MySqlQueryRunner.createMySqlQueryRunner;%0Aimport static java.lang.String.format;%0A%0Apublic class TestMySqlAutomaticJoinPushdown%0A        extends BaseAutomaticJoinPushdownTest%0A%7B%0A    private TestingMySqlServer mySqlServer;%0A%0A    @Override%0A    protected QueryRunner createQueryRunner()%0A            throws Exception%0A    %7B%0A        // Using MySQL 8.0.15 because test is sensitive to quality of NDV estimation and 5.5.46 we use%0A        // in other places does very poor job; for 10000 row table with 1000 distinct keys it estimates NDV at ~2500%0A        mySqlServer = closeAfterClass(new TestingMySqlServer(%22mysql:8.0.15%22, false));%0A%0A        return createMySqlQueryRunner(%0A                mySqlServer,%0A                ImmutableMap.of(),%0A                ImmutableMap.%3CString, String%3Ebuilder()%0A                        .put(%22metadata.cache-ttl%22, %220m%22)%0A                        .put(%22metadata.cache-missing%22, %22false%22)%0A                        .buildOrThrow(),%0A                ImmutableList.of());%0A    %7D%0A%0A    @Override%0A    public void testJoinPushdownWithEmptyStatsInitially()%0A    %7B%0A        throw new SkipException(%22MySQL statistics are automatically collected%22);%0A    %7D%0A%0A    @Override%0A    protected void gatherStats(String tableName)%0A    %7B%0A        for (MaterializedRow row : computeActual(%22SHOW COLUMNS FROM %22 + tableName)) %7B%0A            String columnName = (String) row.getField(0);%0A            String columnType = (String) row.getField(1);%0A            if (columnType.startsWith(%22varchar%22)) %7B%0A                // varchar index require length%0A                continue;%0A            %7D%0A            onRemoteDatabase(format(%22CREATE INDEX %5C%22%252$s%5C%22 ON %251$s (%5C%22%252$s%5C%22)%22, tableName, columnName).replace(%22%5C%22%22, %22%60%22));%0A        %7D%0A        onRemoteDatabase(%22ANALYZE TABLE %22 + tableName.replace(%22%5C%22%22, %22%60%22));%0A    %7D%0A%0A    protected void onRemoteDatabase(String sql)%0A    %7B%0A        try (Handle handle = Jdbi.open(() -%3E mySqlServer.createConnection())) %7B%0A            handle.execute(%22USE tpch%22);%0A            handle.execute(sql);%0A        %7D%0A    %7D%0A%7D%0A

Add MySQL automatic Join pushdown test