示例#1
0
 def test_possible_indexes(self):
     column_0_table_1 = Column("Col0")
     table_1 = Table("Table1")
     table_1.add_column(column_0_table_1)
     query = Query(
         17,
         """SELECT * FROM Table0 as t0, Table1 as t1 WHERE t0.Col0 = 1"
             AND t0.Col1 = 2 AND t0.Col2 = 3 AND t1.Col0 = 17;""",
         [self.column_0, self.column_1, self.column_2, column_0_table_1],
     )
     indexes = self.algo._possible_indexes(query)
     self.assertIn(Index([column_0_table_1]), indexes)
     self.assertIn(Index([self.column_0]), indexes)
     self.assertIn(Index([self.column_1]), indexes)
     self.assertIn(Index([self.column_2]), indexes)
     self.assertIn(Index([self.column_0, self.column_1]), indexes)
     self.assertIn(Index([self.column_0, self.column_2]), indexes)
     self.assertIn(Index([self.column_1, self.column_0]), indexes)
     self.assertIn(Index([self.column_1, self.column_2]), indexes)
     self.assertIn(Index([self.column_2, self.column_0]), indexes)
     self.assertIn(Index([self.column_2, self.column_1]), indexes)
     self.assertIn(Index([self.column_0, self.column_1, self.column_2]),
                   indexes)
     self.assertIn(Index([self.column_0, self.column_2, self.column_1]),
                   indexes)
     self.assertIn(Index([self.column_1, self.column_0, self.column_2]),
                   indexes)
     self.assertIn(Index([self.column_1, self.column_2, self.column_0]),
                   indexes)
     self.assertIn(Index([self.column_2, self.column_0, self.column_1]),
                   indexes)
     self.assertIn(Index([self.column_2, self.column_1, self.column_0]),
                   indexes)
    def test_workload_indexable_columns(self):
        table = Table("TableA")
        column_1 = Column(name="ColA")
        column_2 = Column(name="ColB")
        column_3 = Column(name="ColC")
        table.add_column(column_1)
        table.add_column(column_2)
        table.add_column(column_3)

        query_1 = Query(
            17,
            "SELECT * FROM TableA WHERE ColA = 4 AND ColB = 5;",
            columns=[column_1, column_2],
        )
        query_2 = Query(
            18,
            "SELECT * FROM TableA WHERE ColA = 3 AND ColC = 2;",
            columns=[column_1, column_3],
        )
        database_name = "test_DB"

        workload = Workload([query_1, query_2], database_name)
        indexable_columns = workload.indexable_columns()
        self.assertEqual(sorted(indexable_columns),
                         sorted([column_1, column_2, column_3]))
示例#3
0
    def test_appendable_by_other_table(self):
        column = Column("ColZ")
        table = Table("TableZ")
        table.add_column(column)
        index_on_other_table = Index([column])

        index_0 = Index([self.column_0])

        self.assertFalse(index_0.appendable_by(index_on_other_table))
示例#4
0
    def test_table_add_column(self):
        table = Table("TableA")
        column_1 = Column("ColA")
        table.add_column(column_1)

        self.assertEqual(table.columns, [column_1])
        self.assertEqual(column_1.table, table)

        column_2 = Column("ColB")
        column_3 = Column("ColC")
        table.add_columns([column_2, column_3])

        self.assertEqual(table.columns, [column_1, column_2, column_3])
        self.assertEqual(column_2.table, table)
        self.assertEqual(column_3.table, table)
    def test_runtime_data_logging(self):
        db = PostgresDatabaseConnector(self.db_name, "postgres")

        query = Query(17, "SELECT count(*) FROM nation;")
        db.get_cost(query)
        self.assertEqual(db.cost_estimations, 1)
        self.assertGreater(db.cost_estimation_duration, 0)

        column_n_name = Column("n_name")
        nation_table = Table("nation")
        nation_table.add_column(column_n_name)
        index = Index([column_n_name])
        index_oid = db.simulate_index(index)[0]
        self.assertGreater(db.index_simulation_duration, 0)
        self.assertEqual(db.simulated_indexes, 1)

        previou_simulation_duration = db.index_simulation_duration
        db.drop_simulated_index(index_oid)
        self.assertGreater(db.index_simulation_duration, previou_simulation_duration)
示例#6
0
    def test_column_eq(self):
        table_1 = Table("TableA")
        table_2 = Table("TableA")
        column_1 = Column(name="ColA")
        column_2 = Column(name="ColA")
        column_3 = Column(name="ColB")

        # Column name equal but table (for both) is None
        with self.assertRaises(AssertionError):
            column_1 == column_2

        # Column name different but table (for both) is None
        with self.assertRaises(AssertionError):
            column_1 == column_3

        table_1.add_column(column_1)

        # Column name equal but table of column_2 is None
        with self.assertRaises(AssertionError):
            column_1 == column_2

        # Column name equal but table of column_2 is None
        with self.assertRaises(AssertionError):
            column_2 == column_1

        table_2.add_column(column_2)
        self.assertTrue(column_1 == column_2)

        table_2.add_column(column_3)
        self.assertFalse(column_1 == column_3)

        # Check comparing object of different class
        self.assertFalse(column_1 == int(3))
示例#7
0
 def test_column_repr(self):
     column = Column(name="ColA")
     table = Table("TableA")
     table.add_column(column)
     self.assertEqual(repr(column), "C tablea.cola")
示例#8
0
    def test_column_added_to_table(self):
        column = Column(name="ColA")
        table = Table("TableA")
        table.add_column(column)

        self.assertEqual(column.table, table)
示例#9
0
    def test_table_eq_with_columns(self):
        table_1 = Table("TableA")
        table_1.add_column(Column("ColA"))
        table_2 = Table("TableA")
        self.assertFalse(table_1 == table_2)

        table_2.add_column(Column("ColA"))
        self.assertTrue(table_1 == table_2)

        table_1.add_column(Column("ColB"))
        table_1.add_column(Column("ColC"))
        self.assertFalse(table_1 == table_2)

        table_2.add_column(Column("ColB"))
        table_2.add_column(Column("ColC"))
        self.assertTrue(table_1 == table_2)

        # Testing same column names, but different order
        table_3 = Table("TableA")
        table_3.add_column(Column("ColC"))
        table_3.add_column(Column("ColB"))
        table_3.add_column(Column("ColA"))
        self.assertFalse(table_1 == table_3)