Skip to content

Commit cbb6742

Browse files
committed
SQL: moved VTQ items to separate file
1 parent afe64a4 commit cbb6742

File tree

6 files changed

+422
-372
lines changed

6 files changed

+422
-372
lines changed

sql/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ SET (SQL_SOURCE
143143
rpl_gtid.cc rpl_parallel.cc
144144
sql_type.cc sql_type.h
145145
item_windowfunc.cc sql_window.cc
146+
item_vers.cc
146147
sql_cte.cc sql_cte.h
147148
sql_sequence.cc sql_sequence.h ha_sequence.h
148149
${WSREP_SOURCES}

sql/item.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4937,6 +4937,7 @@ class Item_int_with_ref :public Item_int
49374937
#include "item_xmlfunc.h"
49384938
#include "item_jsonfunc.h"
49394939
#include "item_create.h"
4940+
#include "item_vers.h"
49404941
#endif
49414942

49424943
/**

sql/item_timefunc.cc

Lines changed: 0 additions & 257 deletions
Original file line numberDiff line numberDiff line change
@@ -3273,260 +3273,3 @@ bool Item_func_last_day::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date)
32733273
ltime->time_type= MYSQL_TIMESTAMP_DATE;
32743274
return (null_value= 0);
32753275
}
3276-
3277-
Item_func_vtq_ts::Item_func_vtq_ts(
3278-
THD *thd,
3279-
Item* a,
3280-
vtq_field_t _vtq_field,
3281-
handlerton* hton) :
3282-
VTQ_common<Item_datetimefunc>(thd, a, hton),
3283-
vtq_field(_vtq_field)
3284-
{
3285-
decimals= 6;
3286-
null_value= true;
3287-
DBUG_ASSERT(arg_count == 1 && args[0]);
3288-
}
3289-
3290-
Item_func_vtq_ts::Item_func_vtq_ts(
3291-
THD *thd,
3292-
Item* a,
3293-
vtq_field_t _vtq_field) :
3294-
VTQ_common<Item_datetimefunc>(thd, a),
3295-
vtq_field(_vtq_field)
3296-
{
3297-
decimals= 6;
3298-
null_value= true;
3299-
DBUG_ASSERT(arg_count == 1 && args[0]);
3300-
}
3301-
3302-
template <class Item_func_X>
3303-
void
3304-
VTQ_common<Item_func_X>::init_hton()
3305-
{
3306-
if (!hton)
3307-
{
3308-
if (Item_func_X::args[0]->type() == Item::FIELD_ITEM)
3309-
{
3310-
Item_field *f=
3311-
static_cast<Item_field *>(Item_func_X::args[0]);
3312-
DBUG_ASSERT(
3313-
f->field &&
3314-
f->field->table &&
3315-
f->field->table->s &&
3316-
f->field->table->s->db_plugin);
3317-
hton= f->field->table->file->partition_ht();
3318-
DBUG_ASSERT(hton);
3319-
}
3320-
else if (innodb_plugin)
3321-
{
3322-
hton= plugin_hton(plugin_int_to_ref(innodb_plugin));
3323-
DBUG_ASSERT(hton);
3324-
}
3325-
if (hton && !(hton->flags & HTON_SUPPORTS_SYS_VERSIONING))
3326-
{
3327-
my_error(ER_VERS_ENGINE_UNSUPPORTED, MYF(0), Item::name ? Item::name : this->func_name());
3328-
hton= NULL;
3329-
}
3330-
}
3331-
}
3332-
3333-
bool
3334-
Item_func_vtq_ts::get_date(MYSQL_TIME *res, ulonglong fuzzy_date)
3335-
{
3336-
THD *thd= current_thd; // can it differ from constructor's?
3337-
DBUG_ASSERT(thd);
3338-
ulonglong trx_id= args[0]->val_uint();
3339-
if (trx_id == ULONGLONG_MAX)
3340-
{
3341-
null_value= false;
3342-
thd->variables.time_zone->gmt_sec_to_TIME(res, TIMESTAMP_MAX_VALUE);
3343-
return false;
3344-
}
3345-
3346-
init_hton();
3347-
3348-
if (!hton)
3349-
return true;
3350-
3351-
DBUG_ASSERT(hton->vers_query_trx_id);
3352-
null_value= !hton->vers_query_trx_id(thd, res, trx_id, vtq_field);
3353-
3354-
return false;
3355-
}
3356-
3357-
3358-
Item_func_vtq_id::Item_func_vtq_id(
3359-
THD *thd,
3360-
Item* a,
3361-
vtq_field_t _vtq_field,
3362-
bool _backwards) :
3363-
VTQ_common<Item_int_func>(thd, a),
3364-
vtq_field(_vtq_field),
3365-
backwards(_backwards)
3366-
{
3367-
memset(&cached_result, 0, sizeof(cached_result));
3368-
decimals= 0;
3369-
unsigned_flag= 1;
3370-
null_value= true;
3371-
DBUG_ASSERT(arg_count == 1 && args[0]);
3372-
}
3373-
3374-
Item_func_vtq_id::Item_func_vtq_id(
3375-
THD *thd,
3376-
Item* a,
3377-
Item* b,
3378-
vtq_field_t _vtq_field) :
3379-
VTQ_common<Item_int_func>(thd, a, b),
3380-
vtq_field(_vtq_field),
3381-
backwards(false)
3382-
{
3383-
memset(&cached_result, 0, sizeof(cached_result));
3384-
decimals= 0;
3385-
unsigned_flag= 1;
3386-
null_value= true;
3387-
DBUG_ASSERT(arg_count == 2 && args[0] && args[1]);
3388-
}
3389-
3390-
longlong
3391-
Item_func_vtq_id::get_by_trx_id(ulonglong trx_id)
3392-
{
3393-
ulonglong res;
3394-
THD *thd= current_thd; // can it differ from constructor's?
3395-
DBUG_ASSERT(thd);
3396-
3397-
if (trx_id == ULONGLONG_MAX)
3398-
{
3399-
null_value= true;
3400-
return 0;
3401-
}
3402-
3403-
DBUG_ASSERT(hton->vers_query_trx_id);
3404-
null_value= !hton->vers_query_trx_id(thd, &res, trx_id, vtq_field);
3405-
return res;
3406-
}
3407-
3408-
longlong
3409-
Item_func_vtq_id::get_by_commit_ts(MYSQL_TIME &commit_ts, bool backwards)
3410-
{
3411-
THD *thd= current_thd; // can it differ from constructor's?
3412-
DBUG_ASSERT(thd);
3413-
3414-
DBUG_ASSERT(hton->vers_query_commit_ts);
3415-
null_value= !hton->vers_query_commit_ts(thd, &cached_result, commit_ts, VTQ_ALL, backwards);
3416-
if (null_value)
3417-
{
3418-
return 0;
3419-
}
3420-
3421-
switch (vtq_field)
3422-
{
3423-
case VTQ_COMMIT_ID:
3424-
return cached_result.commit_id;
3425-
case VTQ_ISO_LEVEL:
3426-
return cached_result.iso_level;
3427-
case VTQ_TRX_ID:
3428-
return cached_result.trx_id;
3429-
default:
3430-
DBUG_ASSERT(0);
3431-
null_value= true;
3432-
}
3433-
3434-
return 0;
3435-
}
3436-
3437-
longlong
3438-
Item_func_vtq_id::val_int()
3439-
{
3440-
init_hton();
3441-
3442-
if (!hton)
3443-
{
3444-
null_value= true;
3445-
return 0;
3446-
}
3447-
3448-
if (args[0]->is_null())
3449-
{
3450-
if (arg_count < 2 || vtq_field == VTQ_TRX_ID)
3451-
{
3452-
null_value= true;
3453-
return 0;
3454-
}
3455-
return get_by_trx_id(args[1]->val_uint());
3456-
}
3457-
else
3458-
{
3459-
MYSQL_TIME commit_ts;
3460-
if (args[0]->get_date(&commit_ts, 0))
3461-
{
3462-
null_value= true;
3463-
return 0;
3464-
}
3465-
if (arg_count > 1)
3466-
{
3467-
backwards= args[1]->val_bool();
3468-
DBUG_ASSERT(arg_count == 2);
3469-
}
3470-
return get_by_commit_ts(commit_ts, backwards);
3471-
}
3472-
}
3473-
3474-
Item_func_vtq_trx_sees::Item_func_vtq_trx_sees(
3475-
THD *thd,
3476-
Item* a,
3477-
Item* b) :
3478-
VTQ_common<Item_bool_func>(thd, a, b),
3479-
accept_eq(false)
3480-
{
3481-
null_value= true;
3482-
DBUG_ASSERT(arg_count == 2 && args[0] && args[1]);
3483-
}
3484-
3485-
longlong
3486-
Item_func_vtq_trx_sees::val_int()
3487-
{
3488-
THD *thd= current_thd;
3489-
DBUG_ASSERT(thd);
3490-
3491-
init_hton();
3492-
3493-
if (!hton)
3494-
{
3495-
null_value= true;
3496-
return 0;
3497-
}
3498-
3499-
ulonglong trx_id1, trx_id0;
3500-
ulonglong commit_id1= 0;
3501-
ulonglong commit_id0= 0;
3502-
uchar iso_level1= 0;
3503-
3504-
DBUG_ASSERT(arg_count > 1);
3505-
trx_id1= args[0]->val_uint();
3506-
trx_id0= args[1]->val_uint();
3507-
3508-
vtq_record_t *cached= args[0]->vtq_cached_result();
3509-
if (cached && cached->commit_id)
3510-
{
3511-
commit_id1= cached->commit_id;
3512-
iso_level1= cached->iso_level;
3513-
}
3514-
3515-
cached= args[1]->vtq_cached_result();
3516-
if (cached && cached->commit_id)
3517-
{
3518-
commit_id0= cached->commit_id;
3519-
}
3520-
3521-
if (accept_eq && trx_id1 && trx_id1 == trx_id0)
3522-
{
3523-
null_value= false;
3524-
return true;
3525-
}
3526-
3527-
DBUG_ASSERT(hton->vers_trx_sees);
3528-
bool result= false;
3529-
null_value= !hton->vers_trx_sees(thd, result, trx_id1, trx_id0, commit_id1, iso_level1, commit_id0);
3530-
return result;
3531-
}
3532-

sql/item_timefunc.h

Lines changed: 0 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,119 +1286,4 @@ class Item_func_last_day :public Item_datefunc
12861286
{ return get_item_copy<Item_func_last_day>(thd, mem_root, this); }
12871287
};
12881288

1289-
#include "vtq.h"
1290-
1291-
template <class Item_func_X>
1292-
class VTQ_common : public Item_func_X
1293-
{
1294-
protected:
1295-
handlerton *hton;
1296-
void init_hton();
1297-
public:
1298-
VTQ_common(THD *thd, Item* a) :
1299-
Item_func_X(thd, a),
1300-
hton(NULL) {}
1301-
VTQ_common(THD *thd, Item* a, Item* b) :
1302-
Item_func_X(thd, a, b),
1303-
hton(NULL) {}
1304-
VTQ_common(THD *thd, Item* a, handlerton* _hton) :
1305-
Item_func_X(thd, a),
1306-
hton(_hton) {}
1307-
};
1308-
1309-
class Item_func_vtq_ts :
1310-
public VTQ_common<Item_datetimefunc>
1311-
{
1312-
vtq_field_t vtq_field;
1313-
public:
1314-
Item_func_vtq_ts(THD *thd, Item* a, vtq_field_t _vtq_field, handlerton *hton);
1315-
Item_func_vtq_ts(THD *thd, Item* a, vtq_field_t _vtq_field);
1316-
const char *func_name() const
1317-
{
1318-
if (vtq_field == VTQ_BEGIN_TS)
1319-
{
1320-
return "vtq_begin_ts";
1321-
}
1322-
return "vtq_commit_ts";
1323-
}
1324-
bool get_date(MYSQL_TIME *res, ulonglong fuzzy_date);
1325-
Item *get_copy(THD *thd, MEM_ROOT *mem_root)
1326-
{ return get_item_copy<Item_func_vtq_ts>(thd, mem_root, this); }
1327-
};
1328-
1329-
class Item_func_vtq_id :
1330-
public VTQ_common<Item_int_func>
1331-
{
1332-
vtq_field_t vtq_field;
1333-
vtq_record_t cached_result;
1334-
bool backwards;
1335-
1336-
longlong get_by_trx_id(ulonglong trx_id);
1337-
longlong get_by_commit_ts(MYSQL_TIME &commit_ts, bool backwards);
1338-
1339-
public:
1340-
Item_func_vtq_id(THD *thd, Item* a, vtq_field_t _vtq_field, bool _backwards= false);
1341-
Item_func_vtq_id(THD *thd, Item* a, Item* b, vtq_field_t _vtq_field);
1342-
1343-
vtq_record_t *vtq_cached_result() { return &cached_result; }
1344-
1345-
const char *func_name() const
1346-
{
1347-
switch (vtq_field)
1348-
{
1349-
case VTQ_TRX_ID:
1350-
return "vtq_trx_id";
1351-
case VTQ_COMMIT_ID:
1352-
return "vtq_commit_id";
1353-
case VTQ_ISO_LEVEL:
1354-
return "vtq_iso_level";
1355-
default:
1356-
DBUG_ASSERT(0);
1357-
}
1358-
return NULL;
1359-
}
1360-
1361-
void fix_length_and_dec()
1362-
{
1363-
Item_int_func::fix_length_and_dec();
1364-
max_length= 20;
1365-
}
1366-
1367-
longlong val_int();
1368-
Item *get_copy(THD *thd, MEM_ROOT *mem_root)
1369-
{ return get_item_copy<Item_func_vtq_id>(thd, mem_root, this); }
1370-
};
1371-
1372-
class Item_func_vtq_trx_sees :
1373-
public VTQ_common<Item_bool_func>
1374-
{
1375-
protected:
1376-
bool accept_eq;
1377-
1378-
public:
1379-
Item_func_vtq_trx_sees(THD *thd, Item* a, Item* b);
1380-
const char *func_name() const
1381-
{
1382-
return "vtq_trx_sees";
1383-
}
1384-
longlong val_int();
1385-
Item *get_copy(THD *thd, MEM_ROOT *mem_root)
1386-
{ return get_item_copy<Item_func_vtq_trx_sees>(thd, mem_root, this); }
1387-
};
1388-
1389-
class Item_func_vtq_trx_sees_eq :
1390-
public Item_func_vtq_trx_sees
1391-
{
1392-
public:
1393-
Item_func_vtq_trx_sees_eq(THD *thd, Item* a, Item* b) :
1394-
Item_func_vtq_trx_sees(thd, a, b)
1395-
{
1396-
accept_eq= true;
1397-
}
1398-
const char *func_name() const
1399-
{
1400-
return "vtq_trx_sees_eq";
1401-
}
1402-
};
1403-
14041289
#endif /* ITEM_TIMEFUNC_INCLUDED */

0 commit comments

Comments
 (0)