MCPcopy Create free account
hub / github.com/LadybugDB/ladybug / TEST_F

Function TEST_F

test/api/drop_index_test.cpp:45–76  ·  view source on GitHub ↗

Drop the default hash PK index after inserting data; the index should disappear from storage while rows remain queryable through the PK-scan fallback.

Source from the content-addressed store, hash-verified

43// Drop the default hash PK index after inserting data; the index should disappear from storage
44// while rows remain queryable through the PK-scan fallback.
45TEST_F(DropIndexTest, DropDefaultHashIndex) {
46 auto& con = *conn;
47 assertQuery(*con.query("CREATE NODE TABLE diperson(ID INT64, name STRING, PRIMARY KEY(ID))"));
48 const auto& pkIndexName = PK_INDEX_NAME;
49 // The default hash PK index should be present.
50 ASSERT_TRUE(getNodeTable("diperson").tryGetPKIndex() != nullptr);
51
52 assertQuery(*con.query("CREATE (:diperson {ID: 1, name: 'Alice'})"));
53 assertQuery(*con.query("CREATE (:diperson {ID: 2, name: 'Bob'})"));
54 assertQuery(*con.query("CREATE (:diperson {ID: 3, name: 'Carol'})"));
55
56 auto dropResult = con.query(std::format("DROP INDEX diperson.{}", pkIndexName));
57 assertQuery(*dropResult);
58 EXPECT_EQ(TestHelper::convertResultToString(*dropResult),
59 std::vector<std::string>{std::format("Index {} has been dropped.", pkIndexName)});
60
61 // Index is gone from both storage and catalog.
62 EXPECT_EQ(getNodeTable("diperson").tryGetPKIndex(), nullptr);
63 auto* catalog = database->getCatalog();
64 auto* entry = catalog->getTableCatalogEntry(&DUMMY_CHECKPOINT_TRANSACTION, "diperson")
65 ->ptrCast<NodeTableCatalogEntry>();
66 EXPECT_FALSE(
67 catalog->containsIndex(&DUMMY_CHECKPOINT_TRANSACTION, entry->getTableID(), pkIndexName));
68
69 // Rows are still queryable via the PK-scan fallback (no index).
70 auto res = con.query("MATCH (p:diperson) WHERE p.ID = 2 RETURN p.name");
71 assertQuery(*res);
72 EXPECT_EQ(TestHelper::convertResultToString(*res), std::vector<std::string>{"Bob"});
73 auto countRes = con.query("MATCH (p:diperson) RETURN COUNT(*)");
74 assertQuery(*countRes);
75 EXPECT_EQ(TestHelper::convertResultToString(*countRes), std::vector<std::string>{"3"});
76}
77
78// Dropping a non-existent index without IF EXISTS must error.
79TEST_F(DropIndexTest, DropNonExistentIndexThrows) {

Callers

nothing calls this directly

Calls 9

assertQueryFunction · 0.85
tryGetPKIndexMethod · 0.80
getCatalogMethod · 0.80
getTableCatalogEntryMethod · 0.80
containsIndexMethod · 0.80
queryMethod · 0.45
isSuccessMethod · 0.45
resetMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected