1 /* Copyright (c) 2008, 2021, Oracle and/or its affiliates.
2 
3   This program is free software; you can redistribute it and/or modify
4   it under the terms of the GNU General Public License, version 2.0,
5   as published by the Free Software Foundation.
6 
7   This program is also distributed with certain software (including
8   but not limited to OpenSSL) that is licensed under separate terms,
9   as designated in a particular file or component or in included license
10   documentation.  The authors of MySQL hereby grant you an additional
11   permission to link the program and your derivative works with the
12   separately licensed software that they have included with MySQL.
13 
14   This program is distributed in the hope that it will be useful,
15   but WITHOUT ANY WARRANTY; without even the implied warranty of
16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   GNU General Public License, version 2.0, for more details.
18 
19   You should have received a copy of the GNU General Public License
20   along with this program; if not, write to the Free Software Foundation,
21   51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
22 
23 #include "my_global.h"
24 #include "cursor_by_thread_connect_attr.h"
25 #include "pfs_buffer_container.h"
26 
27 ha_rows
get_row_count(void)28 cursor_by_thread_connect_attr::get_row_count(void)
29 {
30   /*
31     The real number of attributes per thread does not matter,
32     we only need to hint the optimizer there are many per thread,
33     so abusing session_connect_attrs_size_per_thread
34     (which is a number of bytes, not attributes)
35   */
36   return global_thread_container.get_row_count() *
37     session_connect_attrs_size_per_thread;
38 }
39 
cursor_by_thread_connect_attr(const PFS_engine_table_share * share)40 cursor_by_thread_connect_attr::cursor_by_thread_connect_attr(
41   const PFS_engine_table_share *share) :
42   PFS_engine_table(share, &m_pos), m_row_exists(false)
43 {}
44 
rnd_next(void)45 int cursor_by_thread_connect_attr::rnd_next(void)
46 {
47   PFS_thread *thread;
48   bool has_more_thread= true;
49 
50   for (m_pos.set_at(&m_next_pos);
51        has_more_thread;
52        m_pos.next_thread())
53   {
54     thread= global_thread_container.get(m_pos.m_index_1, & has_more_thread);
55     if (thread != NULL)
56     {
57       make_row(thread, m_pos.m_index_2);
58       if (m_row_exists)
59       {
60         m_next_pos.set_after(&m_pos);
61         return 0;
62       }
63     }
64   }
65 
66   return HA_ERR_END_OF_FILE;
67 }
68 
69 
rnd_pos(const void * pos)70 int cursor_by_thread_connect_attr::rnd_pos(const void *pos)
71 {
72   PFS_thread *thread;
73 
74   set_position(pos);
75 
76   thread= global_thread_container.get(m_pos.m_index_1);
77   if (thread != NULL)
78   {
79     make_row(thread, m_pos.m_index_2);
80     if (m_row_exists)
81       return 0;
82   }
83 
84   return HA_ERR_RECORD_DELETED;
85 }
86 
87 
reset_position(void)88 void cursor_by_thread_connect_attr::reset_position(void)
89 {
90   m_pos.reset();
91   m_next_pos.reset();
92 }
93