MCPcopy Create free account
hub / github.com/PostHog/duckgres / TestExplain

Function TestExplain

tests/integration/edge_cases_test.go:741–839  ·  view source on GitHub ↗

TestExplain tests EXPLAIN output.

(t *testing.T)

Source from the content-addressed store, hash-verified

739
740// TestExplain tests EXPLAIN output.
741func TestExplain(t *testing.T) {
742 t.Run("explain_select", func(t *testing.T) {
743 conn := openDuckgresConn(t)
744 defer func() { _ = conn.Close() }()
745
746 rows, err := conn.Query("EXPLAIN SELECT * FROM generate_series(1, 10)")
747 if err != nil {
748 t.Fatalf("EXPLAIN failed: %v", err)
749 }
750 defer func() { _ = rows.Close() }()
751
752 count := 0
753 for rows.Next() {
754 count++
755 }
756 if err := rows.Err(); err != nil {
757 t.Fatalf("Row iteration failed: %v", err)
758 }
759 if count == 0 {
760 t.Error("EXPLAIN returned no rows")
761 }
762 })
763
764 t.Run("explain_analyze", func(t *testing.T) {
765 conn := openDuckgresConn(t)
766 defer func() { _ = conn.Close() }()
767
768 rows, err := conn.Query("EXPLAIN ANALYZE SELECT * FROM generate_series(1, 10)")
769 if err != nil {
770 t.Fatalf("EXPLAIN ANALYZE failed: %v", err)
771 }
772 defer func() { _ = rows.Close() }()
773
774 count := 0
775 for rows.Next() {
776 count++
777 }
778 if err := rows.Err(); err != nil {
779 t.Fatalf("Row iteration failed: %v", err)
780 }
781 if count == 0 {
782 t.Error("EXPLAIN ANALYZE returned no rows")
783 }
784 })
785
786 t.Run("explain_insert", func(t *testing.T) {
787 conn := openDuckgresConn(t)
788 defer func() { _ = conn.Close() }()
789
790 mustExec(t, conn, "CREATE TABLE explain_insert_test (id INTEGER, val TEXT)")
791
792 rows, err := conn.Query("EXPLAIN INSERT INTO explain_insert_test VALUES (1, 'test')")
793 if err != nil {
794 t.Fatalf("EXPLAIN INSERT failed: %v", err)
795 }
796 defer func() { _ = rows.Close() }()
797
798 count := 0

Callers

nothing calls this directly

Calls 9

openDuckgresConnFunction · 0.85
mustExecFunction · 0.85
RunMethod · 0.65
CloseMethod · 0.65
QueryMethod · 0.65
NextMethod · 0.65
ErrMethod · 0.65
ExecMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected