diff --git a/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/rel/metadata/glogue/GlogueBasicCardinalityEstimationImpl.java b/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/rel/metadata/glogue/GlogueBasicCardinalityEstimationImpl.java index ee24b7aa3a16..702d0a1fcdfd 100644 --- a/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/rel/metadata/glogue/GlogueBasicCardinalityEstimationImpl.java +++ b/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/rel/metadata/glogue/GlogueBasicCardinalityEstimationImpl.java @@ -161,7 +161,8 @@ public Double getCardinality(Pattern queryPattern) { return this.patternCardinality.get(pattern); } } - return 0.0; + // if not exist, return 1.0 + return 1.0; } @Override diff --git a/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/rel/metadata/schema/GlogueSchema.java b/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/rel/metadata/schema/GlogueSchema.java index 3ec2d1c3af7e..7333418806ab 100644 --- a/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/rel/metadata/schema/GlogueSchema.java +++ b/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/rel/metadata/schema/GlogueSchema.java @@ -21,6 +21,8 @@ import org.jgrapht.Graph; import org.jgrapht.graph.DirectedPseudograph; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.HashMap; import java.util.List; @@ -30,6 +32,7 @@ public class GlogueSchema { private Graph schemaGraph; private HashMap vertexTypeCardinality; private HashMap edgeTypeCardinality; + private static Logger logger = LoggerFactory.getLogger(GlogueSchema.class); public GlogueSchema( GraphSchema graphSchema, @@ -69,6 +72,7 @@ public GlogueSchema(GraphSchema graphSchema) { edgeTypeCardinality.put(edgeType, 1.0); } } + logger.debug("GlogueSchema created with default cardinality 1.0: {}", this); } public GlogueSchema(GraphSchema graphSchema, GraphStatistics statistics) { @@ -108,6 +112,7 @@ public GlogueSchema(GraphSchema graphSchema, GraphStatistics statistics) { } } } + logger.debug("GlogueSchema created with statistics: {}", this); } public static GlogueSchema fromMeta(IrMetaStats irMeta) { @@ -139,7 +144,9 @@ public List getEdgeTypes(Integer source, Integer target) { public Double getVertexTypeCardinality(Integer vertexType) { Double cardinality = this.vertexTypeCardinality.get(vertexType); if (cardinality == null) { - return 0.0; + logger.debug( + "Vertex type {} not found in schema, assuming cardinality 1.0", vertexType); + return 1.0; } else { return cardinality; } @@ -148,7 +155,8 @@ public Double getVertexTypeCardinality(Integer vertexType) { public Double getEdgeTypeCardinality(EdgeTypeId edgeType) { Double cardinality = this.edgeTypeCardinality.get(edgeType); if (cardinality == null) { - return 0.0; + logger.debug("Edge type {} not found in schema, assuming cardinality 1.0", edgeType); + return 1.0; } else { return cardinality; } diff --git a/interactive_engine/compiler/src/test/java/com/alibaba/graphscope/common/ir/rel/metadata/GLogueSchemaTest.java b/interactive_engine/compiler/src/test/java/com/alibaba/graphscope/common/ir/rel/metadata/GLogueSchemaTest.java index 86b27ee9459c..c0f0fa84d34c 100644 --- a/interactive_engine/compiler/src/test/java/com/alibaba/graphscope/common/ir/rel/metadata/GLogueSchemaTest.java +++ b/interactive_engine/compiler/src/test/java/com/alibaba/graphscope/common/ir/rel/metadata/GLogueSchemaTest.java @@ -43,10 +43,12 @@ public void glogue_schema_test() { // test get type cardinality Assert.assertEquals(4.0, g.getVertexTypeCardinality(person), delta); Assert.assertEquals(2.0, g.getVertexTypeCardinality(software), delta); - Assert.assertEquals(0.0, g.getVertexTypeCardinality(2), delta); Assert.assertEquals(2.0, g.getEdgeTypeCardinality(knows), delta); Assert.assertEquals(4.0, g.getEdgeTypeCardinality(creates), delta); - Assert.assertEquals(0.0, g.getEdgeTypeCardinality(new EdgeTypeId(0, 0, 2)), delta); + + // when query a type that is not in the schema, return 1.0 + Assert.assertEquals(1.0, g.getVertexTypeCardinality(2), delta); + Assert.assertEquals(1.0, g.getEdgeTypeCardinality(new EdgeTypeId(0, 0, 2)), delta); // test get types Assert.assertEquals(2, g.getAdjEdgeTypes(person).size()); diff --git a/interactive_engine/compiler/src/test/java/com/alibaba/graphscope/common/ir/rel/metadata/GlogueTest.java b/interactive_engine/compiler/src/test/java/com/alibaba/graphscope/common/ir/rel/metadata/GlogueTest.java index 9a589b354152..2949c44e40ec 100644 --- a/interactive_engine/compiler/src/test/java/com/alibaba/graphscope/common/ir/rel/metadata/GlogueTest.java +++ b/interactive_engine/compiler/src/test/java/com/alibaba/graphscope/common/ir/rel/metadata/GlogueTest.java @@ -77,6 +77,7 @@ public void glogue_get_row_count_test() { Assert.assertEquals(1.0d, count2, delta); // pattern3: person2 <- person1 <- software (not exist) + // Note the non-exist pattern will return a cardinality of 1.0 Pattern pattern3 = new Pattern(); pattern3.addVertex(v0); pattern3.addVertex(v1); @@ -86,7 +87,7 @@ public void glogue_get_row_count_test() { pattern3.reordering(); Double count3 = gl.getRowCount(pattern3); - Assert.assertEquals(0.0d, count3, delta); + Assert.assertEquals(1.0d, count3, delta); } @Test