什么是index关键词的意思是,它提供什么功能?我知道这是为了加快查询速度,但我不确定如何做到这一点.
何时选择要编制索引的列?
的样品index关键字的使用被显示在下面的create table查询:
CREATE TABLE `blog_comment`
(
`id` INTEGER NOT NULL AUTO_INCREMENT,
`blog_post_id` INTEGER,
`author` VARCHAR(255),
`email` VARCHAR(255),
`body` TEXT,
`created_at` DATETIME,
PRIMARY KEY (`id`),
INDEX `blog_comment_FI_1` (`blog_post_id`),
CONSTRAINT `blog_comment_FK_1`
FOREIGN KEY (`blog_post_id`)
REFERENCES `blog_post` (`id`)
)Type=MyISAM
Run Code Online (Sandbox Code Playgroud)
;
在我的android活动中,我使用的RecyclerView是包含数量的MathViews.MathView是一个显示LaTeX内容的第三方库(这有点类似于WebView.MathView在这个android项目中可以看到实现.github.com/lingarajsankaravelu/Katex).
问题是,为了呈现这个内容MathView,需要更长的时间.因为我MathView在a中使用了很少的组件RecycleView,渲染时间增加了更多.因此,当Activity开始时,首先在视图中显示一些空白区域几秒钟,然后呈现相关内容.
作为此问题的解决方案,我需要显示一个进度条,直到完全呈现Activity的所有布局内容,并在渲染完成后显示Activity.
相关源代码如下所示.
MathView;
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:auto="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:id="@+id/equation_item"
android:clickable="true"
android:foreground="?attr/selectableItemBackground">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="4dp">
<katex.hourglass.in.mathlib.MathView
android:id="@+id/math_view"
android:clickable="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="left"
app:setClickable="true"
app:setTextColor="@color/colorPrimary"
app:setTextSize="10sp"
/>
</android.support.v7.widget.CardView>
<include layout="@layout/item_divider"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
Recycler View;
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.a37moons.mathcheatsheets.ContentActivity"
tools:showIn="@layout/activity_content">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view_equations"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>
</android.support.v4.widget.NestedScrollView>
Run Code Online (Sandbox Code Playgroud)
ViewHolder类
public class ViewHolder …Run Code Online (Sandbox Code Playgroud) 假设我有几个函数来处理不同类型的参数。例如processInt用于处理int变量和 processString用于处理std::string变量。
int processInt(int i)
{
return i;
}
string processString(string s)
{
return s;
}
Run Code Online (Sandbox Code Playgroud)
而且,我有一个名为的模板函数foo,它接受int或std::string作为参数。在这个函数内部,我需要根据作为参数发送给它的变量类型有条件地调用processIntor 。processString该foo函数如下所示:
#include <type_traits>
template<typename T>
T foo(T value)
{
T variable;
if (std::is_same<T, int>::value)
{
variable = processInt(value);
}
else if (std::is_same<T, string>::value)
{
variable = processString(value);
}
return variable;
}
int main() {
string s = "Abc";
int i = 123;
cout << …Run Code Online (Sandbox Code Playgroud)