Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
3.7 kB
1
Indexable
Never
    static void newTest()
    {
        var rand = new Random();
        
        int row_count = 2000;

        Helper.KillAllNB();
        Helper.DeleteAndCreateMSDB("tmp");
        Helper.ReCreateNBDB(3021);

        NBConnect.connectstr = "host=127.0.0.1;port=3021;";
        var connect = new NBMSConnect();

        // ---------------------------INT----------------------
        
        connect.Execute("create table t1(c_int_1 integer, c_int_2 integer );");

        for ( int i = 1; i <= row_count; i += 1 )
        {
            int v = i%100;
            connect.Execute($"insert into t1(c_int_1, c_int_2) values ({v}, {v});");
        }

        connect.Execute("create index i_int_1 on t1 ( c_int_1 );");
        connect.Execute("create index i_int_2 on t1 ( c_int_2 );");

        for (int i = 0; i < 5; i += 1)
        {
            connect.ExcecuteAndCompare($"select * from t1 where c_int_1={rand.Next(0, 100)};").CheckError();
            connect.ExcecuteAndCompare($"select * from t1 where c_int_1<{rand.Next(0, 10)};").CheckError();
            connect.ExcecuteAndCompare($"select * from t1 where c_int_1>{rand.Next(90, 100)};").CheckError();
            connect.ExcecuteAndCompare($"select * from t1 where c_int_1<={rand.Next(0, 10)};").CheckError();
            connect.ExcecuteAndCompare($"select * from t1 where c_int_1>={rand.Next(90, 100)};").CheckError();
        }
        
        // ---------------------------BIGINT----------------------
        
        connect.Execute("create table t2(c_bigint_1 integer, c_bigint_2 integer );");

        for ( int i = 1; i <= row_count; i += 1 )
        {
            int v = i%100;
            connect.Execute($"insert into t2(c_bigint_1, c_bigint_2) values ({v}, {v});");
        }

        connect.Execute("create index i_bigint_1 on t2 ( c_bigint_1 );");
        connect.Execute("create index i_bigint_2 on t2 ( c_bigint_2 );");

        for (int i = 0; i < 5; i += 1)
        {
            connect.ExcecuteAndCompare($"select * from t2 where c_bigint_1={rand.Next(0, 100)};").CheckError();
            connect.ExcecuteAndCompare($"select * from t2 where c_bigint_1<{rand.Next(0, 10)};").CheckError();
            connect.ExcecuteAndCompare($"select * from t2 where c_bigint_1>{rand.Next(90, 100)};").CheckError();
            connect.ExcecuteAndCompare($"select * from t2 where c_bigint_1<={rand.Next(0, 10)};").CheckError();
            connect.ExcecuteAndCompare($"select * from t2 where c_bigint_1>={rand.Next(90, 100)};").CheckError();
        }
        
        // ---------------------------DECIMAL----------------------
        
        connect.Execute("create table t3(c_dec_1 decimal(5,4), c_dec_2 decimal(6,5) );");
        
        for ( int i = 1; i <= row_count; i += 1 )
        {
            double v = i%100 + 0.1234;
            connect.Execute($"insert into t3(c_dec_1, c_dec_2) values ({v}, {v});");
        }
        
        connect.Execute("create index c_dec_1 on t3 ( c_dec_1 );");
        connect.Execute("create index c_dec_2 on t3 ( c_dec_2 );");
        
        for (int i = 0; i < 5; i += 1)
        {
            connect.ExcecuteAndCompare($"select * from t3 where c_dec_1={rand.Next(0, 100) + 0.1234};").CheckError();
            connect.ExcecuteAndCompare($"select * from t3 where c_dec_1<{rand.Next(0, 10) + 0.1234};").CheckError();
            connect.ExcecuteAndCompare($"select * from t3 where c_dec_1>{rand.Next(90, 100) + 0.1234};").CheckError();
            connect.ExcecuteAndCompare($"select * from t3 where c_dec_1>={rand.Next(0, 10) + 0.1234};").CheckError();
            connect.ExcecuteAndCompare($"select * from t3 where c_dec_1<={rand.Next(90, 100) + 0.1234};").CheckError();
        }