Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert ANALYZE statements #691

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions server/ast/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,21 @@ func nodeAnalyze(node *tree.Analyze) (vitess.Statement, error) {
if node == nil {
return nil, nil
}
// This functions a bit differently compared to the GMS version, so it's unsupported for now
return nil, fmt.Errorf("ANALYZE is not yet supported")

objectName, ok := node.Table.(*tree.UnresolvedObjectName)
if !ok {
return nil, fmt.Errorf("unsupported table type in Analyze node: %T", node.Table)
}

if objectName.Object() == "" && objectName.Schema() == "" && objectName.Catalog() == "" {
return nil, fmt.Errorf("ANALYZE all tables not supported; must specify a table")
}

return &vitess.Analyze{Tables: []vitess.TableName{
{
Name: vitess.NewTableIdent(objectName.Object()),
SchemaQualifier: vitess.NewTableIdent(objectName.Schema()),
DbQualifier: vitess.NewTableIdent(objectName.Catalog()),
},
}}, nil
}
7 changes: 3 additions & 4 deletions testing/bats/dataloading/french-towns-communes-francaises.sql
Original file line number Diff line number Diff line change
Expand Up @@ -36921,7 +36921,6 @@ SELECT pg_catalog.setval('towns_id_seq', 36684, true);

COMMIT;

-- TODO: ANALYZE is not supported by Doltgres yet
-- ANALYZE Regions;
-- ANALYZE Departments;
-- ANALYZE Towns;
ANALYZE Regions;
ANALYZE Departments;
ANALYZE Towns;
6 changes: 3 additions & 3 deletions testing/generation/command_docs/output/analyze_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestAnalyze(t *testing.T) {
Unimplemented("ANALYZE ( VERBOSE true , SKIP_LOCKED true )"),
Unimplemented("ANALYZE ( SKIP_LOCKED , SKIP_LOCKED true )"),
Unimplemented("ANALYZE ( SKIP_LOCKED true , SKIP_LOCKED true )"),
Parses("ANALYZE table_name"),
Converts("ANALYZE table_name"),
Unimplemented("ANALYZE ( VERBOSE ) table_name"),
Unimplemented("ANALYZE ( VERBOSE true ) table_name"),
Unimplemented("ANALYZE ( SKIP_LOCKED ) table_name"),
Expand Down Expand Up @@ -292,8 +292,8 @@ func TestAnalyze(t *testing.T) {
Unimplemented("ANALYZE ( SKIP_LOCKED , SKIP_LOCKED true ) table_name ( column_name , column_name ) , table_name ( column_name , column_name )"),
Unimplemented("ANALYZE ( SKIP_LOCKED true , SKIP_LOCKED true ) table_name ( column_name , column_name ) , table_name ( column_name , column_name )"),
Unimplemented("ANALYZE"),
Parses("ANALYZE VERBOSE"),
Parses("ANALYZE table_name"),
Converts("ANALYZE VERBOSE"),
Converts("ANALYZE table_name"),
Unimplemented("ANALYZE VERBOSE table_name"),
Unimplemented("ANALYZE table_name ( column_name )"),
Unimplemented("ANALYZE VERBOSE table_name ( column_name )"),
Expand Down
59 changes: 59 additions & 0 deletions testing/go/stats_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright 2024 Dolthub, Inc.
//
// Licensed 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.

package _go

import (
"testing"

"github.com/dolthub/go-mysql-server/sql"
)

func TestStats(t *testing.T) {
RunScripts(t, StatsTests)
}

var StatsTests = []ScriptTest{
{
Name: "ANALYZE statement",
SetUpScript: []string{
"CREATE TABLE t (pk int primary key);",
},
Assertions: []ScriptTestAssertion{
{
// TODO: Postgres will analyze ALL tables if ANALYZE is invoked without a table name, but
// our postgres parser and our analysis code doesn't support this yet.
Skip: true,
Query: "ANALYZE;",
Expected: []sql.Row{},
},
{
Query: "ANALYZE t;",
Expected: []sql.Row{},
},
{
Query: "ANALYZE public.t;",
Expected: []sql.Row{},
},
{
Query: "ANALYZE postgres.public.t;",
Expected: []sql.Row{},
},
{
Query: "ANALYZE doesnotexists.public.t;",
ExpectedErr: "ERROR: database not found: doesnotexists (errno 1049) (sqlstate HY000) (SQLSTATE XX000)",
},
},
},
}